15

I am trying to setup Keycloak server for our organisation. I have couple of questions.

  1. How can we use our existing user database to authenticate users - User Federation. Keycloak only has LADP/Kerberos options. Is there any custom plugin which can be used for MySQL user authentication or can we use existing connectors itself (LDAP/Kerberos) via some adapter for the database?
  2. Is it possible to have multiple Identity providers within Keycloak environment - (Have Keycloak as IDP for few services, while Keycloak Google IDP for other services).

I have followed the official documentation, but for some reason not able to view the content of the link. Any helpful links to proper guide would be great.

3 Answers 3

11

Check Keycloak Custom User Federation

It means that, to use diffirent datasource (or process) while Keycloak username / password login

see =>

  1. https://github.com/keycloak/keycloak/blob/main/docs/documentation/server_development/topics/user-storage/simple-example.adoc
  2. https://tech.smartling.com/migrate-to-keycloak-with-zero-downtime-8dcab9e7cb2c github => (https://github.com/Smartling/keycloak-user-migration-provider)

First link => explaining how to configure external db to keycloak.

Second link (need changes)=> these examplecan change like that,

  • you can create a custom federation implementation,
  • it will be call your service,
  • your service will be query your db
  • your service will response your result

Second example(my suggestion) will be abstract your custom code (federation process, your service) and keycloak. Keycloak ony call your service, everything else are your implementation.

2
  • 3
    Your first link is no longer available... 1 year later obviously :) Commented Nov 18, 2019 at 11:07
  • For anyone seeing this, I updated the first link on 08-11-2023.
    – Manikandan
    Commented Nov 8, 2023 at 7:08
10

You should implement your own user storage SPI to integrate your MySQL db as an external user storage db

https://www.keycloak.org/docs/latest/server_development/index.html#_user-storage-spi

7

I answered a similar question regarding existing databases user and keycloak authentication (link here)

I published my own solution as a multi RDBMS implementation (oracle, mysql, postgresl, sqlserver) to solve simple database federation needs, supporting bcrypt and several types of hashes.

It is a configurable keycloak custom provider, you will only need the to set some SQL queries and it is ready to use.

It is already compatible with new keycloak quarkus deployment.

Feel free to clone, fork, contribute or do whatever you need to solve your issue.

GitHub repo:

https://github.com/opensingular/singular-keycloak-database-federation

4
  • Whoever is looking for DB connection with keycloak, this answer is gold.
    – maxivis
    Commented Oct 24, 2022 at 12:04
  • @Vinicius Uriel my keycloak instance is deployed on cloud (phasetwo) how i can upload the jar file using keycloak IHM ? because i don't have access to the server files...
    – James
    Commented Dec 3, 2022 at 14:09
  • ERROR [org.keycloak.services.error.KeycloakErrorHandler] (default task-1) Uncaught server error: java.lang.NoClassDefFoundError: org/hibernate/dialect/Dialect
    – James
    Commented Dec 3, 2022 at 15:13
  • Hi James, try opening a issue on github with a few more details it will make it easier to help you Commented Dec 5, 2022 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.