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

How to construct the authorization to use Azure function Key management API #1952

Closed
wxtom opened this issue Sep 26, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@wxtom
Copy link

commented Sep 26, 2017

I want to use the Key management API that mentioned in the document. But can't find a way how to construct the authorization to use those APIs?

@wxtom wxtom changed the title How to get the authorization to use Azure function Key management API How to construct the authorization to use Azure function Key management API Sep 26, 2017

@wxtom

This comment has been minimized.

Copy link
Author

commented Sep 28, 2017

I have got the answer from the following link.
https://stackoverflow.com/questions/46338239/retrieve-the-host-keys-from-an-azure-function-app/46436102#46436102

The key point is that we could get a JWT with Kudu API creds

   ```
        var webFunctionAppName = "functionName";
        var username = "ftpuserName";
        var password = "password";
        var base64Auth = Convert.ToBase64String(Encoding.Default.GetBytes($"{username}:{password}"));
        var apiUrl = new Uri($"https://{webFunctionAppName}.scm.azurewebsites.net/api");
        var siteUrl =new Uri($"https://{webFunctionAppName}.azurewebsites.net");
        string JWT;
        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("Authorization", $"Basic {base64Auth}"  );

            var result = client.GetAsync($"{apiUrl}/functions/admin/token").Result;
            JWT = result.Content.ReadAsStringAsync().Result.Trim('"'); //get  JWT for call funtion key
        }
        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("Authorization", "Bearer "+JWT);

            var key = client.GetAsync($"{siteUrl}/admin/functions/test/keys").Result.Content.ReadAsStringAsync().Result;
        }


@wxtom wxtom closed this Sep 28, 2017

@markheath

This comment has been minimized.

Copy link

commented Mar 17, 2018

Would be great if the docs were updated to include this information. Took me a long time to find this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.