|
|
|
@ -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<Client> CreateClientAsync( |
|
|
|
string name, |
|
|
|
IEnumerable<string> scopes, |
|
|
|
IEnumerable<string> grantTypes, |
|
|
|
string secret, |
|
|
|
string secret = null, |
|
|
|
string redirectUri = null, |
|
|
|
string postLogoutRedirectUri = null, |
|
|
|
string frontChannelLogoutUri = null, |
|
|
|
bool requireClientSecret = true, |
|
|
|
bool requirePkce = false, |
|
|
|
IEnumerable<string> 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) |
|
|
|
|