Guest User

Untitled

a guest
Jul 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. var oAuthOptions = new OAuthAuthorizationServerOptions
  2. {
  3. TokenEndpointPath = new PathString("/token"),
  4. AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(accessTokenExipreMinutes),
  5. Provider = new AuthorizationServerProvider(),
  6. AllowInsecureHttp = allowInsecureHttp
  7. };
  8.  
  9. appBuilder.UseOAuthBearerTokens(oAuthOptions);
  10.  
  11. class AuthorizationServerProvider : OAuthAuthorizationServerProvider
  12. {
  13. public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
  14. {
  15. context.TryGetFormCredentials(out string clientId, out string clientSecret);
  16.  
  17. var result = Validate(clientId, clientSecret);
  18. if (result)
  19. {
  20. context.Validated(clientId);
  21. return;
  22. }
  23.  
  24. context.Rejected();
  25. }
  26.  
  27. public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
  28. {
  29. try
  30. {
  31. ClaimsIdentity oAuthIdentity = new ClaimsIdentity(context.Options.AuthenticationType);
  32. var props = new AuthenticationProperties();
  33. var ticket = new AuthenticationTicket(oAuthIdentity, props);
  34.  
  35. context.Validated(ticket);
  36. }
  37. catch (Exception ex)
  38. {
  39. context.Rejected();
  40. }
  41.  
  42. return Task.FromResult(true);
  43. }
  44. }
Add Comment
Please, Sign In to add comment