Browse Source

updated keycloak seeder for client_credential data

gterdem/swagger_update
Galip Tolga Erdem 4 years ago
parent
commit
e5ce54f499
  1. 1
      apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs
  2. 5
      services/cmskit/src/EShopOnAbp.CmskitService.HttpApi.Host/appsettings.json
  3. 77
      shared/EShopOnAbp.Keycloak.DbMigrator/KeycloakDataSeeder.cs

1
apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs

@ -162,6 +162,7 @@ public class EShopOnAbpPublicWebModule : AbpModule
options.Scope.Add("AdministrationService");
options.Scope.Add("BasketService");
options.Scope.Add("IdentityService");
options.Scope.Add("CatalogService");
options.Scope.Add("PaymentService");
options.Scope.Add("OrderingService");

5
services/cmskit/src/EShopOnAbp.CmskitService.HttpApi.Host/appsettings.json

@ -1,7 +1,7 @@
{
"App": {
"SelfUrl": "https://localhost:44358",
"CorsOrigins": "https://localhost:44372,https://localhost:44373,http://localhost:4200"
"CorsOrigins": "https://localhost:44372,https://localhost:44373,http://localhost:4200,https://localhost:44335"
},
"AuthServer": {
"Authority": "http://localhost:8080/realms/master",
@ -43,7 +43,8 @@
},
"RemoteServices": {
"AbpIdentity": {
"BaseUrl": "https://localhost:44351"
"BaseUrl": "https://localhost:44351/",
"UseCurrentAccessToken": "false"
}
},
"IdentityClients": {

77
shared/EShopOnAbp.Keycloak.DbMigrator/KeycloakDataSeeder.cs

@ -128,6 +128,83 @@ public class KeyCloakDataSeeder : IDataSeedContributor, ITransientDependency
await CreatePublicWebClientAsync();
await CreateSwaggerClientAsync(); // TODO: Test when Volo.Abp.Swashbuckle v6.0.1 is released (https://github.com/abpframework/abp/pull/14409)
await CreateWebClientAsync();
await CreateCmskitClientAsync();
await CreateAdministrationClientAsync();
}
private async Task CreateAdministrationClientAsync()
{
var administrationClient = (await _keycloakClient.GetClientsAsync(_keycloakOptions.RealmName, clientId: "EShopOnAbp_AdministrationService"))
.FirstOrDefault();
if (administrationClient == null)
{
administrationClient = new Client()
{
ClientId = "EShopOnAbp_AdministrationService",
Name = "Cmskit microservice client",
Protocol = "openid-connect",
PublicClient = false,
ImplicitFlowEnabled = false,
AuthorizationServicesEnabled = false,
StandardFlowEnabled = false,
DirectAccessGrantsEnabled = false,
ServiceAccountsEnabled = true,
Secret = "1q2w3e*"
};
administrationClient.Attributes = new Dictionary<string, object>()
{
{ "oauth2.device.authorization.grant.enabled", false },
{ "oidc.ciba.grant.enabled", false }
};
await _keycloakClient.CreateClientAsync(_keycloakOptions.RealmName, administrationClient);
await AddOptionalClientScopesAsync(
"EShopOnAbp_AdministrationService",
new List<string>
{
"IdentityService"
}
);
}
}
private async Task CreateCmskitClientAsync()
{
var cmsKitClient = (await _keycloakClient.GetClientsAsync(_keycloakOptions.RealmName, clientId: "EShopOnAbp_CmskitService"))
.FirstOrDefault();
if (cmsKitClient == null)
{
cmsKitClient = new Client()
{
ClientId = "EShopOnAbp_CmskitService",
Name = "Cmskit microservice client",
Protocol = "openid-connect",
PublicClient = false,
ImplicitFlowEnabled = false,
AuthorizationServicesEnabled = false,
StandardFlowEnabled = false,
DirectAccessGrantsEnabled = false,
ServiceAccountsEnabled = true,
Secret = "1q2w3e*"
};
cmsKitClient.Attributes = new Dictionary<string, object>()
{
{ "oauth2.device.authorization.grant.enabled", false },
{ "oidc.ciba.grant.enabled", false }
};
}
await _keycloakClient.CreateClientAsync(_keycloakOptions.RealmName, cmsKitClient);
await AddOptionalClientScopesAsync(
"EShopOnAbp_CmskitService",
new List<string>
{
"IdentityService"
}
);
}
private async Task CreateWebClientAsync()

Loading…
Cancel
Save