Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Authentication required response when trying to access entries content

Discussion in 'Unity Cloud Content Delivery' started by hadrien23, Sep 29, 2020.

  1. hadrien23

    hadrien23

    Joined:
    Oct 9, 2019
    Posts:
    12
    Hi,

    First time trying to use UCD. Really good experience so far using the dashboard and CLI to upload content, but I'm having issues to access the content via the API.

    So far I could access the bucket entries list using the API but I get an authentication error when trying to access any entry content with the "/buckets/{bucketid}/entries/{entryid}/content/" route.
    I'm using the same authentication header that works to get the entries list via "/buckets/{bucketid}/entries" route.

    Here is the full response text:
    <?xml version='1.0' encoding='UTF-8'?><Error><Code>AuthenticationRequired</Code><Message>Authentication required.</Message></Error>

    Side note, I can't get any route to return an OK response from the swagger UI. I tried with the 'raw' api key as the authorization header value, then the base64 encoded version but always get am Unauthorized response.
     
  2. timtunity3d

    timtunity3d

    Unity Technologies

    Joined:
    Oct 1, 2015
    Posts:
    131
    The authorization code with the "Try it out" feature on the API Docs page is broken. I'll prioritize getting that fixed. When base64 encoding your APIKey are you prefixing it with a colon - ':'? I do it like this:

    echo -n ':aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' | base64

    We don't return XML responses so I'm somewhat puzzled about what endpoint you're hitting. This is working for me (with my real API key obviously):

    curl -L -H 'Authorization: Basic OmFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh' -X GET -H "accept: application/json" "https://content-api.cloud.unity3d.c...3afa3aad-8579-48f2-860c-07db74d60ffa/content/"

    Any more details you can give would be helpful (but don't post your API key or base64 encoded version).
     
  3. hadrien23

    hadrien23

    Joined:
    Oct 9, 2019
    Posts:
    12
    Thanks for the clarifications.

    I can get the list of entries from the bucket so the api key does seem to be the problem.
    Also, trying with curl as you proposed I can download any entry content.

    Strangely enough, once I downloaded an entry content using curl I can then download it from my Unity exe, but not other entries.Could be something wrong with the way I call the API? I'm using BestHttp for network calls and the code looks something like this:
    Code (CSharp):
    1. string localFilePath = ...
    2. Uri uri = ...
    3.  
    4. var request = new HTTPRequest(uri, HTTPMethods.Get, (req, resp) =>
    5. {
    6.     List<byte[]> fragments = resp.GetStreamedFragments();
    7.     if (fragments == null)
    8.         return;
    9.  
    10.     using (var fs = new FileStream(localFilePath, FileMode.Append))
    11.     {
    12.         foreach (byte[] data in fragments)
    13.         {
    14.             fs.Write(data, 0, data.Length);
    15.         }
    16.     }
    17.    
    18.     if (resp.IsStreamingFinished)
    19.     {
    20.        // done
    21.     }
    22. })
    23. {
    24.  
    25.     UseStreaming = true,
    26.     StreamFragmentSize = 1024 * 1024, // 1 Mo
    27.     DisableCache = true
    28. };
    29.  
    30. request.SetHeader("Authorization", $"Basic xxxxxxxxxxxxxxxxxxxxx");
    31. request.Send();
    EDIT: Just realized I'm using the management API instead of the client one... that probably does not help! Will probably have more luck with the client API.
     
    Last edited: Oct 1, 2020
  4. hadrien23

    hadrien23

    Joined:
    Oct 9, 2019
    Posts:
    12
    Some updates. I finally managed to download files from UCD using the client API and removing the authorization header entirely.

    Still, it's not clear how to get the list of files to download without going through the management API as well.
    I don't see a route on the client API to get the current list of entries on a bucket, or a diff with a previous release to get the list of files to download.

    I saw on a different thread you mentioned a manifest.json file that is somewhat hidden by default. Can I access this file on my bucket too, or is there a better way to access the entries to download?
     
  5. timtunity3d

    timtunity3d

    Unity Technologies

    Joined:
    Oct 1, 2015
    Posts:
    131
    The manifest file is generated as part of the Addressables package and is part of using Asset Bundles. We don't currently have a way to list entries from the client API as we were trying to make it at least a little bit challenging to scrape assets for a game, but we may need to find a way to enable that.

    When we designed it, the idea was that you would create and tag a release and then download the files by path. For instance:

    https://[project-id].client-api-tes...eleases/latest/entry_by_path/?path=MyFile.DLL

    We assumed that those file paths would be compiled into your game. We'd love to hear use cases for dynamically downloading content, however.
     
  6. hadrien23

    hadrien23

    Joined:
    Oct 9, 2019
    Posts:
    12
    The app I'm building has a list of animated models that user can browse and interact with. Some of the animations have subtitles as well. The idea to put them on a CDN is to push new animations and subtitles without asking users to download a new version of the app. So the list of entries is dynamic and will grow over time.

    I would expect the client API to expose a way to get the list of files to download, update or delete based on the current local versions of the the files. I believe I can get there by using the management API though, or by generating a custom manifest file with a static address on the CDN, although that last option feels a bit risky since the data is accessible without authentication once you have the file address.

    In that regard, I think the client API should require an authentication as well, or that it should at least be a choice left to the developer to protect the CDN data with a password or not.

    I hope that gives you a better idea of my use case. Thanks.
     
  7. timtunity3d

    timtunity3d

    Unity Technologies

    Joined:
    Oct 1, 2015
    Posts:
    131
    Your solutions are what we recommend currently, but we are collecting input on doing protected content. I'll go ahead and forward your input on to our product managers.
     
  8. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    What did you end up doing? I have similar needs. I want to download all the files that are currently missing from the local directory. For this I now use management API first to get a list of entries that I need to download, then client API to download them. This does work but if you ended up going a different route, I'd love to hear it.

    @timtunity3d what is the reason that downloading content does work with client API + no authentication, but only works for some files when using management API + authentication?