12
12
namespace BlazorWebAppOidc ;
13
13
14
14
// https://github.com/dotnet/aspnetcore/issues/8175
15
- internal sealed class CookieOidcRefresher ( IOptionsMonitor < OpenIdConnectOptions > oidcOptionsMonitor ) : IDisposable
15
+ internal sealed class CookieOidcRefresher ( IOptionsMonitor < OpenIdConnectOptions > oidcOptionsMonitor )
16
16
{
17
- private readonly HttpClient refreshClient = new ( ) ;
18
17
private readonly OpenIdConnectProtocolValidator oidcTokenValidator = new ( )
19
18
{
20
- // Refresh requests do not use the nonce parameter. Otherwise, we'd use oidcOptions.ProtocolValidator.
19
+ // We no longer have the original nonce cookie which is deleted at the end of the authorization code flow having served its purpose.
20
+ // Even if we had the nonce, it's likely expired. It's not intended for refresh requests. Otherwise, we'd use oidcOptions.ProtocolValidator.
21
21
RequireNonce = false ,
22
22
} ;
23
23
@@ -39,7 +39,7 @@ public async Task ValidateOrRefreshCookieAsync(CookieValidatePrincipalContext va
39
39
var oidcConfiguration = await oidcOptions . ConfigurationManager ! . GetConfigurationAsync ( validateContext . HttpContext . RequestAborted ) ;
40
40
var tokenEndpoint = oidcConfiguration . TokenEndpoint ?? throw new InvalidOperationException ( "Cannot refresh cookie. TokenEndpoint missing!" ) ;
41
41
42
- using var refreshResponse = await refreshClient . PostAsync ( tokenEndpoint ,
42
+ using var refreshResponse = await oidcOptions . Backchannel . PostAsync ( tokenEndpoint ,
43
43
new FormUrlEncodedContent ( new Dictionary < string , string ? > ( )
44
44
{
45
45
[ "grant_type" ] = "refresh_token" ,
@@ -77,11 +77,13 @@ public async Task ValidateOrRefreshCookieAsync(CookieValidatePrincipalContext va
77
77
return ;
78
78
}
79
79
80
+ var validatedIdToken = JwtSecurityTokenConverter . Convert ( validationResult . SecurityToken as JsonWebToken ) ;
81
+ validatedIdToken . Payload [ "nonce" ] = null ;
80
82
oidcTokenValidator . ValidateTokenResponse ( new ( )
81
83
{
82
84
ProtocolMessage = message ,
83
85
ClientId = oidcOptions . ClientId ,
84
- ValidatedIdToken = JwtSecurityTokenConverter . Convert ( validationResult . SecurityToken as JsonWebToken ) ,
86
+ ValidatedIdToken = validatedIdToken ,
85
87
} ) ;
86
88
87
89
validateContext . ShouldRenew = true ;
@@ -97,6 +99,4 @@ public async Task ValidateOrRefreshCookieAsync(CookieValidatePrincipalContext va
97
99
new ( ) { Name = "expires_at" , Value = expiresAt . ToString ( "o" , CultureInfo . InvariantCulture ) } ,
98
100
] ) ;
99
101
}
100
-
101
- public void Dispose ( ) => refreshClient . Dispose ( ) ;
102
102
}
0 commit comments