-
Notifications
You must be signed in to change notification settings - Fork 298
Keycloak and User Synchronization #261
Description
In Keycloak, the user ID should be the same as the ID in the identity users table. The "sub" claim in the token should exist in users.
Currently, when creating users in EShopIdentityUserAppService, the ID will not be the same:
Line 38 in 327fbcc
| public override async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input) |
var createdUser = await base.CreateAsync(input);
await _backgroundJobManager.EnqueueAsync(new IdentityUserCreationArgs(input));Each one will create a different ID.
When CreateUserLoggedInEto is executed:
eShopOnAbp/apps/public-web/src/EShopOnAbp.PublicWeb/EShopOnAbpPublicWebModule.cs
Line 199 in 327fbcc
| var userLoggedInEto = CreateUserLoggedInEto(authContext.Principal, authContext.HttpContext); |
and the event is published:
eShopOnAbp/services/identity/src/EShopOnAbp.IdentityService.Application/UserLoggedInEventHandler.cs
Line 34 in 327fbcc
| public virtual async Task HandleEventAsync(UserLoggedInEto eventData) |
For the admin user, this process is fine as it will delete and re-create the admin user to match the ID.
However, for other users, it will attempt to re-create them with the same username but without roles. This can lead to validation issues when creating a new user with the same name.
We are trying to integrate an ABP project with Keycloak. The issue is with the first created user, "admin." We need to sync it with Keycloak in Data Seeder.