Last active
July 18, 2024 19:41
-
-
Save carlin-q-scott/98f96612d90a7ed359e636c089400c7e to your computer and use it in GitHub Desktop.
Reset admin account password for Keycloak using SqlServer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Removes admin account and temporarily reassigns master realm users to a fake realm so that Keycloak will re-create the admin account using the KEYCLOAK_ADMIN and KEYCLOAK_ADMIN_PASSWORD env vars. | |
declare @adminId varchar(36); | |
set @adminId = (select ID from user_entity where USERNAME = 'admin'); | |
delete from credential where user_id = @adminId; | |
delete from user_role_mapping where user_id = @adminId; | |
delete from user_required_action where user_id = @adminId; | |
delete from user_entity where id = @adminId; | |
declare @masterRealmId varchar(36); | |
set @masterRealmId = (select id from realm where realm.name = 'master'); | |
update user_entity set realm_id='banana' from user_entity where realm_id = @masterRealmId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Run after running remove-admin.sql and restarting Keycloak | |
declare @masterRealmId varchar(36); | |
set @masterRealmId = (select id from realm where realm.name = 'master'); | |
update user_entity set realm_id=@masterRealmId where realm_id = 'banana'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment