Giter VIP home page Giter VIP logo

react-webauthn-cognito-poc's Introduction

react-webauthn-cognito-poc

This project is an example of how to set up biometric login for web-based apps (WebAuthn) using Amazon Cognito as the identity provider. This project accomplishes this by leaning on AWS Cognito custom authentication challenges and the SimpleWebAuthn library.

For more information on how this works, here are some references:

This project takes inspiration from the following projects:

The project uses the following libraries for handling the biometric login flow:

The during the authentication process on the frontend, the SimpleWebAuthn library requires some methods that are present on the Node.js Buffer sub class. These methods are not availble in the browser natively, and must be added via the buffer js library. This is being imported and initialized in the index.html file in the /frontend directory.

Running the project

To run the project, make sure that you have an AWS account and have configured the serverless cli

Create an AWS account if you don't already have one, and set up credentials to be used with Serverless https://www.serverless.com/framework/docs/providers/aws/guide/credentials/

Install the serverless cli: npm install -g serverless

Deploying the backend to AWS

1. Install and Initial Deploy

Create a .env file in the /serverless directory and paste in this content:

RELYING_PARTY_ORIGIN=http://localhost:5173
RELYING_PARTY_ID=localhost

These values should be set to the URL of the relying party site, since we're running the relying party locally (frontend project), these values above should be fine.

From the /serverless directory, run the following commands:

npm install

sls deploy

2. Enable IAM role for VerifyAuthChallengeResponse Lambda Function

In the serverless.yml file, uncomment the section under the verifyAuthChallengeResponse function. Looks like this:


verifyAuthChallengeResponse:
handler: ./functions/verify-auth-challenge-response.handler
# Leave the following section commented out on the first deployment.
# Enable this section once you can add the created user pool resource arn
# iamRoleStatementsName: verifyAuthChallengeRes-cognito-idp_AdminUpdateUserAttributes
# iamRoleStatements:
# - Effect: Allow # Action: cognito-idp:AdminUpdateUserAttributes
# # Paste User Pool Resource ARN here
# Resource: your-resource-arn

Find the Cognito User Pool on AWS and copy the user pool's ARN. Paste it in the serverless.yml file for the correct iamRoleStatement.

locate: 'Paste User Pool Resource ARN here'

3. Configure the frontend

Create a .env.local file in the /frontend directory and paste in this content:

VITE_AUTH_REGION=us-east-2
VITE_AUTH_USER_POOL_ID=us-east-2_user-pool-id
VITE_AUTH_USER_POOL_WEB_CLIENT_ID=user-pool-web-client-id
VITE_AUTH_COOKIE_STORAGE_DOMAIN=localhost

Replace the values with your own. I've left in some fake ones as an example.

Add the AWS Region,User Pool ID, and User Pool Web Client ID to the created .env file in the /frontend directory

4. Run the frontend

From the /frontend directory, run the following commands:

npm install

npm run dev

You did it! No more passwords!

Cleanup

1. Removing backend

run sls remove

If it fails to remove the stack, you might need to manually delete the S3 deployment bucket

2. Delete created passkeys from browser

Passkeys located here in Chrome: chrome://settings/passkeys

react-webauthn-cognito-poc's People

Contributors

palmierie avatar andrewg-provisions avatar

Stargazers

Eric Palmieri avatar

Watchers

Eric Hendrickson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.