Browse Source

Merge branch 'dev' into blazor-ui-page-header

pull/5836/head
İlkay İlknur 5 years ago
parent
commit
f1cc72f017
  1. 32
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs

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

@ -7,8 +7,8 @@ using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.ApiResources;
using Volo.Abp.IdentityServer.ApiScopes;
using Volo.Abp.IdentityServer.Clients;
using Volo.Abp.IdentityServer.IdentityResources;
using Volo.Abp.PermissionManagement;
@ -52,10 +52,15 @@ namespace MyCompanyName.MyProjectName.IdentityServer
{
await _identityResourceDataSeeder.CreateStandardResourcesAsync();
await CreateApiResourcesAsync();
await CreateApiScopeAsync();
await CreateApiScopesAsync();
await CreateClientsAsync();
}
private async Task CreateApiScopesAsync()
{
await CreateApiScopeAsync("MyProjectName");
}
private async Task CreateApiResourcesAsync()
{
var commonApiUserClaims = new[]
@ -97,13 +102,22 @@ namespace MyCompanyName.MyProjectName.IdentityServer
return await _apiResourceRepository.UpdateAsync(apiResource);
}
private async Task CreateApiScopeAsync()
private async Task<ApiScope> CreateApiScopeAsync(string name)
{
var apiScope = await _apiScopeRepository.GetByNameAsync("MyProjectName");
var apiScope = await _apiScopeRepository.GetByNameAsync(name);
if (apiScope == null)
{
await _apiScopeRepository.InsertAsync(new ApiScope(_guidGenerator.Create(), "MyProjectName", "MyProjectName API"), autoSave: true);
apiScope = await _apiScopeRepository.InsertAsync(
new ApiScope(
_guidGenerator.Create(),
name,
name + " API"
),
autoSave: true
);
}
return apiScope;
}
private async Task CreateClientsAsync()
@ -116,7 +130,6 @@ namespace MyCompanyName.MyProjectName.IdentityServer
"role",
"phone",
"address",
"MyProjectName"
};
@ -134,7 +147,7 @@ namespace MyCompanyName.MyProjectName.IdentityServer
await CreateClientAsync(
name: webClientId,
scopes: commonScopes,
grantTypes: new[] {"hybrid"},
grantTypes: new[] { "hybrid" },
secret: (configurationSection["MyProjectName_Web:ClientSecret"] ?? "1q2w3e*").Sha256(),
redirectUri: $"{webClientRootUrl}signin-oidc",
postLogoutRedirectUri: $"{webClientRootUrl}signout-callback-oidc",
@ -151,7 +164,7 @@ namespace MyCompanyName.MyProjectName.IdentityServer
await CreateClientAsync(
name: consoleAndAngularClientId,
scopes: commonScopes,
grantTypes: new[] {"password", "client_credentials", "authorization_code"},
grantTypes: new[] { "password", "client_credentials", "authorization_code" },
secret: (configurationSection["MyProjectName_App:ClientSecret"] ?? "1q2w3e*").Sha256(),
requireClientSecret: false,
redirectUri: webClientRootUrl,
@ -171,7 +184,6 @@ 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"
);
@ -269,4 +281,4 @@ namespace MyCompanyName.MyProjectName.IdentityServer
return await _clientRepository.UpdateAsync(client);
}
}
}
}
Loading…
Cancel
Save