Browse Source

Update IdentityServerDataSeeContributor of module template

pull/5614/head
Ahmet 6 years ago
parent
commit
dde6ff69c3
  1. 1
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs
  2. 43
      templates/module/aspnet-core/host/MyCompanyName.MyProjectName.IdentityServer/IdentityServer/IdentityServerDataSeedContributor.cs

1
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs

@ -155,6 +155,7 @@ namespace MyCompanyName.MyProjectName.IdentityServer
grantTypes: new[] { "authorization_code" }, grantTypes: new[] { "authorization_code" },
secret: configurationSection["MyProjectName_Blazor:ClientSecret"]?.Sha256(), secret: configurationSection["MyProjectName_Blazor:ClientSecret"]?.Sha256(),
requireClientSecret: false, requireClientSecret: false,
requirePkce: true,
redirectUri: $"{blazorRootUrl}/authentication/login-callback", redirectUri: $"{blazorRootUrl}/authentication/login-callback",
postLogoutRedirectUri: $"{blazorRootUrl}/authentication/logout-callback" postLogoutRedirectUri: $"{blazorRootUrl}/authentication/logout-callback"
); );

43
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.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using IdentityServer4.Models;
using Microsoft.Extensions.Configuration;
using Volo.Abp.Authorization.Permissions; using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -11,6 +12,8 @@ using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.IdentityResources; using Volo.Abp.IdentityServer.IdentityResources;
using Volo.Abp.PermissionManagement; using Volo.Abp.PermissionManagement;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using ApiResource = Volo.Abp.IdentityServer.ApiResources.ApiResource;
using Client = Volo.Abp.IdentityServer.Clients.Client;
namespace MyCompanyName.MyProjectName.IdentityServer namespace MyCompanyName.MyProjectName.IdentityServer
{ {
@ -131,15 +134,37 @@ namespace MyCompanyName.MyProjectName.IdentityServer
commonSecret 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( private async Task<Client> CreateClientAsync(
string name, string name,
IEnumerable<string> scopes, IEnumerable<string> scopes,
IEnumerable<string> grantTypes, IEnumerable<string> grantTypes,
string secret, string secret = null,
string redirectUri = null, string redirectUri = null,
string postLogoutRedirectUri = null, string postLogoutRedirectUri = null,
string frontChannelLogoutUri = null,
bool requireClientSecret = true,
bool requirePkce = false,
IEnumerable<string> permissions = null) IEnumerable<string> permissions = null)
{ {
var client = await _clientRepository.FindByCliendIdAsync(name); var client = await _clientRepository.FindByCliendIdAsync(name);
@ -160,7 +185,10 @@ namespace MyCompanyName.MyProjectName.IdentityServer
AccessTokenLifetime = 31536000, //365 days AccessTokenLifetime = 31536000, //365 days
AuthorizationCodeLifetime = 300, AuthorizationCodeLifetime = 300,
IdentityTokenLifetime = 300, IdentityTokenLifetime = 300,
RequireConsent = false RequireConsent = false,
FrontChannelLogoutUri = frontChannelLogoutUri,
RequireClientSecret = requireClientSecret,
RequirePkce = requirePkce
}, },
autoSave: true 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) if (redirectUri != null)

Loading…
Cancel
Save