Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question How to add access token to CCD request to private bucket

Discussion in 'Unity Cloud Content Delivery' started by Limewood_, Nov 16, 2022.

  1. Limewood_


    Jan 5, 2020
    Note: I posted this in the Addressables forum first, but this seems a more appropriate place for it.

    I've set up buckets on CCD and created an Addressables profile using the 'latest' badge in the project.
    I've set the buckets private and created an access token for each of my buckets.
    Finally, I've used the code from here to try to add the base64 encoded token to the request: CCD + Addressables walkthrough|_____0#The_Command-line_interface_(optional)
    Code (CSharp):
    1. Addressables.WebRequestOverride = webRequest =>
    2. {
    3. webRequest.SetRequestHeader("Authorization", base64encodedToken);
    4. };
    5. var downloadHandle = Addressables.DownloadDependenciesAsync(downloadTags, Addressables.MergeMode.Union, true);
    I'm getting a 401 Unauthorized response each time.
    I've tried with both tokens, base64 encoded and not, adding "Bearer: " in front of the token and not.
    I've also tried adding "Basic " in front of the token, as recommended by this thread (which got a worryingly late reply):
    I've set the addressables groups to "Use UnityWebRequest for" as well.
    How is it supposed to be done?

    Also, when we find out how it's actually supposed to work, could you please update the example at the bottom here? CCD + Addressables walkthrough|_____0#The_Command-line_interface_(optional)
  2. Limewood_


    Jan 5, 2020
    Also, what is the use for public buckets where anyone can upload and access content without authentication (e.g. "If a bucket is tagged “Open to all”, anyone can modify content in this bucket" from Is it really a bucket where anyone in the world can upload content if they know the URL?
  3. Limewood_


    Jan 5, 2020
    @kaanyalti Did you find out how it's supposed to work with private buckets and access tokens?
  4. Limewood_


    Jan 5, 2020
    Well, I found out the solution, but I feel like this is either a bug or something is missing in all documentation about this.
    I noticed that on the following page there is an example of an access token and its Base64 encoded counterpart, but they don't match:
    However, decoding the Base64 version gives the example token with ":" prepended, so I tried adding a colon in front of my access token before encoding to Base64 and then it started working.
    Is this a mistake or is it intended to have a colon in front to work? And if so, why is this not documented anywhere?
  5. llunity3d


    Unity Technologies

    Aug 23, 2021
    Hi @Limewood_ ,

    Yes that is intended, in the documentation, just a few line above the base64 encoded counterpart, it is mentioned that :

    To authenticate requests, include a Basic Authentication header as a base64-encoded string 'username:password', using your access token as the password (and empty username).

    So you get something like have ':access token' and encode it in base64 afterward.

    We will update it to make it clearer,

    Hope this helps.
  6. Limewood_


    Jan 5, 2020
    Oh, I see now then, thank you for clarifying.
  7. kenamis


    Feb 5, 2015
    I am wondering about this too.
    I assume only the Unity accounts tied to the project can write to open buckets? According to the Management API
    then later under permissions
    It's very unclear.

    I'm using Addressables with the CCD and the CCD management package to build and release directly from the editor. I have a Staging environment and bucket with open, so I can write to it, and a production bucket with "promotion only", to promote to if the staging bucket is correct.

    How do I make sure my staging bucket is read only for anyone except my developers?

    I know there's the newer private read access token. I don't care about people reading the staging bucket, only write access. Do I need to use the private read access to fully protect the staging bucket?

    Do I need to get the CLI to properly add permissions to my buckets that aren't available on the dashboard?
    Frozen_Monkey likes this.
  8. LenoM


    Sep 19, 2018
    Hi I want to provide some code here, which worked for me to access private buckets with a token setup. I found the Documentations example code



    a bit contradictory.

    Please find the code below:

    Code (CSharp):
    1.         void Start()
    2.         {
    3.             //Add private token to addressable web request header
    4.             Addressables.WebRequestOverride = AddPrivateToken;
    5.         }
    8.         private void AddPrivateToken(UnityWebRequest request)
    9.         {
    10.             string bucketAccessToken = ""; // Add your bucket token here
    12.             var encodedToken = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes($":{bucketAccessToken}"));
    14.             request.SetRequestHeader("Authorization", $"Basic {encodedToken}");
    15.         }
    Last edited: Mar 8, 2023