Coder Social home page Coder Social logo

dystudio / keycloak-avatar-minio-extension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thomasdarimont/keycloak-avatar-minio-extension

0.0 1.0 0.0 92 KB

Simple example for managing avatar images with Keycloak

Java 58.00% FreeMarker 12.63% JavaScript 3.01% HTML 26.36%

keycloak-avatar-minio-extension's Introduction

Simple extension for managing avatar images in Keycloak

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.

Keycloak Avatar Demo

Start the minio backend

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

Build the example

mvn clean verify

Deploy the example

Copy to the standalone/deployments directory in Keycloak.

Uploading an avatar image via account theme

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.

Uploading an avatar image via CURL

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)

Upload avatar image via account page

Goto account page and click on 'Choose File' and click save.

Retrieve avatar image

 curl -v \
   -H "Authorization: Bearer $KC_ACCESS_TOKEN" \
   http://localhost:8080/auth/realms/$KC_REALM/avatar-provider/avatar \
   -o output.png

keycloak-avatar-minio-extension's People

Contributors

ajcamilo avatar thomasdarimont avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.