Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bearer token that never expires

Is it possible define that ASP.NET Web API 2 bearer token that never expires? Any clue?

like image 742
Friend Avatar asked Mar 10 '14 19:03

Friend


2 Answers

I think we can also achieve this by using given below code

AccessTokenExpireTimeSpan = TimeSpan.MaxValue

According to MSDN,

The value of this field is equivalent to Int64.MaxValue ticks. The string representation of this value is positive 10675199.02:48:05.4775807, or slightly more than 10,675,199 days https://msdn.microsoft.com/en-us/library/system.timespan.maxvalue(v=vs.110).aspx

like image 128
Ibtisam Avatar answered Sep 21 '22 15:09

Ibtisam


I don't think you can set it to never expire but you could certainly set a longer AccessTokenExpireTimeSpan:

OAuthOptions = new OAuthAuthorizationServerOptions
{
    TokenEndpointPath = new PathString("/Token"),
    Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
    AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
    AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
    AllowInsecureHttp = true
};  
app.UseOAuthBearerTokens(OAuthOptions);
like image 27
Ben Foster Avatar answered Sep 22 '22 15:09

Ben Foster