Skip to content

An example app showing how to implement passkeys using the Authsignal React Native SDK with AWS Cognito

Notifications You must be signed in to change notification settings

authsignal/aws-cognito-react-native-example

Repository files navigation

Authsignal React Native + AWS Cognito Passkeys Example

This example is part of a guide demonstrating how to integrate Authsignal with AWS Cognito when using React Native.

It's part of a series of guides showing different options for integrating Authsignal with AWS Cognito.

Prerequisites

You should follow the prerequisite steps described here to setup your Relying Party and your apple-app-site-association and assetlinks.json files.

Installation

yarn install
npx pod-install ios

Configuration

Update this file with the config values for your Authsignal tenant and region-specific URL, along with the values for your AWS Cognito user pool.

The AWS lambdas

Create Auth Challenge lambda

You can find the full lambda code for this example here.

Verify Auth Challenge Response lambda

You can find the full lambda code for this example here.

The app code

Sign up

You can find a full example of the sign up implementation here.

1. Call Amplify SDK signUp method

Pass the email as the username.

await signUp({
  username: email,
  password: Math.random().toString(36).slice(-16) + 'X', // Dummy value - never used
  options: {
    userAttributes: {
      email,
    },
  },
});

2. Call Amplify SDK signIn method

This step invokes the Create Auth Challenge lambda.

const {nextStep} = await signIn({
  username: email,
  options: {
    authFlowType: 'CUSTOM_WITHOUT_SRP',
  },
});

3. Launch Authsignal pre-built UI

Pass the url returned by the Create Auth Challenge lambda.

const url = nextStep.additionalInfo.url;

const token = await launch(url);

4. Call Amplify SDK confirmSignIn method

This step invokes the Verify Auth Challenge Response lambda.

const {isSignedIn} = await confirmSignIn({
  challengeResponse: token,
});

Sign in

You can find a full example of the sign in implementation here.

1. Call Authsignal SDK passkey.signIn method

const {data} = await authsignal.passkey.signIn({
  action: 'cognitoAuth',
});

2. Call Amplify SDK signIn and confirmSignIn methods

Pass the username and token returned by the Authsignal SDK.

await signIn({
  username: data.username,
  options: {
    authFlowType: 'CUSTOM_WITHOUT_SRP',
  },
});

const {isSignedIn} = await confirmSignIn({
  challengeResponse: data.token,
});