Browse Source

Add `AuthenticationOptions`.

pull/18876/head
maliming 2 years ago
parent
commit
4bfcd720ff
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 13
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/AbpAspNetCoreComponentsWebAssemblyBasicThemeModule.cs
  2. 8
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/AuthenticationOptions.cs
  3. 4
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LoginDisplay.razor
  4. 4
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LoginDisplay.razor.cs
  5. 9
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/WebAssemblyRedirectToLogin.razor
  6. 6
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/Menus/MyProjectNameMenuContributor.cs
  7. 3
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/wwwroot/appsettings.json
  8. 6
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Client/Menus/MyProjectNameMenuContributor.cs
  9. 24
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Client/MyProjectNameBlazorClientModule.cs
  10. 8
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Client/wwwroot/appsettings.json
  11. 6
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Tiered.Client/Menus/MyProjectNameMenuContributor.cs
  12. 13
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Tiered.Client/MyProjectNameBlazorClientModule.cs
  13. 6
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Tiered.Client/wwwroot/appsettings.json

13
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/AbpAspNetCoreComponentsWebAssemblyBasicThemeModule.cs

@ -1,4 +1,6 @@
using Volo.Abp.AspNetCore.Components.Web.BasicTheme;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.Components.Server;
using Volo.Abp.AspNetCore.Components.Web.BasicTheme;
using Volo.Abp.AspNetCore.Components.Web.Theming.Routing;
using Volo.Abp.AspNetCore.Components.Web.Theming.Toolbars;
using Volo.Abp.AspNetCore.Components.WebAssembly.Theming;
@ -25,5 +27,14 @@ public class AbpAspNetCoreComponentsWebAssemblyBasicThemeModule : AbpModule
{
options.Contributors.Add(new BasicThemeToolbarContributor());
});
if (context.Services.ExecutePreConfiguredActions<AbpAspNetCoreComponentsWebOptions>().IsBlazorWebApp)
{
Configure<AuthenticationOptions>(options =>
{
options.LoginUrl = "Account/Login";
options.LogoutUrl = "Account/Logout";
});
}
}
}

8
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/AuthenticationOptions.cs

@ -0,0 +1,8 @@
namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme;
public class AuthenticationOptions
{
public string LoginUrl { get; set; } = "authentication/login";
public string LogoutUrl { get; set; } = "authentication/logout";
}

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

@ -2,12 +2,14 @@
@using Volo.Abp.Users
@using Volo.Abp.MultiTenancy
@using global::Localization.Resources.AbpUi
@using Microsoft.Extensions.Options
@inherits AbpComponentBase
@inject ICurrentUser CurrentUser
@inject ICurrentTenant CurrentTenant
@inject IJSRuntime JsRuntime
@inject NavigationManager Navigation
@inject IStringLocalizer<AbpUiResource> UiLocalizer
@inject IOptions<AuthenticationOptions> AuthenticationOptions
<AuthorizeView>
<Authorized>
<Dropdown RightAligned="true">
@ -35,6 +37,6 @@
</Dropdown>
</Authorized>
<NotAuthorized>
<a class="nav-link" href="authentication/login">@UiLocalizer["Login"]</a>
<a class="nav-link" href="@AuthenticationOptions.Value.LoginUrl">@UiLocalizer["Login"]</a>
</NotAuthorized>
</AuthorizeView>

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

@ -1,8 +1,6 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Routing;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.JSInterop;
@ -61,6 +59,6 @@ public partial class LoginDisplay : IDisposable
private void BeginSignOut()
{
Navigation.NavigateToLogout("authentication/logout");
Navigation.NavigateToLogout(AuthenticationOptions.Value.LogoutUrl);
}
}

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

