Search Results :

×

SSO Login into Drupal using Keycloak as OAuth / OpenID Connect Provider

SSO Login into Drupal using Keycloak as OAuth / OpenID Connect Provider


Drupal OAuth/OpenID Connect SSO integration enables SSO between the Drupal site and Keycloak. This setup guide helps in configuring Single Sign-On (SSO) between the Drupal site and Keycloak using the OAuth/OpenID Connect module. When you incorporate the OAuth/OpenID Connect module with the Drupal site, you can log into the Drupal site seamlessly with Keycloak credentials. This module is compatible with Drupal 7, Drupal 8, Drupal 9, and Drupal 10.

Installation Steps:


  • Download the module:
    composer require 'drupal/miniorange_oauth_client'
  • Navigate to Extend menu on your Drupal admin console and search for miniOrange OAuth Client Configuration using the search box.
  • Enable the module by checking the checkbox and click on the Install button.
  • You can configure the module at:
    {BaseURL}/admin/config/people/miniorange_oauth_client/config_clc
  • Install the module:
    drush en drupal/miniorange_oauth_client
  • Clear the cache:
     drush cr
  • You can configure the module at:
    {BaseURL}/admin/config/people/miniorange_oauth_client/config_clc
  • Navigate to Extend menu on your Drupal admin console and click on Install new module.
  • Install the Drupal OAuth & OpenID Connect Login - OAuth2 Client SSO Login module either by downloading the zip or from the URL of the package (tar/zip).
  • Click on Enable newly added modules.
  • Enable this module by checking the checkbox and click on install button.
  • You can configure the module at:
    {BaseURL}/admin/config/people/miniorange_oauth_client/config_clc

Set up Drupal as OAuth Client:

  • After installing the module, navigate to the Configuration -> miniOrange OAuth Client Configuration -> Configure OAuth tab.
  • Drupal OAuth Client - Configuration tab and select miniorange oauth client module
  • Select Keycloak from the Select Application dropdown.
  • Copy the Callback/Redirect URL and keep it handy.
  • Note: If your provider only supports HTTPS Callback/Redirect URLs and you have an HTTP site, please make sure to enable the 'Enforce HTTPS Callback URL' checkbox at the bottom of the tab.

  • Enter the Display Name as the Keycloak.
  • Drupal OAuth Client - Configure OAuth tab Select Keycloak and copy the Callback URL

Create OAuth/OpenID Single Sign-On Application in Keycloak:

  • Log into your Keycloak administrator console.
  • Select Create Realm from the master dropdown menu.
  • Keycloak OAuth/OIDC Single Sign On - Navigate to the master and click on Create Realm button
  • Enter the application name in the Realm name text field and click on the Create button to proceed.
  • Keycloak OAuth/OIDC Single Sign On - enter application name in Realm name text field
  • Navigate to the Clients -> Clients list -> Create client.
  • Keycloak OAuth/OIDC Single Sign On - Click on create client button
  • In the General Settings, enter the Client ID and click on the Next button.
  • Keycloak OAuth/OIDC Single Sign On - enter Client ID name into the text field
  • In the Capability Config, enable the checkbox for Client authentication and click on the Next button.
  • Keycloak OAuth/OIDC Single Sign On - Enable the Client authentication checkbox
  • In the Login settings, paste the Callback/Redirect URL into the Valid redirect URIs text field and click on the Save button.
  • Keycloak OAuth/OIDC Single Sign On - Copy the Callback URL that you have copied from OAuth Client module and paste it into the field

