This PoC extension exposes a custom realm resource to manage user avatars. The avatar images are stored in a minio backend.
Avatar images can either be uploaded via the account page of the custom
account theme account-avatar
or via the AvatarResource
custom realm resource.
docker run -p 9000:9000 --name keycloak-avatars \
-e "MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE" \
-e "MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" \
-v $PWD/data:/data \
-v $PWD/config:/root/.minio \
minio/minio server /data
mvn clean verify
Copy to the standalone/deployments
directory in Keycloak.
Configure the avatar-account
theme as account theme in the realm settings.
Open the account page for a user and select and upload an image.
Retrieve access token
KC_USERNAME=tester
KC_PASSWORD=test
KC_CLIENT=admin-cli
KC_CLIENT_SECRET=""
KC_REALM=avatar-demo
KC_URL=http://localhost:8080/auth
KC_RESPONSE=$( \
curl -k \
-d "username=$KC_USERNAME" \
-d "password=$KC_PASSWORD" \
-d 'grant_type=password' \
-d "client_id=$KC_CLIENT" \
-d "client_secret=$KC_CLIENT_SECRET" \
"$KC_URL/realms/$KC_REALM/protocol/openid-connect/token" \
| jq .
)
KC_ACCESS_TOKEN=$(echo $KC_RESPONSE| jq -r .access_token)
KC_ID_TOKEN=$(echo $KC_RESPONSE| jq -r .id_token)
KC_REFRESH_TOKEN=$(echo $KC_RESPONSE| jq -r .refresh_token)
Goto account page and click on 'Choose File' and click save.
curl -v \
-H "Authorization: Bearer $KC_ACCESS_TOKEN" \
http://localhost:8080/auth/realms/$KC_REALM/avatar-provider/avatar \
-o output.png