This UserStorageProvider plugin will seamlessly migrate users from an existing Cognito user pool into Keycloak.
When an user attempts to login:
When an user is successfully migrated, its attributes in Cognito will also be copied to Keycloak, with a cognito_
prefix (See webhook example below).
standalone/deployments/
folder.There is a "On Account Created" and "On Credentials Migrated" webhook configuration.
When set, the plugin will invoke the webhook with a POST method and a JSON payload in the form shown below (typescript notation):
Note: Payload of "On Account Created" is an array, because accounts can be bulk-created via the Sync button
interface WebhookPayload {
id: string;
attributes: Record<string, string>;
}
Example:
{
"id": "8dc7fd6e-ffff-4820-88fa-2395129c3f5a",
"attributes": {
"cognito_preferred_mfa_setting": null,
"cognito_user_status": "CONFIRMED",
"cognito_email_verified": "true",
"cognito_user_create_date": "2018-06-15T06:01:16Z",
"cognito_user_last_modified_date": "2020-12-02T05:32:25Z",
"cognito_username": "25d75cdd-ffff-4dc2-a913-156603436cc6",
"cognito_sub": "25d75cdd-ffff-4dc2-a913-156603436cc6",
"cognito_email": "user@abc.xyz",
}
}
This plugin also exposes an API that allow searching migrated users by their Cognito ID and will return the Keycloak User ID if found, or null otherwise.
Item | Details |
---|---|
Method | GET |
Path | /realms/master/cognito-migration/search |
Query Param | id (cognito id), realm |
Response | {result:null\|string} |
Example: curl http://localhost:8080/admin/realms/master/cognito-migration/search?id=my-cognito-id&realm=my-realm
When creating the user and setting its password in keycloak local database, the realm's password policies will apply. That means if the user's password in Cognito does not comply with the policies, the migration will fail. So make sure your realm's policies match those in your Cognito user pool.
mvn package
cp target/keycloak-cognito-migration*.jar .devcontainer/keycloak/deployments/
References: