Created
March 27, 2018 21:37
-
-
Save jpda/06c61c3db03377414e2b6eab8282c837 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Net; | |
| using System.Net.Http; | |
| using System.Net.Http.Headers; | |
| using Microsoft.Azure.Services.AppAuthentication; | |
| public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log) | |
| { | |
| var target = "<target app client ID>"; | |
| var azureServiceTokenProvider = new AzureServiceTokenProvider(); | |
| string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync(target); | |
| log.Info($"Got token for {target}: {accessToken}"); | |
| var wc = new System.Net.Http.HttpClient(); | |
| wc.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); | |
| var result = await wc.GetAsync("https://<app endpoint>/api/who"); | |
| var data = await result.Content.ReadAsStringAsync(); | |
| log.Info($"got {data}"); | |
| return req.CreateResponse(HttpStatusCode.OK, data); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment