5.7 KiB
OpenIddict Blazor Wasm UI Migration Guide
Blazor Project
-
In the MyApplicationBlazorModule.cs update the
ConfigureAuthenticationmethod:builder.Services.AddOidcAuthentication(options => { ... options.UserOptions.RoleClaim = JwtClaimTypes.Role; options.ProviderOptions.DefaultScopes.Add("role"); ... });Update UserOptions and role scope as below
builder.Services.AddOidcAuthentication(options => { ... options.UserOptions.NameClaim = OpenIddictConstants.Claims.Name; options.UserOptions.RoleClaim = OpenIddictConstants.Claims.Role; options.ProviderOptions.DefaultScopes.Add("roles"); ... });
Http.Api.Host (Non-Separated IdentityServer)
-
In the MyApplication.HttpApi.Host.csproj replace project references:
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="6.0.0-rc.1" /> <PackageReference Include="Volo.Abp.Account.Web.IdentityServer" Version="6.0.0-rc.1" />with
<PackageReference Include="Volo.Abp.Account.Web.OpenIddict" Version="6.0.0-rc.1" /> -
In the MyApplicationHttpApiHostModule.cs replace usings and module dependencies:
using System.Net.Http; using Volo.Abp.AspNetCore.Authentication.JwtBearer; ... typeof(AbpAspNetCoreAuthenticationJwtBearerModule), typeof(AbpAccountWebIdentityServerModule),with
using OpenIddict.Validation.AspNetCore; ... typeof(AbpAccountWebOpenIddictModule), -
In the MyApplicationBlazorModule.cs add
PreConfigureServiceslike below with your application name as the audience:public override void PreConfigureServices(ServiceConfigurationContext context) { PreConfigure<OpenIddictBuilder>(builder => { builder.AddValidation(options => { options.AddAudiences("MyApplication"); // Replace with your application name options.UseLocalServer(); options.UseAspNetCore(); }); }); } -
In the MyApplicationBlazorModule.cs
ConfigureServicesmethod, replace the method call:From
ConfigureAuthentication(context, configuration);toConfigureAuthentication(context);and update the method as:private void ConfigureAuthentication(ServiceConfigurationContext context) { context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme); } -
In the MyApplicationBlazorModule.cs
OnApplicationInitializationmethod, replace the midware:app.UseJwtTokenMiddleware(); app.UseIdentityServer();with
app.UseAbpOpenIddictValidation(); -
Delete
c.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);inapp.UseAbpSwaggerUIoptions configurations which is no longer needed. -
In
appsettings.jsondelete SwaggerClientSecret from the AuthServer section like below:"AuthServer": { "Authority": "https://localhost:44345", "RequireHttpsMetadata": "false", "SwaggerClientId": "MyApplication_Swagger" },
Http.Api.Host (Separated IdentityServer)
-
In the MyApplicationHttpApiHostModule.cs
OnApplicationInitializationmethod, deletec.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);inapp.UseAbpSwaggerUIoptions configurations which is no longer needed. -
In
appsettings.jsondelete SwaggerClientSecret from the AuthServer section like below:"AuthServer": { "Authority": "https://localhost:44345", "RequireHttpsMetadata": "false", "SwaggerClientId": "MyApplication_Swagger" },
IdentityServer
This project is renamed to AuthServer after v6.0.0-rc1. You can also refactor and rename your project to AuthServer for easier updates in the future.
-
In MyApplication.IdentityServer.csproj replace project references:
<PackageReference Include="Volo.Abp.Account.Web.IdentityServer" Version="6.0.0-rc.1" />with
<PackageReference Include="Volo.Abp.Account.Web.OpenIddict" Version="6.0.0-rc.1" /> -
In the MyApplicationIdentityServerModule.cs replace usings and module dependencies:
typeof(AbpAccountWebIdentityServerModule),with
typeof(AbpAccountWebOpenIddictModule), -
In the MyApplicationIdentityServerModule.cs add
PreConfigureServiceslike below with your application name as the audience:public override void PreConfigureServices(ServiceConfigurationContext context) { PreConfigure<OpenIddictBuilder>(builder => { builder.AddValidation(options => { options.AddAudiences("MyApplication"); // Replace with your application name options.UseLocalServer(); options.UseAspNetCore(); }); }); } -
In the MyApplicationIdentityServerModule.cs
OnApplicationInitializationmethod, remove the midware:app.UseIdentityServer(); -
To use the new AuthServer page, replace Index.cshtml.cs with AuthServer Index.cshtml.cs and Index.cshtml file with AuthServer Index.cshtml and rename Ids2OpenId with your application namespace.
Note: It can be found under the Pages folder.