OIDC SSO Amazon Cognito Testing Steps

From iDempiere en

Create user pool

Amazon Cognito https://console.aws.amazon.com/cognito/home > User pools > Create user pool

Step 1: Select Cognito user pool provider type

IMPORTANT NOTES:

  • if you are planning to use EMail authentication with iDempiere then select EMail as the ONLY attribute for sign in, otherwise you won't be able to create your users based on emails
  • if you are planning to use Name as authentication you can select both User Name + EMail, but make sure that you check "Make user case sensitive", otherwise you won't be able to create GardenAdmin as user (it will end and gardenadmin and the REST integration won't work)

Amazon Cognito Testing Step 1.png

Step 2: Configure password and authentication policy

Amazon Cognito Testing Step 2.png ===

Step 3: Configure sign-up experience

Amazon Cognito Testing Step 3.png

Step 4: Configure email and SMS delivery

Amazon Cognito Testing Step 4.png

Step 5: Integrate app

Step 5.1: Setup integration with app

Amazon Cognito Testing Step 5 1.png

Step 5.2: Setup Cognito domain

Amazon Cognito Testing Step 5 2.png

Step 5.3: Select Confidential client, enter app client name and select Generate a client secret

Amazon Cognito Testing Step 5 3.png

Step 5.4: Enter callback URLs

Amazon Cognito Testing Step 5 4.png

Step 5.5: Add ALLOW_USER_PASSWORD_AUTH to Authentication flows

Amazon Cognito Testing Step 5 5.png

Step 5.6: Add Profile to Open ID Connect scopes

Amazon Cognito Testing Step 5 6.png

User pool configuration

Step 1: Create user

User pool: GardenWorld > Users > Create user

Notes:

  • User name = iDempiere user (AD_User.Name)
  • Email address = iDempiere user (AD_User.EMail)
  • User has to login for the first time using the temporary password to change new password

Amazon Cognito Testing User Pool Step 1.png

Step 2: Create group (Optional)

NOTE this step and the next are optional, not required if you uncheck the "Authorization" flag in the iDempiere "Rest OpenID Connect Service configuration" explaned below.

User pool: GardenWorld > Groups > Create group

Note: Group name = iDempiere role (AD_Role.Name) without space

Amazon Cognito Testing User Pool Step 2.png

Step 3: Add user to group

User pool: GardenWorld > Groups > Group: GardenWorldAdmin > Add user to group

Amazon Cognito Testing User Pool Step 3.png

Step 4: Get region, User pool ID, Client ID, Client secret, Domain and Allowed callback URLs

Step 4.1: Copy region and User pool ID

User pool: GardenWorld > App integration

Get the region from the Token signing key URL. Token signing key URL format - https://cognito-idp.[region].amazonaws.com/[userPoolId]/.well-known/jwks.json.

Copy the User pool ID

Amazon Cognito Testing User Pool Step 4 1.png

Step 4.2: Copy Client ID and Client secret

User pool: GardenWorld > App integration > App client: iDempiere Web Client

Copy the Client ID and Client secret

Amazon Cognito Testing User Pool Step 4 2.png

Step 4.3: Copy Domain

Note: Cognito domain is required for Authorization Code Grant authorization flow

User pool: GardenWorld > App integration > Domain

Copy Domain

Amazon Cognito Testing User Pool Step 4 3.png

Step 4.4: Copy Allowed callback URLs and Hosted UI link address

Note: Allowed callback URL is required for Authorization Code Grant authorization flow

User pool: GardenWorld > App integration > App client: iDempiere Web Client > Hosted UI

Copy Allowed callback URLs

Right-click on the View Hosted UI button to Copy link address

Amazon Cognito Testing User Pool Step 4 4.png

Step 5: Pre Token Generation Lambda trigger (Optional)

User attributes such as email, phone number etc. are included in the ID Token instead of Access Token.

You have to set up a Pre Token Generation Lambda trigger to add custom claims (such as user email, phone number etc.) to the Access Token. Customization of Access Token requires user to turn on the Advanced security features.

Rest OpenID Connect Service configuration

iDempiere Web Client > Tenant: GardenWorld > Rest OpenID Connect Service

Authority URL format - https://cognito-idp.[region].amazonaws.com/[userPoolId]

Audience - User pool: GardenWorld > App integration > App client: iDempiere Web Client > Client ID

