From dde6ff69c3ba02aaaa11f674958303be73f6d518 Mon Sep 17 00:00:00 2001 From: Ahmet Date: Fri, 25 Sep 2020 12:55:13 +0300 Subject: [PATCH] Update IdentityServerDataSeeContributor of module template --- .../IdentityServerDataSeedContributor.cs | 1 + .../IdentityServerDataSeedContributor.cs | 43 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs index dcd105a4e9..9edcfd1cd6 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs @@ -155,6 +155,7 @@ namespace MyCompanyName.MyProjectName.IdentityServer grantTypes: new[] { "authorization_code" }, secret: configurationSection["MyProjectName_Blazor:ClientSecret"]?.Sha256(), requireClientSecret: false, + requirePkce: true, redirectUri: $"{blazorRootUrl}/authentication/login-callback", postLogoutRedirectUri: $"{blazorRootUrl}/authentication/logout-callback" ); diff --git a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/IdentityServer/IdentityServerDataSeedContributor.cs b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/IdentityServer/IdentityServerDataSeedContributor.cs index 593169ae48..c3b50e92f2 100644 --- a/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/IdentityServer/IdentityServerDataSeedContributor.cs +++ b/templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/IdentityServer/IdentityServerDataSeedContributor.cs @@ -1,7 +1,8 @@ -using Microsoft.Extensions.Configuration; -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; +using IdentityServer4.Models; +using Microsoft.Extensions.Configuration; using Volo.Abp.Authorization.Permissions; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; @@ -11,6 +12,8 @@ using Volo.Abp.IdentityServer.Clients; using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.PermissionManagement; using Volo.Abp.Uow; +using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource; +using Client = Volo.Abp.IdentityServer.Clients.Client; namespace MyCompanyName.MyProjectName.IdentityServer { @@ -131,15 +134,37 @@ namespace MyCompanyName.MyProjectName.IdentityServer commonSecret ); } + + // Blazor Client + var blazorClientId = configurationSection["MyProjectName_Blazor:ClientId"]; + if (!blazorClientId.IsNullOrWhiteSpace()) + { + var blazorRootUrl = configurationSection["MyProjectName_Blazor:RootUrl"].TrimEnd('/'); + + await CreateClientAsync( + name: blazorClientId, + scopes: commonScopes, + grantTypes: new[] { "authorization_code" }, + secret: configurationSection["MyProjectName_Blazor:ClientSecret"]?.Sha256(), + requireClientSecret: false, + requirePkce: true, + redirectUri: $"{blazorRootUrl}/authentication/login-callback", + postLogoutRedirectUri: $"{blazorRootUrl}/authentication/logout-callback" + ); + } + } private async Task CreateClientAsync( string name, IEnumerable scopes, IEnumerable grantTypes, - string secret, + string secret = null, string redirectUri = null, string postLogoutRedirectUri = null, + string frontChannelLogoutUri = null, + bool requireClientSecret = true, + bool requirePkce = false, IEnumerable permissions = null) { var client = await _clientRepository.FindByCliendIdAsync(name); @@ -160,7 +185,10 @@ namespace MyCompanyName.MyProjectName.IdentityServer AccessTokenLifetime = 31536000, //365 days AuthorizationCodeLifetime = 300, IdentityTokenLifetime = 300, - RequireConsent = false + RequireConsent = false, + FrontChannelLogoutUri = frontChannelLogoutUri, + RequireClientSecret = requireClientSecret, + RequirePkce = requirePkce }, autoSave: true ); @@ -182,9 +210,12 @@ namespace MyCompanyName.MyProjectName.IdentityServer } } - if (client.FindSecret(secret) == null) + if (!secret.IsNullOrEmpty()) { - client.AddSecret(secret); + if (client.FindSecret(secret) == null) + { + client.AddSecret(secret); + } } if (redirectUri != null)