@ -1,17 +1,16 @@
@inject NavigationManager Navigation
@using Volo.Abp.DependencyInjection
@using Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@using Microsoft.Extensions.Options
@inherits RedirectToLogin
@attribute [ExposeServices(typeof(RedirectToLogin))]
@attribute [Dependency(ReplaceServices = true)]
@inject IOptions<AuthenticationOptions> AuthenticationOptions
@code {
protected override void OnInitialized()
{
Navigation.NavigateToLogin("authentication/login");
Navigation.NavigateToLogin(AuthenticationOptions.Value.LoginUrl);
}
}
}

6
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/Menus/MyProjectNameMenuContributor.cs

@ -46,7 +46,7 @@ public class MyProjectNameMenuContributor : IMenuContributor
icon: "fas fa-home"
)
);
var administration = context.Menu.GetAdministration();
if (MultiTenancyConsts.IsEnabled)
@ -68,12 +68,10 @@ public class MyProjectNameMenuContributor : IMenuContributor
{
var accountStringLocalizer = context.GetLocalizer<AccountResource>();
var authServerUrl = _configuration["AuthServer:Authority"] ?? "";
context.Menu.AddItem(new ApplicationMenuItem(
"Account.Manage",
accountStringLocalizer["MyAccount"],
$"{authServerUrl.EnsureEndsWith('/')}Account/Manage?returnUrl={_configuration["App:SelfUrl"]}",
$"Account/Manage",
icon: "fa fa-cog",
order: 1000,
null).RequireAuthenticated());

3
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Client/wwwroot/appsettings.json

@ -1,7 +1,4 @@
{
"App": {
"SelfUrl": "https://localhost:44307"
},
"AuthServer": {
"Authority": "https://localhost:44305",
"ClientId": "MyProjectName_Blazor",

6
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Client/Menus/MyProjectNameMenuContributor.cs

@ -46,7 +46,7 @@ public class MyProjectNameMenuContributor : IMenuContributor
icon: "fas fa-home"
)
);
var administration = context.Menu.GetAdministration();
if (MultiTenancyConsts.IsEnabled)
@ -68,12 +68,10 @@ public class MyProjectNameMenuContributor : IMenuContributor
{
var accountStringLocalizer = context.GetLocalizer<AccountResource>();
var authServerUrl = _configuration["AuthServer:Authority"] ?? "";
context.Menu.AddItem(new ApplicationMenuItem(
"Account.Manage",
accountStringLocalizer["MyAccount"],
$"{authServerUrl.EnsureEndsWith('/')}Account/Manage?returnUrl={_configuration["App:SelfUrl"]}",
$"Account/Manage",
icon: "fa fa-cog",
order: 1000,
null).RequireAuthenticated());

24
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Client/MyProjectNameBlazorClientModule.cs

@ -3,12 +3,14 @@ using System.Net.Http;
using Blazorise.Bootstrap5;
using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using MyCompanyName.MyProjectName.Blazor.Server.WebApp.Client.Menus;
using OpenIddict.Abstractions;
using Volo.Abp.AspNetCore.Components.Server;
using Volo.Abp.AspNetCore.Components.Web.Theming.Routing;
using Volo.Abp.AspNetCore.Components.WebAssembly.LeptonXLiteTheme;
using Volo.Abp.AspNetCore.Components.WebAssembly.WebApp;
@ -34,6 +36,14 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.WebApp.Client;
)]
public class MyProjectNameBlazorClientModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpAspNetCoreComponentsWebOptions>(options =>
{
options.IsBlazorWebApp = true;
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var environment = context.Services.GetSingletonInstance<IWebAssemblyHostEnvironment>();
@ -73,19 +83,9 @@ public class MyProjectNameBlazorClientModule : AbpModule
private static void ConfigureAuthentication(WebAssemblyHostBuilder builder)
{
//TODO: Remove SignOutSessionStateManager in new version.
builder.Services.TryAddScoped<SignOutSessionStateManager>();
builder.Services.AddBlazorWebAppServices();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddOidcAuthentication(options =>
{
builder.Configuration.Bind("AuthServer", options.ProviderOptions);
options.UserOptions.NameClaim = OpenIddictConstants.Claims.Name;
options.UserOptions.RoleClaim = OpenIddictConstants.Claims.Role;
options.ProviderOptions.DefaultScopes.Add("MyProjectName");
options.ProviderOptions.DefaultScopes.Add("roles");
options.ProviderOptions.DefaultScopes.Add("email");
options.ProviderOptions.DefaultScopes.Add("phone");
});
}
private static void ConfigureHttpClient(ServiceConfigurationContext context, IWebAssemblyHostEnvironment environment)

8
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Client/wwwroot/appsettings.json

@ -1,12 +1,4 @@
{
"App": {
"SelfUrl": "https://localhost:44307"
},
"AuthServer": {
"Authority": "https://localhost:44308",
"ClientId": "MyProjectName_Blazor",
"ResponseType": "code"
},
"RemoteServices": {
"Default": {
"BaseUrl": "https://localhost:44308"

6
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Tiered.Client/Menus/MyProjectNameMenuContributor.cs

@ -46,7 +46,7 @@ public class MyProjectNameMenuContributor : IMenuContributor
icon: "fas fa-home"
)
);
var administration = context.Menu.GetAdministration();
if (MultiTenancyConsts.IsEnabled)
@ -68,12 +68,10 @@ public class MyProjectNameMenuContributor : IMenuContributor
{
var accountStringLocalizer = context.GetLocalizer<AccountResource>();
var authServerUrl = _configuration["AuthServer:Authority"] ?? "";
context.Menu.AddItem(new ApplicationMenuItem(
"Account.Manage",
accountStringLocalizer["MyAccount"],
$"{authServerUrl.EnsureEndsWith('/')}Account/Manage?returnUrl={_configuration["App:SelfUrl"]}",
$"Account/Manage",
icon: "fa fa-cog",
order: 1000,
null).RequireAuthenticated());

13
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Tiered.Client/MyProjectNameBlazorClientModule.cs

@ -2,18 +2,16 @@
using System.Net.Http;
using Blazorise.Bootstrap5;
using Blazorise.Icons.FontAwesome;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using MyCompanyName.MyProjectName.Blazor.Server.WebApp.Tiered.Client.Menus;
using Volo.Abp.AspNetCore.Components.Server;
using Volo.Abp.AspNetCore.Components.Web.Theming.Routing;
using Volo.Abp.AspNetCore.Components.WebAssembly.LeptonXLiteTheme;
using Volo.Abp.AspNetCore.Components.WebAssembly.WebApp;
using Volo.Abp.Autofac.WebAssembly;
using Volo.Abp.AutoMapper;
using Volo.Abp.Http.Client.Authentication;
using Volo.Abp.Identity.Blazor.WebAssembly;
using Volo.Abp.Modularity;
using Volo.Abp.SettingManagement.Blazor.WebAssembly;
@ -32,6 +30,14 @@ namespace MyCompanyName.MyProjectName.Blazor.Server.WebApp.Tiered.Client;
)]
public class MyProjectNameBlazorClientModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpAspNetCoreComponentsWebOptions>(options =>
{
options.IsBlazorWebApp = true;
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var environment = context.Services.GetSingletonInstance<IWebAssemblyHostEnvironment>();
@ -70,6 +76,7 @@ public class MyProjectNameBlazorClientModule : AbpModule
private static void ConfigureAuthentication(WebAssemblyHostBuilder builder)
{
//TODO: Remove SignOutSessionStateManager in new version.
builder.Services.TryAddScoped<SignOutSessionStateManager>();
builder.Services.AddBlazorWebAppTieredServices();
}

6
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor.Server.WebApp.Tiered.Client/wwwroot/appsettings.json

@ -1,10 +1,4 @@
{
"App": {
"SelfUrl": "https://localhost:44309"
},
"AuthServer": {
"Authority": "https://localhost:44301"
},
"RemoteServices": {
"Default": {
"BaseUrl": "https://localhost:44300"

Loading…
Cancel
Save