copy ID into clipboard (in our case it is 5d10b343-a3e3-40a4-82e2-9e30efb658f7)
Open HostHttpApiHostModule.cs-file of the rupbes.tstapp.Auth.Host.csproj-project
modify SeedData()-method as follows:
Click to show the code
privateasyncTaskSeedData(ApplicationInitializationContextcontext){using(varscope=context.ServiceProvider.CreateScope()){varseeder=scope.ServiceProvider.GetRequiredService<IDataSeeder>();awaitseeder.SeedAsync(newDataSeedContext().WithProperty("AdminId",newGuid("5d10b343-a3e3-40a4-82e2-9e30efb658f7"))// your ID of the created keycloak user.WithProperty("AdminEmail","[email protected]")// your Email of the created keycloak user.WithProperty("AdminUserName","tstadmin")// your UserName of the created keycloak user// .WithProperty("AdminPassword", "1q2w3E*") // it doesn't matter what password is set);}}
tstwebapp
open the Properties/launchSettings.json-file of the rupbes.tstapp.Web.Host.csproj-project and copy the value of the "profiles/rupbes.tstapp.Web.Host/applicationUrl"-prop. In our case it is "https://localhost:44377".
In keycloak console
click Manage realms-menu
click rupbes.tstrealm
click Clients-menu
click Create Client-button
On the Create client-page
Client type: OpenID Connect
Client ID: tstwebapp
Client authentication: ON
Authorization: OFF
Authentication flow: Standard flow
Root URL: https://localhost:44377 (we copied this value from Properties/launchSettings.json-file above)
Home URL: https://localhost:44377 (we copied this value from Properties/launchSettings.json-file above)
Web origins: https://localhost:44377 (we copied this value from Properties/launchSettings.json-file above)
Valid redirect URIs: /signin-oidc
Valid post logout redirect URIs: /signout-callback-oidc
click Save-button
On the tstwebapp-page
click Credetentials-tab
copy Client Secret-value into the clipboard. In our case it is LmmU7nynLQR0nsnN6shOw3sGFfatKqvP
Open appsettings.json of the rupbes.tstapp.Web.Host.csproj-project and modify as follows:
the value for the "RemoteServices/Default/BaseUrl" we copied from Properties/launchSettings.json-file of the rupbes.tstapp.Auth.Host.csproj-project
Set correct value for "Redis/Configuration". In our case we use 10.183.96.52:6379
Set correct protocol(http/https), host and port of your keycloak server. In our case it is https://kc.rupbes.by:8445
Set correct value for "AuthServer/RequireHttpsMetadata". In our case we use Https.
the value for "AuthServer/ClientSecret"-prop we copied above
open the Properties/launchSettings.json-file of the rupbes.tstapp.Auth.Host.csproj-project and copy the value of the "profiles/rupbes.tstapp.Auth.Host/applicationUrl"-prop. In our case it is "https://localhost:54635".
In keycloak console
click Manage realms-menu
click rupbes.tstrealm
click Clients-menu
click Create Client-button
On the Create client-page
Client type: OpenID Connect
Client ID: tstauth
Client authentication: ON
Authorization: OFF
Authentication flow: Standard flow
Root URL: https://localhost:54635 (we copied this value from Properties/launchSettings.json-file above)
Home URL: https://localhost:54635 (we copied this value from Properties/launchSettings.json-file above)
Web origins: https://localhost:54635 (we copied this value from Properties/launchSettings.json-file above)
Valid redirect URIs: (did not set, i.e. empty)
Valid post logout redirect URIs: (did not set, i.e. empty)
click Save-button
Open appsettings.json of the rupbes.tstapp.Auth.Host.csproj-project and modify as follows:
Set correct value for "Redis/Configuration". In our case we use 10.183.96.52:6379
Set correct protocol(http/https), host and port of your keycloak server. In our case it is https://kc.rupbes.by:8445
Set correct value for "AuthServer/RequireHttpsMetadata". In our case we use Https.
the value for "App/CorsOrigins"-prop we copied from appsettings.json of the rupbes.tstapp.HttpApi.Host.csproj-project
the value for "ConnectionStrings"-prop we copied from appsettings.json of the rupbes.tstapp.HttpApi.Host.csproj-project (we copied only "Default" connection string)
"AuthServer/SwaggerClientId" and "AuthServer/SwaggerClientSecret" are incorrect for now (because we didn't register it in keycloak and we didn't tested it !!!)
open the Properties/launchSettings.json-file of the rupbes.tstapp.HttpApi.Host.csproj-project and copy the value of the "profiles/rupbes.tstapp.DemoApp/applicationUrl"-prop. In our case it is "https://localhost:44323".
In keycloak console
click Manage realms-menu
click rupbes.tstrealm
click Clients-menu
click Create Client-button
On the Create client-page
Client type: OpenID Connect
Client ID: tstapihost
Client authentication: ON
Authorization: OFF
Authentication flow: Standard flow
Root URL: https://localhost:44323 (we copied this value from Properties/launchSettings.json-file above)
Home URL: https://localhost:44323 (we copied this value from Properties/launchSettings.json-file above)
Web origins: https://localhost:44323 (we copied this value from Properties/launchSettings.json-file above)
Valid redirect URIs: (did not set, i.e. empty)
Valid post logout redirect URIs: (did not set, i.e. empty)
click Save-button
Open appsettings.json of the rupbes.tstapp.HttpApi.Host.csproj-project and modify as follows:
Set correct value for "Redis/Configuration". In our case we use 10.183.96.52:6379
Set correct protocol(http/https), host and port of your keycloak server. In our case it is https://kc.rupbes.by:8445
Set correct value for "AuthServer/RequireHttpsMetadata". In our case we use Https.
the value for "App/CorsOrigins"-prop was generated by abp.cli
the value for "ConnectionStrings"-prop was generated by abp.cli
"AuthServer/SwaggerClientId" and "AuthServer/SwaggerClientSecret" are incorrect for now (because we didn't register it in keycloak and we didn't tested it !!!)
Really, we do not need to define the scope with audience settings for Frontend app. It is just for testing.
In keycloak console
click Manage realms-menu
click rupbes.tstrealm
click Client scopes-menu
click Create Client Scope-button
On the Create client scope-page
Protocol: OpenID Connect
Name: tstwebapp_scope
Type: Optional
click Save-button
On the tstwebapp_scope-page
click Mappers-tab
click Configure new mapper-button
In the Configure a new mapper-dialog
click Audience
On the Add mapper-page
Name: tstwebapp_scope_aud_mapper
Included Client Audience: tstwebapp
Add to access token: ON
Add to token introspection: ON
Included Custom Audience: empty
Add to ID token: OFF
Add to lightweight access token: OFF
click Save-button
Goto clients/tstwebapp-page
click Client scopes-tab
click Add client scope
in the Add client scopes to tstwebapp-dialog
choose tstwebapp_scope
click add/optional
tstauth scope
In keycloak console
click Manage realms-menu
click rupbes.tstrealm
click Client scopes-menu
click Create Client Scope-button
On the Create client scope-page
Protocol: OpenID Connect
Name: tstauth_scope
Type: Optional
click Save-button
On the tstauth_scope-page
click Mappers-tab
click Configure new mapper-button
In the Configure a new mapper-dialog
click Audience
On the Add mapper-page
Name: tstauth_scope_aud_mapper
Included Client Audience: tstauth
Add to access token: ON
Add to token introspection: ON
Included Custom Audience: empty
Add to ID token: OFF
Add to lightweight access token: OFF
click Save-button
Goto clients/tstwebapp-page
click Client scopes-tab
click Add client scope
in the Add client scopes to tstwebapp-dialog
choose tstauth_scope
click add/optional
tstapihost scope
In keycloak console
click Manage realms-menu
click rupbes.tstrealm
click Client scopes-menu
click Create Client Scope-button
On the Create client scope-page
Protocol: OpenID Connect
Name: tstapihost_scope
Type: Optional
click Save-button
On the tstapihost_scope-page
click Mappers-tab
click Configure new mapper-button
In the Configure a new mapper-dialog
click Audience
On the Add mapper-page
Name: tstapihost_scope_aud_mapper
Included Client Audience: tstapihost
Add to access token: ON
Add to token introspection: ON
Included Custom Audience: empty
Add to ID token: OFF
Add to lightweight access token: OFF
click Save-button
Goto clients/tstwebapp-page
click Client scopes-tab
click Add client scope
in the Add client scopes to tstwebapp-dialog
choose tstapihost_scope
click add/optional
admin role
In keycloak console
click Manage realms-menu
click rupbes.tstrealm
click Clients-menu
click tstwebapp-ref
On the tstwebapp-page
click Roles-tab
click Create Role-button
In the Create role-dialog
Role name: Admin
click Save-button
In keycloak console
click Manage realms-menu
click rupbes.tstrealm
click Users-menu
On the Users-page
click tstadmin-ref
On the tstadmin-page
click Role mappings-button
click Assign client role-button
In the Assign Client roles to tstadmin-dialog
choose Admin
click Assign
CustomClaimsTransformation
Our implementation of the CustomClaimsTransformation-class is very simple: it collects all roles of all resources. After the defining appName-var we must add additional filter.