Version
Google Translate

OpenIddict Blazor-Server UI Migration Guide

Blazor Project (Non-Tiered Solution)

  • In the MyApplication.Blazor.csproj replace project references:

    <PackageReference Include="Verto.Vcp.Account.Pro.Public.Web.IdentityServer" Version="6.0.*" />
    <PackageReference Include="Verto.Vcp.IdentityServer.Blazor.Server" Version="6.0.*" />
    

    with

    <PackageReference Include="Verto.Vcp.Account.Pro.Public.Web.OpenIddict" Version="6.0.*" />
    <PackageReference Include="Verto.Vcp.OpenIddict.Pro.Blazor.Server" Version="6.0.*" />    
    
  • In the MyApplicationBlazorModule.cs replace usings and module dependencies:

    using Verto.Vcp.AspNetCore.Authentication.JwtBearer;
    using Verto.Vcp.IdentityServer.Blazor.Server;
    ...
    typeof(VcpAccountPublicWebIdentityServerModule),
    typeof(VcpIdentityServerBlazorServerModule),
    

    with

    using OpenIddict.Validation.AspNetCore;
    using Verto.Vcp.OpenIddict.Pro.Blazor.Server;
    ...
    typeof(VcpAccountPublicWebOpenIddictModule),
    typeof(VcpOpenIddictProBlazorServerModule),
    
  • In the MyApplicationBlazorModule.cs add PreConfigureServices like 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 ConfigureServices method, replace the method call:

    From ConfigureAuthentication(context, configuration); to ConfigureAuthentication(context); and update the method as:

    private void ConfigureAuthentication(ServiceConfigurationContext context)
    {
        context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
    }
    
  • In the MyApplicationBlazorModule.cs OnApplicationInitialization method, replace the midware:

    app.UseJwtTokenMiddleware();
    app.UseIdentityServer();
    

    with

    app.UseVcpOpenIddictValidation();
    
  • In the MyApplicationMenuContributor.cs under Menus folder, replace the using and menu name under ConfigureMainMenuAsync:

    using Verto.Vcp.IdentityServer.Blazor.Navigation;
    ...
    //Administration->Identity Server
    administration.SetSubItemOrder(VcpIdentityServerMenuNames.GroupName, 2);
    

    with

    using Verto.Vcp.OpenIddict.Pro.Blazor.Menus;
    ...
    //Administration->OpenIddict
    administration.SetSubItemOrder(OpenIddictProMenus.GroupName, 2);
    

Blazor Project (Tiered Solution)

  • In the MyApplicationWebModule.cs update the AddVcpOpenIdConnect configurations:

    .AddVcpOpenIdConnect("oidc", options =>
    {
      options.Authority = configuration["AuthServer:Authority"];
        options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
        options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
    
        options.ClientId = configuration["AuthServer:ClientId"];
        options.ClientSecret = configuration["AuthServer:ClientSecret"];
    
        options.SaveTokens = true;
        options.GetClaimsFromUserInfoEndpoint = true;
    
        options.Scope.Add("roles"); // Replace "role" with "roles"
        options.Scope.Add("email");
        options.Scope.Add("phone");
        options.Scope.Add("MyApplication");
    });
    

    Replace role scope with roles.

Http.Api.Host

  • In the MyApplicationHttpApiHostModule.cs OnApplicationInitialization method, delete c.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); in app.UseVcpSwaggerUI options configurations which is no longer needed.

  • In appsettings.json delete 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. 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="Verto.Vcp.Account.Pro.Public.Web.IdentityServer" Version="6.0.*" />
    

    with

    <PackageReference Include="Verto.Vcp.Account.Pro.Public.Web.OpenIddict" Version="6.0.*" />
    
  • In MyApplicationIdentityServerModule.cs replace usings and module dependencies:

    using IdentityServer4.Configuration;
    using Verto.Vcp.AspNetCore.Authentication.JwtBearer;
    ...
    typeof(VcpAccountPublicWebIdentityServerModule),
    

    with

    using OpenIddict.Validation.AspNetCore;
    ...
    typeof(VcpAccountPublicWebOpenIddictModule),
    
  • In the MyApplicationIdentityServerModule.cs add PreConfigureServices like 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 replace ForwardIdentityAuthenticationForBearer under ConfigureServices method:

    context.Services.ForwardIdentityAuthenticationForBearer();
    

    with

    context.Services.ForwardIdentityAuthenticationForBearer(OpenIddictValidationAspNetCoreDefaults.AuthenticationScheme);
    
  • In the MyApplicationIdentityServerModule.cs, remove IdentityServerOptions configuration and JwtBearer options under ConfigureServices method:

    if (Convert.ToBoolean(configuration["AuthServer:SetSelfAsIssuer"])) // Remove
    {
        Configure<IdentityServerOptions>(options => { options.IssuerUri = configuration["App:SelfUrl"]; });
    }
    ...
    context.Services.AddAuthentication() // Remove
        .AddJwtBearer(options =>
        {
           options.Authority = configuration["AuthServer:Authority"];
           options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
           options.Audience = "MyApplication";
        })
    
  • In the MyApplicationIdentityServerModule.cs OnApplicationInitialization method, replace the midware:

    app.UseJwtTokenMiddleware();
    app.UseIdentityServer();
    

    with

    app.UseVcpOpenIddictValidation();
    
  • To use the new AuthServer page, replace Index.cshtml.cs with AuthServer Index.cshtml.cs and Index.cshtml file with AuthServer Index.cshtml.

    Note: It can be found under the Pages folder.

See Also

In this document