Skip to content

Commit e04baf0

Browse files
authored
Add tests for JWT bearer events; fix event when expired (#87)
* Add capability to enable JwtBearer events * fix comment * update formatting * update * delete net core 3.1 / 5.0 testing * update * update * update * Update * update * update * update * try creating rsa parameters once
1 parent f7b74e2 commit e04baf0

File tree

2 files changed

+191
-39
lines changed

2 files changed

+191
-39
lines changed

src/GraphQL.AspNetCore3.JwtBearer/JwtWebSocketAuthenticationService.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ public async Task AuthenticateAsync(AuthenticationRequest authenticationRequest)
129129
// set the ClaimsPrincipal for the HttpContext; authentication will take place against this object
130130
connection.HttpContext.User = principal;
131131
return;
132+
} else if (_jwtBearerAuthenticationOptions.EnableJwtEvents) {
133+
// If JWT events are enabled, trigger the AuthenticationFailed event
134+
var exception = tokenValidationResult.Exception ?? new SecurityTokenValidationException($"The TokenHandler: '{tokenHandler}', was unable to validate the Token.");
135+
var failedResult = await TriggerAuthenticationFailedEventAsync(connection.HttpContext, options, exception, scheme).ConfigureAwait(false);
136+
if (failedResult.Handled && failedResult.Success) {
137+
connection.HttpContext.User = failedResult.Principal!;
138+
return;
139+
}
132140
}
133141
} catch (Exception ex) {
134142
// If JWT events are enabled, trigger the AuthenticationFailed event

0 commit comments

Comments
 (0)