public async void RequestToken() { Uri authorizationServerTokenIssuer = new Uri("https://localhost:5002/connect/token"); // string clientId = "ClientIdThatCanOnlyRead"; // string clientSecret = "secret1"; // string scope = "scope.readaccess"; string clientId = defaultScope[0]; string clientSecret = defaultScope[1]; string scope = defaultScope[2]; string rawJwtToken = RequestTokenToAuthorizationServer( authorizationServerTokenIssuer, clientId, scope, clientSecret) .GetAwaiter() .GetResult(); Debug.WriteLine("DEGUB: >> Requested Bearer Token: " + rawJwtToken); authorizationToken = JsonConvert.DeserializeObject <AuthorizationServerAnswer>(rawJwtToken); SetTokenToHeader(); }
private static async Task <string> RequestValuesToSecuredWebApi(AuthorizationServerAnswer authorizationServerToken) { HttpResponseMessage responseMessage; using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authorizationServerToken.access_token); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:56086/api/values"); responseMessage = await httpClient.SendAsync(request); } return(await responseMessage.Content.ReadAsStringAsync()); }