I'm new to keycloak I have created custom SPI for authenticating users, i want to save user info in keycloak db after successful authentication.
I have gone through the documentation and there I found that using this interface org.keycloak.storage.user.UserRegistrationProvider we can register new user, In my case I need to update user info in keycloak db after user is authenticated.
Here's my code
public void authenticate(AuthenticationFlowContext context) {
boolean isValidToken= false;
try {
isValidToken = validateToken(jwsObject, context.getAuthenticatorConfig());
} catch (Exception e) {
log.info("validate Token error",e);
context.attempted();
}
if (username != null) {
UserModel user = KeycloakModelUtils.findUserByNameOrEmail(session,
session.getContext().getRealm(), username);
if (user == null) {
log.info("No user with provided username");
context.attempted();
} else if (!user.isEnabled()) {
log.info("User is disabled");
context.attempted();
} else {
log.info("Successfully authenticated the user");
// here i want to save some info in Keycloak fb
context.setUser(user);
context.success();
}
}
}
please suggest or refer some code or material that can help in saving info in keycloak db