Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAS tokens instead of keys in app #4

Open
mikaelhogstrom opened this issue Jan 10, 2018 · 3 comments
Open

SAS tokens instead of keys in app #4

mikaelhogstrom opened this issue Jan 10, 2018 · 3 comments

Comments

@mikaelhogstrom
Copy link

It would be really cool if you could use a SAS token (generated elsewhere) instead of storing the account key in the application.

I have a backend where I generate SAS tokens but I don't really know what to do with them, so that's pretty much the functionality I am asking for :)

@deadlyfingers
Copy link
Contributor

SAS token support is something I would like to add here... But with .NET 4.6 (Experiment) support looming I have held fire on developing this as it looks like we are close to being able to use the full SDKs now.
https://docs.microsoft.com/en-us/sandbox/gamedev/unity/azure-storage-unity

@mikaelhogstrom
Copy link
Author

Makes sense. I have already jumped ship to 4.6 myself :)

@jelling
Copy link

jelling commented Apr 17, 2022

The experimental Unity Azure SDK has been removed from the web, and from what I saw elsewhere, no longer works anyway.

So here's a quick and dirty modification that works for my needs and will hopefully save someone time:

        public void AuthorizeRequest(StorageServiceClient client, Method method, string resourcePath = "", Dictionary<string, string> queryParams = null, Dictionary<string, string> headers = null, int contentLength = 0)
        {
            AuthorizationHeaders authHeaders = new AuthorizationHeaders(client, method, resourcePath, queryParams, headers, contentLength);
            string stringToSign = authHeaders.ToString();
            this.AddHeader("x-ms-date", authHeaders.MSDate());
            this.AddHeader("x-ms-version", authHeaders.MSVersion());

            // NOTE: you'll need to add string SASParams to the client also 
            if (client.SASParams != null)
            {
                this.Request.url = $"{client.Url}{resourcePath}{client.SASParams}";
            }
            else
            {
                string signature = GetSignature(client.Key, stringToSign);
                string authorization = GetAuthorizationHeader(client.Account, signature);
                this.AddHeader("Authorization", authorization);
                Debug.Log("Authorized request url:" + this.Request.url + "\n\nauthorization: \"" + authorization + "\"\nx-ms-date: " + authHeaders.MSDate() + "\nstringToSign:'" + stringToSign + "'");
            }

            if (headers != null)
            {
                this.AddHeaders(headers);
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants