Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Startup
- {
- public static void Configuration(IAppBuilder app)
- {
- app.UseOAuthBearerAuthentication(
- new OAuthBearerAuthenticationOptions());
- app.UseOAuthAuthorizationServer(
- new OAuthAuthorizationServerOptions
- {
- TokenEndpointPath = new PathString("/Token"),
- Provider = new OAuthAuthorizationServerProvider()
- {
- OnValidateClientAuthentication = async c =>
- {
- c.Validated();
- },
- OnGrantResourceOwnerCredentials = async c =>
- {
- if (c.UserName == "alice" && c.Password == "supersecret")
- {
- Claim claim1 = new Claim(ClaimTypes.Name, c.UserName);
- Claim[] claims = new Claim[] { claim1 };
- ClaimsIdentity claimsIdentity =
- new ClaimsIdentity(
- claims, OAuthDefaults.AuthenticationType);
- c.Validated(claimsIdentity);
- }
- }
- },
- // AccessTokenExpireTimeSpan = TimeSpan.FromSeconds(30),
- // AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
- AccessTokenExpireTimeSpan = TimeSpan.FromSeconds(40),
- AllowInsecureHttp = true,
- RefreshTokenProvider = new ApplicationRefreshTokenProvider()
- });
- }
- }
- public class ApplicationRefreshTokenProvider : AuthenticationTokenProvider
- {
- public override void Create(AuthenticationTokenCreateContext context)
- {
- // Expiration time in seconds
- int expire = 2 * 60;
- context.Ticket.Properties.ExpiresUtc = new DateTimeOffset(DateTime.Now.AddSeconds(expire));
- context.SetToken(context.SerializeTicket());
- }
- public override void Receive(AuthenticationTokenReceiveContext context)
- {
- context.DeserializeTicket(context.Token);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement