Skip to content

CLI tool written in node to generate a secret hash for use with AWS Cognito Authentication

Notifications You must be signed in to change notification settings

uptech/node-aws-cognito-secret-hash-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

About

CLI tool written in node to generate a secret hash for use with AWS Cognito Authentication

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published