Code Monkey home page Code Monkey logo

keycloak-custom-attribute-idp-linking's Introduction

Keycloak Custom Attribute IDP Linking

Build Release

Keycloak default authenticator flows for external identity provider brokering only match existing users only on username and password attributes. If you want to lookup user with different attributes you can use this extension. If you for example get attribute eid from your external provider and want your local user, for example from ldap storage provider matched where you store this eid value in an attribute with name u_eid you can do so. Matching attributes will add identity provider links in keycloak and your users will not get created twice in your keycloak database. An example would be European Union eIDAS project with services/members like ID Austria.

Development

mvn clean install
docker-compose up

Update Plugin in container by running mvn install.

Attach remote jvm debug session on port 5005 (default).

Installation

Tested on Keycloak 15.0.2, 17.0.0, `22.0.3.

Keycloak >= v17.0.0

After Packaging the project with,

mvn package -f "./pom.xml"

deploy the keycloak-custom-attribute-idp-linking-2.0.1.jar to /opt/keycloak/providers and rebuild keycloak to bring this provider in.

Deploy custom attribute provider

# Sometimes (depending on versions), this dir is not present;
[ ! -d "/opt/keycloak/providers" ] && sudo mkdir /opt/keycloak/providers;
sudo mv keycloak-custom-attribute-idp-linking-2.0.1.jar /opt/keycloak/providers/keycloak-custom-attribute-idp-linking-2.0.1.jar;

Rebuild and Restart Keycloak

all-in-one: This is the suggested method, check Keycloak's Docs for more configuration options from the cli

# This will rebuild keycloak and make the provider available in the Keycloak admin console
sudo /opt/keycloak/bin/kc.sh start --auto-build;

build only:

/opt/keycloak/bin/kc.sh build

Keycloak <= 15.0.2

Copy or mount plugin in your keycloak installation depending on your environment (k8s, compose, gke). For example in /opt/jboss/keycloak/standalone/deployments/ (see file docker-compose.yml). You should see something like following in your keycloak log:

...
WFLYSRV0010: Deployed "keycloak-custom-attribute-idp-linking-1.0.0.jar" (runtime-name : "keycloak-custom-attribute-idp-linking-1.0.0.jar")
...

Now you can use Custom Attribute IDP Linking Authenticator in your Keycloak Authentication configuration.

Using the Provider

Custom Attribute IDP Linking

Setup below is only for testing and your production configuration might differ. Read more about Keycloak Authenticators and Flows Configurations.

[Optional] Check your external provider attribute mapping

If necessary check whether you really map and import the attribute you want to use for matching users.

IDP attribute mappers

IDP custom attribute mapping

Create Custom Authentication Flow

Go to Authentication and create a new Flow. In this example will call it Auto-linking. Next add this extensions Custom Attribute IDP Linking execution as well as the standard Automatically Set Existing User as a fallback.

Custom authentication flow

Adjust configuration to your needs. Attribute name on external side and lookup attribute for existing users.

Set custom execution config

Adjust custom execution config

Set first login flow

Set first login flow in your identity provider configuration to your newly created custom flow.

Set first login flow

[Optional ;)] Check config

Login in using your external provider and check if user get linked to the provider.

IDP Login

User id provider links

User id provider link

keycloak-custom-attribute-idp-linking's People

Contributors

azayzel avatar sd-f avatar

Stargazers

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

Watchers

 avatar

keycloak-custom-attribute-idp-linking's Issues

Question: how to prepare eid/austria id on users?

Hello,

thank you very much fir your awesome repo!
This fits my usecase nearly perfect.

I can not wrap my head around how the eid or austria id should be prepared beforehand for each user?

My current understanding is:

  • existing local user logs in with local credentials
  • locally authenticated user invokes identity provider account linking
  • Redirected to Austria ID
  • On successful authentication with Austria ID user is returned to keycloak an we store the needed information as an user attribute locally
  • now the user can use Austria ID to authenticate
  • On successful authentication with Austria ID user is returned to keycloak an we look up the user by the custom attribute.

However currently I have no way of extracting claims from the token during identity provider account linking.
I tried setting up an event handler. The event will only contain the „identity_provider_identity“ (which is the claim „sub“ from the token returned by Austria ID)

How do you set the custom attributes to your local users?

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.