public async Task <ActionResult> OAuthCallback(string code, string error) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // ignore certificate errors when testing ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; if (error != null) { // TODO: the authorization failed return(new HttpStatusCodeResult(HttpStatusCode.NoContent)); } var authClient = new OAuth2Client( new Uri($"{GrowthZoneClient.Host}/oauth/token"), GrowthZoneClient.ClientId, GrowthZoneClient.ClientSecret, OAuth2Client.ClientAuthenticationStyle.PostValues); var tokenResponse = await authClient.RequestAuthorizationCodeAsync(code, RedirectUri); if (tokenResponse.IsError) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } using (var client = new GrowthZoneClient(new Uri(GrowthZoneClient.Host), tokenResponse.AccessToken)) { var claims = await client.GetClaimsAsync(); return(View("Claims", claims)); } }
static void Main(string[] args) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateValidationFailureForTestingOnly; Console.WriteLine("Please enter your username:"******"\nPlease enter your password:"******"{GrowthZoneClient.Host}/oauth/token"), GrowthZoneClient.ClientId, GrowthZoneClient.ClientSecret, OAuth2Client.ClientAuthenticationStyle.PostValues); var response = oAuthClient.RequestResourceOwnerPasswordAsync(username, password).Result; Console.WriteLine(response.AccessToken); Console.WriteLine("\n\nDisplaying your claims."); using (var client = new GrowthZoneClient(new Uri(GrowthZoneClient.Host), response.AccessToken)) { var claims = client.GetClaimsAsync().Result; foreach (var claim in claims.Claims) { Console.WriteLine("{0}: {1}", claim.Name, claim.Value); } } }
public async Task <ActionResult> Claims() { var user = User as ClaimsPrincipal; // the access token for the GrowthZone API is contained as a claim var accessToken = user.FindFirst("access_token").Value; using (var client = new GrowthZoneClient(new Uri(GrowthZoneClient.Host), accessToken)) { var claims = await client.GetClaimsAsync(); return(View(claims)); } }