|
|
|
@ -24,34 +24,46 @@ public class ClientProxyExceptionEventHandler : ILocalEventHandler<ClientProxyEx |
|
|
|
|
|
|
|
public virtual async Task HandleEventAsync(ClientProxyExceptionEventData eventData) |
|
|
|
{ |
|
|
|
if (eventData.StatusCode == 401) |
|
|
|
using (var scope = ServiceProvider.CreateScope()) |
|
|
|
{ |
|
|
|
using (var scope = ServiceProvider.CreateScope()) |
|
|
|
switch (eventData.StatusCode) |
|
|
|
{ |
|
|
|
var options = scope.ServiceProvider.GetRequiredService<IOptions<AbpAspNetCoreComponentsWebOptions>>(); |
|
|
|
|
|
|
|
if (!options.Value.IsBlazorWebApp) |
|
|
|
case 401: |
|
|
|
{ |
|
|
|
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) |
|
|
|
var options = scope.ServiceProvider.GetRequiredService<IOptions<AbpAspNetCoreComponentsWebOptions>>(); |
|
|
|
|
|
|
|
if (!options.Value.IsBlazorWebApp) |
|
|
|
{ |
|
|
|
navigationManager.NavigateToLogout(authenticationOptions.Value.LogoutUrl); |
|
|
|
return; |
|
|
|
} |
|
|
|
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)) |
|
|
|
result.TryGetToken(out var token); |
|
|
|
if (token != null && DateTimeOffset.Now >= token.Expires.AddMinutes(-5)) |
|
|
|
{ |
|
|
|
navigationManager.NavigateToLogout(authenticationOptions.Value.LogoutUrl); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
navigationManager.NavigateToLogout(authenticationOptions.Value.LogoutUrl); |
|
|
|
var jsRuntime = scope.ServiceProvider.GetRequiredService<IJSRuntime>(); |
|
|
|
await jsRuntime.InvokeVoidAsync("eval", "setTimeout(function(){location.assign('/')}, 2000)"); |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
else |
|
|
|
case 403: |
|
|
|
{ |
|
|
|
var jsRuntime = scope.ServiceProvider.GetRequiredService<IJSRuntime>(); |
|
|
|
await jsRuntime.InvokeVoidAsync("eval", "setTimeout(function(){location.assign('/')}, 2000)"); |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|