Authorization - when checked the integration will verify the roles vs the groups configured on Cognito, when unchecked the roles assignment is completely managed on iDempiere

Amazon Cognito Testing Rest OpenID Connect Service.png

Generate Secret Hash

Note: Secret Hash is required for Resource Owner Password Credentials (ROPC) authorization flow

  • Combine the User name and Client ID into a single string
  • Hash the combined string using the HMAC-SHA256 algorithm and the client secret as the key
  • Base64 encode the resulting hash

For example, to generate the hash using a linux CLI:

USERNAME=<cognito user pool username>
CLIENT_ID=<your client_id>
CLIENT_SECRET=<your client secret>
SECRET_HASH=$(echo -n $USERNAME$CLIENT_ID | openssl sha256 -binary -mac HMAC -macopt key:$CLIENT_SECRET | base64)
echo $SECRET_HASH

Alternatively for testing you can use an online generator like this: https://www.devglan.com/online-tools/hmac-sha256-online

Testing using Postman

  • Import amazon-cognito-oidc-test.postman_collection.json and environment-http---localhost-8080.postman_environment.json to Postman
  • Set variable value
    • cognitoDomain - Get Domain value from User pool configuration > Step 4.3 (for Authorization Code Grant flow only)
    • cognitoRegion - Get region value from User pool configuration > Step 4.1
    • cognitoClientId - Get Client ID value from User pool configuration > Step 4.1
    • cognitoSecret - Get Client secret value from User pool configuration > Step 4.1
    • cognitoRedirectUri - Get Allowed callback URL from User pool configuration > Step 4.4 (for Authorization Code Grant flow only)
    • cognitoUsername - User name of User pool: GardenWorld > Users > User: GardenAdmin (for Resource Owner Password Credentials flow only)
    • cognitoPassword - Password of User pool: GardenWorld > Users > User: GardenAdmin (for Resource Owner Password Credentials flow only)
    • cognitoSecretHash - Get the generated secret hash from Generate Secret Hash (for Resource Owner Password Credentials flow only)

Step 1: Get and Refresh Token

There are two authentication flows used to get token and refresh token: Authorization Code Grant and Resource Owner Password Credentials (ROPC).

For ROPC flow, the access token is not OpenID scope, therefore cannot be used to access the endpoints return from well known configuration URL.

Step 1.1: Authorization Code Grant

Step 1.1.1: Get Code

Get the Hosted UI link address (i.e. Authorization URL) from User pool configuration > Step 4.4

Authorization URL format - [cognitoDomain]/oauth2/authorize?client_id=[cognitoClientId]&response_type=code&scope=email+openid+profile&redirect_uri=[cognitoRedirectUri]

When the user accesses the Authorization URL, they will be prompted to log in. After logging in and granting permissions, Cognito will redirect them to the redirect_uri with an authorization code.

Redirect format - [cognitoRedirectUri]?code=[authorizationCode]

Step 1.1.2: Get Token

Enter the [authorizationCode] from Step 1.1.1: Get Code to the code value

Amazon Cognito Testing Postman Step 1 1 2.png

Step 1.1.3: Refresh Token

Amazon Cognito Testing Postman Step 1 1 3.png

Step 1.2: Resource Owner Password Credentials (ROPC)

Step 1.2.1: Get Token

Amazon Cognito Testing Postman Step 1 2 1.png

Step 1.2.2: Refresh Token

Amazon Cognito Testing Postman Step 1 2 2.png

Step 2: Sample REST requests

Step 2.1: Get tax records where C_TaxCategory_ID=107

Notes:

  • X-ID-IdToken is required if iDempiere is configured to use email to login and email information is not included in the Access Token (for Resource Owner Password Credentials flow only)
  • X-ID-Role is required if user has more than one role access
  • X-ID-Organization is required if user + role has more than one organization access

Amazon Cognito Testing Postman Step 2 1.png

Step 2.2: Get document no and description of the order records

Notes:

  • X-ID-IdToken is required if iDempiere is configured to use email to login and email information is not included in the Access Token (for Resource Owner Password Credentials flow only)
  • X-ID-Role is required if user has more than one role access
  • X-ID-Organization is required if user + role has more than one organization access

Amazon Cognito Testing Postman Step 2 2.png

Cookies help us deliver our services. By using our services, you agree to our use of cookies.