Browse Source

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

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