Giter Club home page Giter Club logo

keycloak-rest-api-extensions's Introduction

keycloak-rest-api-extensions

This module implementents extensions to keycloak's REST API. Currently implemented functions are:

  • admin
    • gets a list of users credentials
    • delete a credential
    • gets users filtered by group or by role
    • get user statistics
    • get credentials statistics
  • account : Fix a bug with CORS

Currently works under keycloak 20.0.5

Installation

Requires java 17 and maven 3.X

mvn clean package
keycloak-rest-api-extensions/install.sh <KEYCLOAK_HOME>

Add the following to the launch parameters of Keycloak:

-Dkeycloak.profile.feature.account_api=enabled

Usage

To call the REST first get an access token as described in Keycloak's documentation.

Credentials

To get the credentials:

curl \
  -H "Authorization: bearer eyJhbGciOiJSUz..." \
  "http://localhost:8080/auth/realms/master/api/admin/realms/{realm}/users/{userid}/credentials"

If you want to delete a credential:

curl \
  -H "Authorization: bearer eyJhbGciOiJSUz..." \
  -v -X "DELETE"
  "http://localhost:8080/auth/realms/master/api/admin/realms/{realm}/users/{userid}/credentials/{credentialid}"

Users filtered by group or by role

To get a list of users filtered by group id:

curl \
  -H "Authorization: bearer eyJhbGciOiJSUz..." \
  "http://localhost:8080/auth/realms/master/api/admin/realms/{realm}/users?groupId=group1

Note: it must be the group id, not the name. It is also possible to filter by multiple groups, for example with .../users?groupId=group1&groupId=group2. This will return the union of all users in group1 and all users in group2

To get a list of users filtered by role id

curl \
  -H "Authorization: bearer eyJhbGciOiJSUz..." \
  "http://localhost:8080/auth/realms/master/api/admin/realms/{realm}/users?roleId=role1

It is also possible to filter by multiple roles, for example with .../users?roleId=role1&roleId=role2. This will return the union of all users with role1 and all users with role2

It is also possible to combine the two:

curl \
  -H "Authorization: bearer eyJhbGciOiJSUz..." \
  "http://localhost:8080/auth/realms/master/api/admin/realms/{realm}/users?roleId=role1&roleId=role2&groupId=group1&groupId=group2

This will search the intersection of users with groups group1 or group2 and of users with roles role1 and role2

User creation with Groups and Roles

To create a user with a specific group and role

curl \
  -H "Authorization: bearer eyJhbGciOiJSUz..." \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{ "email": "[email protected]", "username": "toto", "realmRoles": ["010b904b-f052-4f4c-a3f1-4b14da3a3448"], "groups": ["dc1689ff-ece8-4b34-bc31-66ea9b254290", "c322b499-0e32-4d42-a76d-a832b4fbb2f9"]}' \
   http://localhost:8080/auth/realms/master/api/admin/realms/master/users

The user will be created with roles and groups assigned.

Statistics

To get the users statistics

curl \
  -H "Authorization: bearer eyJhbGciOiJSUz..." \
  "http://localhost:8080/auth/realms/master/api/admin/realms/{realm}/statistics/users

To get the credentials statistics

curl \
  -H "Authorization: bearer eyJhbGciOiJSUz..." \
  "http://localhost:8080/auth/realms/master/api/admin/realms/{realm}/statistics/credentials

keycloak-rest-api-extensions's People

Contributors

alistairdoswald avatar basbeu avatar bernardgut avatar fperot74 avatar fratt avatar fratt-elca avatar harture avatar lagess avatar vloup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.