Skip to main content

Cognito OAuth Integration for Consumer Apps

A simple example of enabling Consumer login to the Open Gateway Consumer Dashboard, using AWS Cognito as the identity provider.

Release Version

Open Gateway: v1.0.12+

Overview​

Amazon Cognito is an identity provider (IdP) hosted by AWS. It manages user pools, the login process, and integrations with other AWS services.

Consumers log in to the Open Gateway Consumer Dashboard with OAuth 2.0, so the dashboard needs OAuth 2.0 client credentials from your IdP.

note

This guide suits customers who already have an AWS Cognito user pool and want the same users to log in to Open Gateway.


Prerequisites​

  • An AWS Cognito user pool to connect to Open Gateway.
  • Users in the pool have these attributes:
    • email
    • name

Setup guide​

Log in to the AWS Console.

Create a Lambda for the pre token generation trigger​

  1. Go to AWS Lambda and select Create function > Author from scratch. On the Basic information screen, enter:

    • Function name: biza-pre-token-generation
    • Runtime: Node.js 20.x (or later)
    • Architecture: x86_64

    Click Create.

Create Function

Create Function

  1. Add the following code and click Deploy. The function is not used until it is deployed.
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, set:

    • 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:
    • Trigger type: authentication
    • Authentication: Pre token generation trigger
    • Trigger event version: Basic features + access token customization - Recommended
    • Lambda function: the Lambda you created above
Lambda Triggers

Lambda Triggers

Create an app integration for the Open Gateway Consumer Dashboard​

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

User Pool

  1. In the App Integration tab, enter:
    • 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: select your preferred identity providers. These must match the identity providers used by the client app that creates agreements in OG.
    • OAuth 2.0 grant types: Authorization code grant
    • OpenID Connect scopes (see OAuth2 Profiles for the required scopes):
      • openid
      • email
      • profile
    • Attribute read and write permissions: keep the defaults.

References​