oauth 2.0 - Multiple Token lifetimes in WebAPI2 with asp.net Identity -
I am using ASP.NET Identity Provider with OWuth Middleware with OAuth in my WebAPI application. Use template to do I work OAuth your WebAPI endpoint I though, how do I provide different token life span of various requests to extend this architecture I'm failing to look for For example, my REST API will be consumed by a web application, and a mobile app. I want the mobile app to have a longer token lifetime than a web application. I see configuration following OAuth my Startup.Auth.cs file - Can this behavior be overridden per token request? For example, I can expose "/ token" - & gt; 14 days and one "/ device token" - & gt; 60 days is this possible? I was able to fix it put the following in my my OAuth provider (ApplicationOAuthProvider. CS) sample -
// carrier to authenticate users app.UseOAuthBearerTokens to use tokens New OAuthAuthorizationServerOptions (application enable {TokenEndpointPath = new Pthstring ( "/ token"), provider = new ApplicationOAuthProvider & lt; ApplicationUserManager, DirectoryUser, Guid & gt; (PublicClientId), AuthorizeEndpointPath = new PathString ( "/ api / account / external login"), AccessTokenExpireTimeSpan = TimeSpan.FromDays (14), AllowInsecureHttp = true});
Task GrantResourceOwnerCredentials async public override (OAuthGrantResourceOwnerCredentialsContext context) {var userManager = context.OwinContext.Get & LT; TUserManager & gt; (); TUSUR User = User Manager Awaiting FNSINC (reference user, reference password); If (user == tap) {context.SetError ("invalid_grant", "username or password is incorrect."); Return; } // user, then 60. expire administrator, if 14 days (userManager.IsInRole (user.Id, "user")) {context.Options.AccessTokenExpireTimeSpan = TimeSpan.FromDays (60); } Other {context.Options.AccessTokenExpireTimeSpan = Timespan. Formady (14); } Claims oAuthIdentity = User Manager. Waiting for CREATINDITYSINK (user, reference option, authorization type); Dawmness Query Confirmation = User Manager Wait for Credit IdentitySync (User, Cookie Efficiency Defaults, Authentication Type); Authentication properties property = create properties (user.UserName); Authentication Ticket Ticket = New Authentication Tate (oAuthIdentity, Properties); Context.Validated (ticket); Context.Request.Context.Authentication.SignIn (cookiesIdentity); }
Comments
Post a Comment