diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs index f36c9b6e..fa85989a 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs +++ b/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"); diff --git a/services/cmskit/src/EShopOnAbp.CmskitService.HttpApi.Host/appsettings.json b/services/cmskit/src/EShopOnAbp.CmskitService.HttpApi.Host/appsettings.json index 6fefb7e9..239346e8 100644 --- a/services/cmskit/src/EShopOnAbp.CmskitService.HttpApi.Host/appsettings.json +++ b/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": { diff --git a/shared/EShopOnAbp.Keycloak.DbMigrator/KeycloakDataSeeder.cs b/shared/EShopOnAbp.Keycloak.DbMigrator/KeycloakDataSeeder.cs index 2956e3d4..dbb0af1a 100644 --- a/shared/EShopOnAbp.Keycloak.DbMigrator/KeycloakDataSeeder.cs +++ b/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() + { + { "oauth2.device.authorization.grant.enabled", false }, + { "oidc.ciba.grant.enabled", false } + }; + + await _keycloakClient.CreateClientAsync(_keycloakOptions.RealmName, administrationClient); + + await AddOptionalClientScopesAsync( + "EShopOnAbp_AdministrationService", + new List + { + "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() + { + { "oauth2.device.authorization.grant.enabled", false }, + { "oidc.ciba.grant.enabled", false } + }; + } + await _keycloakClient.CreateClientAsync(_keycloakOptions.RealmName, cmsKitClient); + + await AddOptionalClientScopesAsync( + "EShopOnAbp_CmskitService", + new List + { + "IdentityService" + } + ); } private async Task CreateWebClientAsync()