Bearer token that never expires
Asked Answered
K

2

5

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

Kobe answered 10/3, 2014 at 19:27 Comment(3)
ASP.NET MVC and ASP.NET Web API are different projects.Timi
You can set expiration to 1 year or 100.Timi
that's a really bad idea! If you have an access token which never expires, how is it different than a password/username combination? It's even worse than that.Marelya
V
4

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);
Vereeniging answered 10/3, 2014 at 23:30 Comment(0)
P
7

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

Peroneus answered 27/6, 2018 at 10:37 Comment(0)
V
4

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);
Vereeniging answered 10/3, 2014 at 23:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.