Skip to content

Instantly share code, notes, and snippets.

Last active August 31, 2021 14:13
Show Gist options
  • Save thomasdarimont/17fa146c4fb5440d7fc2ee6322ec392d to your computer and use it in GitHub Desktop.
Save thomasdarimont/17fa146c4fb5440d7fc2ee6322ec392d to your computer and use it in GitHub Desktop.
Use Keycloak as Identity provider for Drupal

Keycloak with Drupal

Create docker container

Install openid_connect module

cd /var/www/sites/all/
drush dl openid_connect && drush en openid_connect

Setup IPTables

Special case: if you run keycloak on the host machine, you might need to allow docker containers to access the host machine with an additional iptables rule.

For adding the rule just run the following:

sudo iptables -A INPUT -i docker0 -j ACCEPT

you should be able to do a curl -v

For deleting the rule just run:

sudo iptables -D INPUT -i docker0 -j ACCEPT

Configure Keycloak

In my example I run the default KeycloakServer from the integration tests with

Where the IP's are used as follows:

// -> IP of keycloak host
// -> IP of drupal container

Configure Keycloak CLient

Create a client for drupal with the following settings:

client id: drupal
client name: drupal

Client Protocol: openid-connect
Access type: confidential

Standard Flow Enabled: true

Valid redirect url:*

Base URL:

Web Origins:*

Create test user

username: test
firstname: Theo
lastname: Tester

Password: test

Configure Drupal

Tested with drupal (7.x).

configure openid_connect module

in configuration -> web services -> openid_connect

Enabled OpenID Connect clients: select "generic"

clientid: drupal
client secret: 45acbe37-b05e-4aac-b721-d95abf27ad5a

Authorization endpoint:
Token endpoint:
User Info endpoint:

User claims mapping:
Time Zone: zoneinfo

add login block

structure -> blocks -> Disabled -> Select block "OpenID Connect login" -> add to sidebar first

To login simply point a browser to your drupal installation and click on "login with generic".

Copy link

Nice work! but, how do yo map keycloal roles to drupal roles?
I've followed your steps and now I can log in to Drupal with a keycloak user, but inside Drupal this user has no rol.

Copy link

@leitonet try to create a role in the drupal client within Keycloak.
Then assign the client role to a user - this might transfer the role to drupal.

Copy link

johnreytanquinco commented Dec 14, 2016


Thanks for this step by step instruction. One thing i noticed is that there is no log messages for certain errors or processes being done. There is an item under manage, called Events, but doesn't include any logs.

Is there any? Thanks!

Copy link

Hi Thomas, I have done what you sad.

I have a client with the following roles: "ACO - Editor" and "Equipe Web".
I have assigned that roles to specific groups: "ACO Editores" and "GTI Equipe Web".
And these groups to the correct users on Keycloak server.

The user is created but no role is assigned properly.

How can I trace it?

Thanks a ton.

Best Regards,
Ricardo Morais

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment