Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. public class Startup
  2. {
  3. public static void Configuration(IAppBuilder app)
  4. {
  5. app.UseOAuthBearerAuthentication(
  6. new OAuthBearerAuthenticationOptions());
  7.  
  8. app.UseOAuthAuthorizationServer(
  9. new OAuthAuthorizationServerOptions
  10. {
  11. TokenEndpointPath = new PathString("/Token"),
  12. Provider = new OAuthAuthorizationServerProvider()
  13. {
  14. OnValidateClientAuthentication = async c =>
  15. {
  16. c.Validated();
  17. },
  18. OnGrantResourceOwnerCredentials = async c =>
  19. {
  20. if (c.UserName == "alice" && c.Password == "supersecret")
  21. {
  22. Claim claim1 = new Claim(ClaimTypes.Name, c.UserName);
  23. Claim[] claims = new Claim[] { claim1 };
  24. ClaimsIdentity claimsIdentity =
  25. new ClaimsIdentity(
  26. claims, OAuthDefaults.AuthenticationType);
  27. c.Validated(claimsIdentity);
  28. }
  29. }
  30. },
  31. // AccessTokenExpireTimeSpan = TimeSpan.FromSeconds(30),
  32. // AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
  33. AccessTokenExpireTimeSpan = TimeSpan.FromSeconds(40),
  34. AllowInsecureHttp = true,
  35. RefreshTokenProvider = new ApplicationRefreshTokenProvider()
  36.  
  37.  
  38. });
  39. }
  40. }
  41.  
  42. public class ApplicationRefreshTokenProvider : AuthenticationTokenProvider
  43. {
  44. public override void Create(AuthenticationTokenCreateContext context)
  45. {
  46. // Expiration time in seconds
  47. int expire = 2 * 60;
  48. context.Ticket.Properties.ExpiresUtc = new DateTimeOffset(DateTime.Now.AddSeconds(expire));
  49. context.SetToken(context.SerializeTicket());
  50. }
  51.  
  52. public override void Receive(AuthenticationTokenReceiveContext context)
  53. {
  54. context.DeserializeTicket(context.Token);
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement