Skip to content

Instantly share code, notes, and snippets.

@HamidMosalla
Last active December 7, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HamidMosalla/f31f5e7c1e19b7971646ec53769fdabb to your computer and use it in GitHub Desktop.
Save HamidMosalla/f31f5e7c1e19b7971646ec53769fdabb to your computer and use it in GitHub Desktop.
public static async Task<string> RequestWithResourceOwnerPasswordWithPolicy()
{
async Task<string> GetAccessToken()
{
var discoveryResponse = await DiscoveryClient.GetAsync("http://localhost:5000");
// request token
var tokenClient = new TokenClient(discoveryResponse.TokenEndpoint, "ro.client1", "123654");
var accessToken = await tokenClient.RequestResourceOwnerPasswordAsync("mosalla", "password", "Api1");
if (accessToken.IsError)
{
Console.WriteLine(accessToken.Error);
return accessToken.Error;
}
Console.WriteLine(accessToken.Json);
return accessToken.AccessToken;
}
using (var client = new HttpClient())
{
var accessToken = await GetAccessToken();
client.SetBearerToken(accessToken);
var response = await client.GetAsync("http://localhost:5001/api/ApiResourceWithPolicy");
if (!response.IsSuccessStatusCode)
{
return response.StatusCode.ToString();
}
var content = await response.Content.ReadAsStringAsync();
return content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment