Based on this great example https://github.com/sashee/cognito-auth-example
Follow Permit io docs site to see more details about this integration https://docs.permit.io/category/cognito
Create a Cognito user pool and a client.
Set the following environment variables:
USER_POOL_ID
: the user pool idCLIENT_ID
: the Cognito client idPERMIT_TOKEN
: Permit env token Inside the /standalone_be/.env folder (you can see the .env.example file for reference)
Run npm install inside the /standalone_be folder
And then npx nodemon index.mjs
to start the backend (or just node index.mjs
)
Set the following environment variables in the frontend/config.js file:
cognitoLoginUrl- the Cognito login URL should look like
https://[cognito-name].auth.[region].amazoncognito.com
clientId` - the Cognito client id
Run npm install
inside the frontend
folder
And then just start a local server in the frontend
folder (for example python -m SimpleHTTPServer 8000
or npx http-server
)
Open the browser at http://localhost:8000
and you should see the login page
:: Note that you should add the fe url to the backend CORS configuration you should change this line
res.header("Access-Control-Allow-Origin", "http://localhost:8181");
To your frontend url
Requirements: Terraform set up with an AWS account, npm
terraform init
terraform apply
- go to the URL
- sign up with a user (for example
test
/Password1]
, to conform to the password policy) - you'll see the Cognito user id and that you have tokens
- use "Refresh token" to generate a new set of access keys
- you'll see the status of each token
userInfo
: result for the USERINFO endpointapi access_token
: API check for the access tokenapi id_token
: API check for the id token
- use "Revoke token" to send a revocation to the REVOCATION endpoint
terraform destroy
Thanks again to @sashee for the original example and explanation