mirror of https://github.com/abpframework/abp.git
6 changed files with 65 additions and 4 deletions
@ -0,0 +1,40 @@ |
|||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Components; |
||||
|
using Microsoft.AspNetCore.Components.WebAssembly.Authentication; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.EventBus; |
||||
|
using Volo.Abp.Http; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.WebAssembly; |
||||
|
|
||||
|
public class ClientProxyExceptionEventHandler : ILocalEventHandler<ClientProxyExceptionEventData>, ITransientDependency |
||||
|
{ |
||||
|
protected NavigationManager NavigationManager { get; } |
||||
|
protected IAccessTokenProvider AccessTokenProvider { get; } |
||||
|
|
||||
|
public ClientProxyExceptionEventHandler(NavigationManager navigationManager, IAccessTokenProvider accessTokenProvider) |
||||
|
{ |
||||
|
NavigationManager = navigationManager; |
||||
|
AccessTokenProvider = accessTokenProvider; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task HandleEventAsync(ClientProxyExceptionEventData eventData) |
||||
|
{ |
||||
|
if (eventData.StatusCode == 401) |
||||
|
{ |
||||
|
var result = await AccessTokenProvider.RequestAccessToken(); |
||||
|
if (result.Status != AccessTokenResultStatus.Success) |
||||
|
{ |
||||
|
NavigationManager.NavigateToLogout("authentication/logout"); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
result.TryGetToken(out var token); |
||||
|
if (token != null && DateTimeOffset.Now >= token.Expires.AddMinutes(-5)) |
||||
|
{ |
||||
|
NavigationManager.NavigateToLogout("authentication/logout"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
namespace Volo.Abp.Http; |
||||
|
|
||||
|
public class ClientProxyExceptionEventData |
||||
|
{ |
||||
|
public int? StatusCode { get; set; } |
||||
|
|
||||
|
public string ReasonPhrase { get; set; } |
||||
|
} |
||||
Loading…
Reference in new issue