Skip to content

Latest commit

 

History

History
52 lines (35 loc) · 1.58 KB

File metadata and controls

52 lines (35 loc) · 1.58 KB

Node AWS Cognito Secret Hash Generator

This generates the secret hash for AWS Cognito so that you can authenticate against AWS Cognito via the Auth Flow: USER_PASSWORD_AUTH and obtain an Authentication Result back with bearer access, id, and refresh tokens.

This is useful in API tools like Postman, Insomnia, Paw, RapidAPI, curl, etc to authenticate a request as a user.

Requirements

All you need is a modern version of node on your system with npx available.

Running

Run the following in your terminal and the script will prompt you for inputs. The prompting helps prevent storing secrets in the command history.

npx github:uptech/node-aws-cognito-secret-hash-generator

Using

Once you get your secret hash, you can get auth tokens from AWS Cognito like so:

Notes

  • Replace the xxx sections below to your information.
  • The secret has will not change as long as your inputs do not change.

Curl Example to Fetch Tokens

This uses the Auth Flow: User Password Auth to obtain authorization bearer tokens from AWS Cognito.

curl -X "POST" "https://cognito-idp.us-west-2.amazonaws.com/" \
     -H 'X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth' \
     -H 'Content-Type: application/x-amz-json-1.1' \
     -d $'{
  "AuthFlow": "USER_PASSWORD_AUTH",
  "AuthParameters": {
    "USERNAME": "xxx"
    "PASSWORD": "xxx",
    "SECRET_HASH": "xxx",
  },
  "ClientId": "xxx"
}'

Credits

Inspired by: