File tree 3 files changed +16
-3
lines changed
Security/Authentication/BearerToken/src 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -73,14 +73,26 @@ protected override async Task HandleChallengeAsync(AuthenticationProperties prop
73
73
74
74
protected override Task HandleSignInAsync ( ClaimsPrincipal user , AuthenticationProperties ? properties )
75
75
{
76
+ long expiresInTotalSeconds ;
77
+ var utcNow = TimeProvider . GetUtcNow ( ) ;
78
+
76
79
properties ??= new ( ) ;
77
- properties . ExpiresUtc ??= TimeProvider . GetUtcNow ( ) + Options . BearerTokenExpiration ;
80
+
81
+ if ( properties . ExpiresUtc is null )
82
+ {
83
+ properties . ExpiresUtc ??= utcNow + Options . BearerTokenExpiration ;
84
+ expiresInTotalSeconds = ( long ) Options . BearerTokenExpiration . TotalSeconds ;
85
+ }
86
+ else
87
+ {
88
+ expiresInTotalSeconds = ( long ) ( properties . ExpiresUtc . Value - utcNow ) . TotalSeconds ;
89
+ }
78
90
79
91
var ticket = new AuthenticationTicket ( user , properties , Scheme . Name ) ;
80
92
var accessTokenResponse = new AccessTokenResponse
81
93
{
82
94
AccessToken = BearerTokenProtector . Protect ( ticket ) ,
83
- ExpiresInTotalSeconds = Options . BearerTokenExpiration . TotalSeconds ,
95
+ ExpiresInTotalSeconds = expiresInTotalSeconds ,
84
96
} ;
85
97
86
98
return Context . Response . WriteAsJsonAsync ( accessTokenResponse , BearerTokenJsonSerializerContext . Default . AccessTokenResponse ) ;
Original file line number Diff line number Diff line change @@ -14,5 +14,5 @@ internal sealed class AccessTokenResponse
14
14
public required string AccessToken { get ; init ; }
15
15
16
16
[ JsonPropertyName ( "expires_in" ) ]
17
- public required double ExpiresInTotalSeconds { get ; init ; }
17
+ public required long ExpiresInTotalSeconds { get ; init ; }
18
18
}
Original file line number Diff line number Diff line change 75
75
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj",
76
76
"src\\Middleware\\WebSockets\\src\\Microsoft.AspNetCore.WebSockets.csproj",
77
77
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj",
78
+ "src\\Security\\Authentication\\BearerToken\\src\\Microsoft.AspNetCore.Authentication.BearerToken.csproj",
78
79
"src\\Security\\Authentication\\Certificate\\src\\Microsoft.AspNetCore.Authentication.Certificate.csproj",
79
80
"src\\Security\\Authentication\\Cookies\\src\\Microsoft.AspNetCore.Authentication.Cookies.csproj",
80
81
"src\\Security\\Authentication\\Core\\src\\Microsoft.AspNetCore.Authentication.csproj",
You can’t perform that action at this time.
0 commit comments