Integrating Drupal with Keycloak:

  • Go to your Keycloak Application. On the Settings tab, copy the Client ID from the General Settings section. Keep it handy.
  • Keycloak OAuth/OIDC Single Sign On - Copy the Client ID name and keep it handy
  • In Drupal’s Configure OAuth tab paste the copied Client ID into the Client ID text field.
  • Drupal OAuth/OIDC Single Sign On - paste the copied client id into the text field
  • Go to your Keycloak Application, navigate to the Credentials tab, and copy the Client secret by clicking on the Icon to copy it to the clipboard.
  • Keycloak OAuth/OIDC Single Sign On - Copy the Client Secret
  • In Drupal’s Configure OAuth tab, paste the copied Client secret into the Client Secret text field.
  • Drupal OAuth/OIDC Single Sign On - Paste the copied Client Secret into the field

    Enter the following information in the corresponding text fields of the Configure OAuth tab of the Drupal OAuth Client module.

    Scope openid email profile
    Authorize Endpoint (Keycloak base URL)/realms/{realm-name}/protocol/openid-connect/auth
    Access Token Endpoint (Keycloak base URL)/realms/{realm-name}/protocol/openid-connect/token
    Get User Info Endpoint (Keycloak base URL)/realms/{realm-name}/protocol/openid-connect/userinfo
  • Go to the Keycloak Administrator console.
  • Navigate to Realm settings -> General and copy the Realm ID by clicking on copy Icon.
  • Keycloak OAuth/OIDC Single Sign On - copy the Realm name
  • In Drupal’s Configure OAuth tab, replace the previously copied Realm ID with "realm-name" in the Authorize Endpoint, Access Token Endpoint, and Get User Info Endpoint text fields, respectively.
  • Drupal OAuth/OIDC Single Sign On - Paste the copied Realm name into respected field
  • Navigate to the Keycloak Administrator console and copy the Keycloak domain URL. For example, if your Keycloak is running on localhost, then the domain would be "https://localhost:8080”. (refer to the below image)
  • Keycloak OAuth/OIDC Single Sign On - Copy the Keycloak domain name
  • In Drupal’s Configure OAuth tab, replace "Keycloak_base_URL" with the copied Keycloak domain URL in the Authorize Endpoint, Access Token Endpoint, and Get User Info Endpoint text fields. Then, click on the Save Configuration button to proceed.
  • Drupal OAuth/OIDC Single Sign On - Copy the Keycloak domain name

miniorange img Steps to configure Keycloak as OAuth Provider:

  • First of all, Download Keycloak and install it.
  • Start Server: Start the keycloak server by running the _standalone.sh_ file Root Directory of keycloak/bin/standalone.sh
  • Create Realm: Now login to keycloak administration console and navigate to your desired realm. You can add a new realm by selecting Create Realm option.
  • Keycloak - Login Add Realm
  • Create Realm: Enter Realm Name and click on CREATE to add realm.
  • Keycloak - Login create Realm
  • Enter the Client ID and click on the Save button.
  • Keycloak - create client ID
  • Enable the Client authentication and click on the Save button.
  • Keycloak - client authentication
  • Paste the copied (in step1) callback url into the Valid Redirect URLs text area and click on the Save button.
  • Keycloak - paste redirect-url

miniorange img Integrating Drupal with Keycloak

  • Copy the Client ID from the Keycloak application, client ID will be your client name.
  • Keycloak SSO Client id
  • Navigate to the Credentials tab and copy the Client Secret.
  • Keycloak SSO Client secret
  • In Drupal’s Configure OAuth tab paste the copied Client ID and Client Secret (copied from the Keycloak Portal) in the Client ID and Client Secret text-field.
  • Keycloak - Client Credentials
  • Copy the Keycloak Domain and Keycloak realm.
  • Replace the copied Keycloak Domain & Keycloak realm with the {your Domain} and {realm-name} in the Authorize Endpoint, Access Token Endpoint, and Get User Info Endpoint respectively.
  • Click on the Save Configuration button.
  • Keycloak - scope and endpoints
  • Keycloak Scope and Endpoints:
  • Scope: openid email profile
    Authorize Endpoint: (Keycloak base URL)/realms/{realm-name}/protocol/openid-connect/auth
    Access Token Endpoint: (Keycloak base URL)/realms/{realm-name}/protocol/openid-connect/token
    Get User Info Endpoint: (Keycloak base URL)/realms/{realm-name}/protocol/openid-connect/userinfo

2. Configure SSO Application in Keycloak

  • First of all, Download Keycloak and install it.
  • Start Server: Start the keycloak server by running the _standalone.sh_ file Root Directory of keycloak/bin/standalone.sh
  • Add Realm: Now login to keycloak administration console and navigate to your desired realm. You can add new realm by selecting Add Realm option.
  • Keycloak - Login Add Realm
  • Create Realm: Enter Realm Name and click on CREATE to add realm.
  • Keycloak - Login create Realm
  • Now, enter the Display name and click on the Save button.
  • Keycloak - enter display name
  • Navigate to the Clients tab and click on Create button.
  • Keycloak - Click on create button
  • Enter the Client ID and click on the Save button.
  • Keycloak - create client ID
  • Paste the previously copied Callback/Redirect URL into the Valid Redirect URLs text field and click on Save button.
  • Keycloak - paste redirect-url

