Skip to main content

Cognito OAuth Integration for Consumer Apps

This article describes a simple example of how to enable Consumer login to the Open Gateway Dashboard by integrating with AWS Cognito as an identity provider.

Release Version

Open Gateway: v1.0.12+

Overview

Amazon Cognito is a hosted Identity Provider (IDP) managed by AWS and allows AWS to manage user pools, the log in process and various integrations with AWS services.

Biza's Open Gateway (OG) setup requires OAuth 2.0 credentials to log in to the Consumer Dashboard of Open Gateway.

note

This article is suitable for customers with an existing AWS Cognito setup with users and wish to integrate the same set of users to Open Gateway.


Prerequisites

  • AWS Cognito setup with a user pool connected with Open Gateway
  • Users in your pool should have the following -
    • email
    • name

Setup Guide​

To begin, log into the AWS Console.

Creating a new Lambda for the Pre Claim Trigger​

  1. Go to AWS Lambda
  • Create function > Author from scratch.
  • Enter or select the following information on the Basic information screen.
    • Function name: biza-pre-token-generation
    • Run time: Node.js 20.x (or latest)
    • Architecture: x86_64
  • Click Create
Create Function

Create Function

  1. Add the following code and click Deploy (Please ensure you click Deploy).
export const handler = function(event, context) {
// Retrieve user attribute from event request
const userAttributes = event.request.userAttributes;
// Add scope to event response
event.response = {
"claimsAndScopeOverrideDetails": {
"idTokenGeneration": {
"claimsToAddOrOverride": {
"biza-au:auth:user_id": userAttributes.sub,
"biza-au:auth:principal_id": userAttributes.sub
}
},
"accessTokenGeneration": {}
}
};
// Return to Amazon Cognito
context.done(null, event);
};

Enable the Pre Token Generation Trigger in Cognito​

  1. Select your user pool, go to Advanced Security and click Enable
Advanced Security

Advanced Security

  1. On the Edit advanced security screen, enable the following.
  • Advanced security : ✅ Full-function
  • Compromised credentials : ✅ Cognito defaults
  • Adaptive authentication: ✅ Cognito defaults
  • Click Enable
Edit Advanced Security

Edit Advanced Security

  1. Go to User pool properties
User Pool Properties

User Pool Properties

  1. On the Add Lambda trigger screen, select the following
  • Trigger type: authentication
  • Authentication: Pre token generation trigger
  • Trigger event version: Basic features + access token customization - Recommended
  • Lambda function: Select the Lambda created above
Lambda Triggers

User Pool Properties

Create an App Integration for OG Dashboard​

  1. Go to your User Pool in Cognito.
User Pool - Cognito

User Pool Properties

  1. In the App Integration tab, enter the following information
  • App type: Other
  • App client name: biza-og-dashboard-integration
  • Client secret: ✅ Generate a client secret
  • Allowed callback URLs: https://{{DASHBOARD HOST}}/api/auth/callback/rbac_oauth
  • Advanced security configurations - optional
    • ✅ Enable token revocation
    • ✅ Prevent user existence errors
    • ❌ Accept additional user context data
  • Identity providers:
    • Please select the preferred identity providers. This should match the identity providers specified in the client app which creates arrangements against OG.
  • OAuth 2.0 grant types: Authorization code grant
  • OpenID Connect scopes (see here for the required scopes)
    • openid
    • email
    • profile
  • Attribute read and write permissions
    • keep default

References