Skip to main content

Guidance for Authentication with Digital Wallets on AWS

Overview

This Guidance demonstrates a custom authentication flow with Amazon Cognito. Using a decentralized web application (dApp), you can authenticate with your digital wallet through Amazon Cognito to be granted temporary AWS credentials. These credentials then give you access to AWS services so you can securely proxy API calls to third-party APIs. This Guidance offers two different authorization methods, allowing you to choose the method most convenient for you.

How it works

This architecture diagram enables you to authenticate with your digital wallet and obtain AWS credentials. Those credentials can be used to access AWS services and to make secure API calls to third-party Web3 APIs.

Well-Architected Pillars

The architecture diagram above is an example of a Solution created with Well-Architected best practices in mind. To be fully Well-Architected, you should follow as many Well-Architected best practices as possible.

This Guidance uses the AWS Serverless Application Model (SAM) to define, build, and deploy architecture resources. If Lambda functions and API Gateway encounter failures or errors, you can set up Amazon CloudWatch alarms to address unexpected issues. Review this blog post for more information: How to get notified on specific Lambda function error patterns using CloudWatch.

Read the Operational Excellence whitepaper

This Guidance employs a custom authentication flow where users sign a generated message with their digital wallet (crypto wallet) to answer an Amazon Cognito custom challenge, creating identities in the User Pool. Additionally, this Guidance demonstrates two authorization methods for API Gateway: using Amazon Cognito User Pool identity token or Amazon Cognito Identity Pool and AWS Identity and Access Management (IAM) roles for authenticated and unauthenticated users.

You can securely proxy API calls to third-party Web3 provider APIs, a principle applicable to any third-party API. API Gateway secures access to the backend by providing different authorization mechanisms. Data from third-party Web3 APIs is encrypted in transit as it travels through API Gateway to the client decentralized web dApp.

Read the Security whitepaper

This Guidance uses the highly available managed services, Amazon Cognito and API Gateway. Both services generate CloudWatch metrics that can invoke alarms, and detailed API Gateway logs provide visibility into received HTTP requests. These observability features help you monitor the health of the AWS Region in which you deploy the Guidance to support overall reliability of your workloads.

Read the Reliability whitepaper

The source code available on GitHub and the SAM template provided in the backend folder can serve as a boilerplate for your own project. You can then configure API Gateway to point to the desired backend API or to run your chosen Lambda function.

Read the Performance Efficiency whitepaper

This Guidance uses Amazon Cognito and API Gateway, both serverless services that offer a free tier for getting started. Amazon Cognito charges are based on the number of monthly active users (MAU) in your User Pool, while API Gateway charges are based on the number of API calls received and the volume of data transferred out.

Read the Cost Optimization whitepaper

Wherever possible, this Guidance proxies API requests directly to backend integrations instead of initiating Lambda functions, reducing resource consumption. The Lambda functions involved run only for the required duration. This approach enables a sustainable and cost-effective solution, consuming resources only when necessary.

Read the Sustainability whitepaper

Disclaimer

The sample code; software libraries; command line tools; proofs of concept; templates; or other related technology (including any of the foregoing that are provided by our personnel) is provided to you as AWS Content under the AWS Customer Agreement, or the relevant written agreement between you and AWS (whichever applies). You should not use this AWS Content in your production accounts, or on production or other critical data. You are responsible for testing, securing, and optimizing the AWS Content, such as sample code, as appropriate for production grade use based on your specific quality control practices and standards. Deploying AWS Content may incur AWS charges for creating or using AWS chargeable resources, such as running Amazon EC2 instances or using Amazon S3 storage.