3. Integrating Drupal with Keycloak

  • Copy the Client ID from the Keycloak application, client ID will be your client name.
  • Keycloak SSO Client id
  • Navigate to the Credentials tab and copy the Client Secret.
  • Keycloak SSO Client secret
  • In Drupal’s Configure OAuth tab paste the copied Client ID and Client Secret (copied from the Keycloak Portal) in the Client ID and Client Secret text-field.
  • Keycloak - Client Credentials
  • Copy the Keycloak Domain and Keycloak realm.
  • Replace the copied Keycloak Domain & Keycloak realm with the {your Domain} and {realm-name} in the Authorize Endpoint, Access Token Endpoint, and Get User Info Endpoint respectively then click on the Save Configuration button.
  • Keycloak - scope and endpoints
  • You have successfully completed your Keycloak App OAuth Server side configurations.
  • Enter the following Keycloak Scope and Endpoints:
  • Client ID : from the above step
    Client Secret : from the above step
    Scope email profile
    Authorize Endpoint (Keycloak base URL)/realms/{realm-name}/protocol/openid-connect/auth
    Access Token Endpoint (Keycloak base URL)/realms/{realm-name}/protocol/openid-connect/token
    Get User Info Endpoint (Keycloak base URL)/realms/{realm-name}/protocol/openid-connect/userinfo

Test connection between Drupal and Keycloak:

  • After saving the configuration, click on the Perform Test Configuration button to test the connection between Drupal and Keycloak.
  • Drupal OAuth OpenID Single Single On - Click on Perform Test Configuration to test connection between Drupal and Keyclaok
  • On a Test Configuration popup, if you don't have an active session in keycloak on the same browser, you will be asked to sign in to your Keycloak administrator console. After successfully logging into Keycloak, you will be provided with a list of attributes that are received from the Keycloak.
  • Select the Email Attribute from the dropdown menu in which the user's email ID is obtained and click on the Done button.
  • Drupal OAuth OpenID Single Single On - If test connection is successfull, you will received the attribute list from keycloak
  • Once you click on the Done button, you will be redirected to the Attribute & Role Mapping tab, in which you can select the Username Attribute from the dropdown and click on the Save Configuration button.
  • Keycloak sso login with drupal OAuth OpenID Single Single On Keycloak test Configuration successfully

Note: Mapping the Email attribute is mandatory for Login.

Congratulations! You have successfully configured Keycloak as OAuth Provider and Drupal as OAuth Client.

How to perform the SSO?

  • Now, open a new browser/private window and go to your Drupal site login page.
  • Click on the Login using the Keycloak link to initiate the SSO from Drupal.
  • If you want to add the SSO link to other pages as well, please follow the steps given in the image below:
  • Drupal OAuth OpenID Single Single-On - Add login link into different page of the Drupal site

Need Assistance?

If you face any issues during the configuration or if you want some additional features, please contact us at drupalsupport@xecurify.com.

Additional Features:

Troubleshooting:

Getting error: ‘Username not received. Check your Attribute Mapping configuration.’ OR Getting Error: ‘Email not received. Check your Attribute Mapping configuration.’
 

Follow the steps mentioned HERE

I am getting “Client Credentials were not found in the headers or body” when I try to perform test configuration
 

Follow the steps mentioned HERE

After I click on the logout in Drupal, it sends me back to the Drupal homepage. However, when I try to login with other user, it doesn’t ask me to login but automatically logs me in with same user
 

The logout functionality you’ve mentioned here is the default behavior of a module. It’s logging you out of Drupal but not from your Application/Provider. To allow the module to logout from your provider/application account (what you are looking for), you need to make the below configurations: [know more]

I purchased the paid Drupal module and replaced it with the free module, but still I am not able to use paid features.
 

As you have upgraded to one of our paid versions of the Drupal module and replaced the free module with the paid one, you must first activate the paid module. Please refer to the below steps. [Know more]

Frequently Asked Questions (FAQ)
 

[Know more]

 Case Studies
miniOrange has successfully catered to the use cases of 400+ trusted customers with its highly flexible/customizable Drupal solutions. Feel free to check out some of our unique case studies using this link.
 Other Solutions
Feel free to explore other Drupal solutions that we offer here. The popular solutions used by our trusted customers include Two Factor Authentication - 2FA, Website Security, REST & JSON API Authentication, User Provisioning and Sync. 
  24*7 Active Support
The Drupal developers at miniOrange offer quick and active support for your queries. We can assist you from choosing the best solution for your use case to deploying and maintaining the solution.
Hello there!

Need Help? We are right here!

support
Contact miniOrange Support
success

Thanks for your inquiry.

If you dont hear from us within 24 hours, please feel free to send a follow up email to info@xecurify.com