Advertising sustains the DA. Ads are hidden for members. Join today

Drupal OAuth & OpenID Connect Login - OAuth2 Client SSO Login

Configure AWS Cognito as OAuth / OpenID Connect provider for Drupal login

Last updated on
14 February 2024

This document will help you configure AWS Cognito as an OpenID Provider making Drupal an OAuth Client. Following these steps will allow you to configure OAuth / OpenID Single Sign-On (SSO) between AWS Cognito and your Drupal site such that your users will be able to log in to your Drupal site using their AWS Cognito credentials. 

We provide Drupal OAuth & OpenID Connect Login - OAuth2 Client SSO Login module which is compatible with Drupal 7, Drupal 8, Drupal 9, and Drupal 10.

Download  Know more

You can check our module reviews and ratings here.

Pre-requisites:

Setup Video:

 Drupal Oauth AWS Cognito Youtube Video

Steps to configure Drupal as OAuth Client:

  • After installing the module, navigate to the Configuration tab., and click on the miniOrange OAuth Client Configuration.

    Drupal-Select-the-Drupal-OAuth-Client-Configuration-Navigate-to-the-Configuration-tab

  • Provide the following information into the Configure OAuth tab: 
    • Select AWS Cognito as the OpenID Provider from the Select Application drop-down. Also, if you don't see your Application/Provider in the Select Application drop-down, you can select Custom OAuth 2.0 Provider.

      Drupal-OAuth-Client-Configuration-Select-AWS-Cognito-Application

    • Copy the Callback/Redirect URL and keep it handy.
    • Enter the AWS as the Application name in the Custom App Name text-field.

      Drupal OAuth Client callback url and provide custom app name

Configure OpenID SSO Application in AWS Cognito:

  • Sign in to AWS Amazon console.
  • Search for Cognito and then click on Cognito under Services.

    drupal oauth client AWS management Console

  • Click on Create user pool button to create new user pools. (User Pool is a user directory. Users in User Pool can access the app using AWS Cognito credentials.)

    drupal oauth client manage user pools

  • Select the Provider types (keep it default if you are not sure) and the Cognito user pool sign-in options as per requirement.

    drupal oauth client AWS Cognito user pools

  • Select the appropriate options based on the need from the Password policy, Multi-factor authentication, and User account recovery, and click on the Next button.

    drupal oauth client AWS Cognito review default

  • Select the suitable options from the Configure sign-up experience as per requirements and click on the Next button.

    Drupal oauth client AWS add app client

  • Choose the message delivery option. Click on the Next button.

    Drupal oauth client AWS App client name

  • Enter the User Pool name. Under the Initial app client, select the Confidential client radio button. Enter the App client name. Click on the Next button.

    Drupal oauth client AWS App client name

  • Verify the required information, scroll down and click on Create user pool button.
  • Now, search for the user pool you created and click on it.

    drupal oauth client AWS App client setting

  • Now, lets create a user for the app.
  • Click on Create user.

    drupal oauth client AWS App client setting

  • Enter the User Information like email and password and click on Create user button.

    drupal oauth client AWS App client setting

  • Click on App integration.

    drupal oauth client AWS App client setting

  • Under Domain section expand Actions and click on Create Cognito domain.

    drupal oauth client AWS App client setting

  • Enter the domain name and click on Create Cognito domain. Copy the Cognito domain it will be required later for Authorization and Access Token endpoints.

    drupal oauth client AWS App client setting

  • Scroll down, find your app and click on it.

    drupal oauth client AWS App client setting

  • Scroll down to Hosted UI. Click on Edit button.

    AWS-Cognito-OpenID-Signle-Sign-on-App-client-Hosted-UI-click-on-Edit

  • Under Hosted sign-up and sign-in pages, provide the following information:
    • Click the Add Callback URL button under Allowed callback URLs.

      drupal oauth client AWS App client setting

    • Paste the previously copied Callback/Redirect URL into the URL text field.

      If your provider only supports HTTPS Callback/Redirect URL and you have an HTTP site, just save your base site URL in the Sign In Settings tab with HTTPS.

      AWS-Cognito-OpenID-Signle-Sign-on-Edit-Hosted-UI-App-client-Paste-Callback-URL

    • Choose which Identity providers will be accessible to this app client.
    • Select the Authorization code grant from the OAuth 2.0 grant types dropdown.
    • Choose the appropriate OpenID Connect scopes from the dropdown, such as OpenID, Email, or Profile.

      AWS-OpenID-Signle-Sign-On-Edit-Hosted-UI-App-client-Choose-the-required-information

  • Click on Save changes button.

Integrating Drupal with AWS Cognito:

  • Navigate to the AWS Cognito panel.
  • Copy the Client ID from the App client information section.

    AWS App copy client id

  • Navigate to the Drupal site and paste the copied Client ID into the Client Id text field.

    Drupal-OAuth-Client-Configuration-paste-the-copied-client-id

  • Again, go back to the AWS Cognito.
  • Click on the Show client secret toggle button in the App client information section.
  • Then, copy the Client secret.

    AWS-Cognito-copy-the-Client-secret

  • Navigate to the Drupal site and paste the copied Client secret into the Client Secret text field.

    Drupal-OAuth-Client-Configuration-Paste-the-copied-client-secret

  • Replace the initial URL with the Cognito domain in the Authorize Endpoint and Access Token Endpoint text fields. Enable the Login with OAuth checkbox, then click on the Save Configuration button.
  • The Send Client ID and Secret in header or body checkbox is used to send Client ID and Secret inside header or body of the Token End Point Request.

    drupal oauth client replace the Endpoints with the cognito domain url

You can also refer to the AWS Cognito Endpoints and Scope from the table given below:

Authorize Endpoint: https://<cognito-app-domain>/oauth2/authorize
Access Token Endpoint: https://<cognito-app-domain>/oauth2/token
Scope: openid
  • The Send Client ID and Secret in Header or Body checkbox allows you to specify whether the Client ID and Secret should be included in the header or the body of the Token Endpoint Request. If you're unsure which option to select, you can stick with the default settings.

    Drupal-AWS-OAuth-Client-Select-Header-or-Body

Test Configuration of Drupal with AWS Cognito:

  • After successfully saving the configurations, now click on the Test Configuration option to check the Single Sign-On (SSO) connection between Drupal and AWS Cognito.

    Drupal-OAuth-Client-Configuration-Click-on-Test-Configuration

  • On a Test Configuration popup, if you don't have an active session in AWS Cognito on the same browser, you will be asked to sign in to your AWS Cognito account. After successfully logging into AWS Cognito account, you will be provided with a list of attributes that are received from the AWS Cognito.
  • Scroll to bottom and click on Configure Attribute / Role Mapping button.

    Drupal oauth client received attribute from AWS

  • Once you clicked on the Configure Attribute / Role Mapping button, you will be auto-redirected to the Attribute & Role Mapping tab. Then, copy the attribute name that contains the email address and paste it into the Email Attribute text field. Now, click the Save Configuration button.

    drupal oauth client AWS Cognito select email attribute

Mapping the Email Attribute is mandatory for your login to work. 

Congratulations! You have successfully configured AWS Cognito as OpenID Provider and Drupal as OAuth Client.

How to perform the SSO login?

  • Now, open a new browser/private window and go to your Drupal site login page.
  • Click on the Login using AWS 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 client - go to configure oauth and scroll  the page select your url here

Contact our 24*7 support team

Feel free to reach out to our Drupal experts if you need any sort of assistance in setting up OAuth2 Client SSO Login on your Drupal site.

 Get In Touch With Us Join Our Slack Channel

back to top Back to top