Browse Source

Merge pull request #14389 from abpframework/liangshiwei/blazor

Update Authentication in Blazor applications
pull/14410/head
Enis Necipoglu 4 years ago
committed by GitHub
parent
commit
ca6e6468bf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/RedirectToLogin.razor
  2. 13
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LoginDisplay.razor.cs
  3. 17
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/WebAssemblyRedirectToLogin.razor

19
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/RedirectToLogin.razor

@ -1,17 +1,10 @@
@inject NavigationManager Navigation @inject NavigationManager Navigation
@inject IJSRuntime JSRuntime
@code { @code {
protected override void OnInitialized() protected override void OnInitialized()
{ {
bool isWebAssembly = JSRuntime is IJSInProcessRuntime; Navigation.NavigateTo($"account/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}", true);
if (isWebAssembly) }
{
Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}"); }
}
else
{
Navigation.NavigateTo($"account/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}", true);
}
}
}

13
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LoginDisplay.razor.cs

@ -18,9 +18,6 @@ public partial class LoginDisplay : IDisposable
[Inject] [Inject]
public AuthenticationStateProvider AuthenticationStateProvider { get; set; } public AuthenticationStateProvider AuthenticationStateProvider { get; set; }
[CanBeNull]
protected SignOutSessionStateManager SignOutManager;
protected ApplicationMenu Menu { get; set; } protected ApplicationMenu Menu { get; set; }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
@ -29,8 +26,6 @@ public partial class LoginDisplay : IDisposable
Navigation.LocationChanged += OnLocationChanged; Navigation.LocationChanged += OnLocationChanged;
LazyGetService(ref SignOutManager);
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProvider.AuthenticationStateChanged +=
AuthenticationStateProviderOnAuthenticationStateChanged; AuthenticationStateProviderOnAuthenticationStateChanged;
} }
@ -65,12 +60,8 @@ public partial class LoginDisplay : IDisposable
} }
} }
private async Task BeginSignOut() private void BeginSignOut()
{ {
if (SignOutManager != null) Navigation.NavigateToLogout("authentication/logout");
{
await SignOutManager.SetSignOutState();
await NavigateToAsync("authentication/logout");
}
} }
} }

17
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/WebAssemblyRedirectToLogin.razor

@ -0,0 +1,17 @@
@inject NavigationManager Navigation
@using Volo.Abp.DependencyInjection
@using Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@inherits RedirectToLogin
@attribute [ExposeServices(typeof(RedirectToLogin))]
@attribute [Dependency(ReplaceServices = true)]
@code {
protected override void OnInitialized()
{
Navigation.NavigateToLogin("authentication/login");
}
}
Loading…
Cancel
Save