Browse Source
Merge pull request #19770 from abpframework/ClientProxyExceptionEventHandler
Log out of blazor wasm when get a "401" response.
pull/19779/head
Gizem Mutu Kurt
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
2 additions and
15 deletions
-
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ClientProxyExceptionEventHandler.cs
|
|
|
@ -31,24 +31,11 @@ public class ClientProxyExceptionEventHandler : ILocalEventHandler<ClientProxyEx |
|
|
|
case 401: |
|
|
|
{ |
|
|
|
var options = scope.ServiceProvider.GetRequiredService<IOptions<AbpAspNetCoreComponentsWebOptions>>(); |
|
|
|
|
|
|
|
if (!options.Value.IsBlazorWebApp) |
|
|
|
{ |
|
|
|
var navigationManager = scope.ServiceProvider.GetRequiredService<NavigationManager>(); |
|
|
|
var accessTokenProvider = scope.ServiceProvider.GetRequiredService<IAccessTokenProvider>(); |
|
|
|
var authenticationOptions = scope.ServiceProvider.GetRequiredService<IOptions<AbpAuthenticationOptions>>(); |
|
|
|
var result = await accessTokenProvider.RequestAccessToken(); |
|
|
|
if (result.Status != AccessTokenResultStatus.Success) |
|
|
|
{ |
|
|
|
navigationManager.NavigateToLogout(authenticationOptions.Value.LogoutUrl); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
result.TryGetToken(out var token); |
|
|
|
if (token != null && DateTimeOffset.Now >= token.Expires.AddMinutes(-5)) |
|
|
|
{ |
|
|
|
navigationManager.NavigateToLogout(authenticationOptions.Value.LogoutUrl); |
|
|
|
} |
|
|
|
var navigationManager = scope.ServiceProvider.GetRequiredService<NavigationManager>(); |
|
|
|
navigationManager.NavigateToLogout(authenticationOptions.Value.LogoutUrl, "/"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|