• Stars
    star
    1,371
  • Rank 34,304 (Top 0.7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A sample authentication service implemented with a server-less architecture, using AWS Lambda to host and execute the code and Amazon DynamoDB as persistent storage. This provides a cost-efficient solution that is scalable and highly available and can be used with Amazon Cognito for Developer Authenticated Identities.

LambdAuth

Join the chat at https://gitter.im/danilop/LambdAuth

Note:

A sample authentication service implemented with a server-less architecture, using AWS Lambda to host and execute the code and Amazon DynamoDB as persistent storage. This provides a cost-efficient solution that is scalable and highly available.

The authentication can be used with Amazon Cognito to assume an Authenticated Role via Developer Authenticated Identities.

The basic functions implemented are:

  • new user creation, an email is sent to validate the email address provided
  • login, getting back an authentication "token" that can be used with Amazon Cognito to assume an Authenticated Role via Developer Authenticated Identities
  • password change
  • password reset, an email is sent with a link to reset the password

Passwords are not saved in clear in the database, but "salted" (via HMAC-SHA1) using a dedicated, random salt for each password.

Amazon SES is used to send all emails.

The login function is calling in the backend GetOpenIdTokenForDeveloperIdentity, a Cognito API to register (or retrieve) the IdentityId and an OpenID Connect token for a user authenticated by your backend authentication process.

A sample implementation can be found at http://lambdauth.danilop.net.

License

Copyright (c) 2015 Danilo Poccia, http://danilop.net

This code is licensed under the The MIT License (MIT). Please see the LICENSE file that accompanies this project for the terms of use.

Installation

A sample installation script using Bash (init.sh) is provided to install and configure all necessary resources in your AWS account:

The init.sh script requires a configured AWS Command Line Interface (CLI) and the jq tool. The script is designed to be non destructive, so you can run it again (e.g. if you delete a role) without affecting the other resources.

Before running the init.sh script, set up your configuration in the config.json file:

  • your AWS account (12-digit number). If an alias happens to be set for your root account, then you will need to go to Support > Support Center of your AWS Console and find your Account Number from the top right corner.
  • name of your CLI profile. This is the CLI profile that you want to represent while running ./init.sh from the command-line. This value is usually found in square brackets inside the ~/.aws/credentials file (%UserProfile%\.aws\credentials file in Windows) after installing the AWS CLI tools for your operating system. For more information, you may refer to the section called Named Profiles in the AWS CLI tools user guide.
  • the AWS region (e.g. "eu-west-1")
  • the Amazon S3 bucket to use for the sample HTML pages
  • the Cache-Control: max-age value, in seconds, to use on Amazon S3 (e.g. if distributed by Amazon CloudFront or another CDN)
  • the cryptographically generated byte size: the length of the various randomly generated hashes / keys / tokens etc can be altered from here centrally. If you choose to use different lengths for the different strings generated by the different lambda functions, you can override this value in those particular lambda scripts individually as desired
  • the Amazon DynamoDB table to create/use
  • the Amazon Cognito identity pool name to create/use (the identity pool id is automatically overwritten if present in the config.json file)
  • the Developer Provider Name to use with Amazon Cognito
  • the external name to be included in emails
  • the email source for emails (must be verified by Amazon SES)
  • the link to the verification page (usually http://bucket.s3.amazonaws.com/verify.html, but can be customized using a bucket name that is a DNS domain, Amazon CloudFront or another CDN)
  • the link to the password reset page (usually http://bucket.s3.amazonaws.com/reset.html, but can be customized using a bucket name that is a DNS domain, Amazon CloudFront or another CDN)
{
  "AWS_ACCOUNT_ID": "123412341234",
  "CLI_PROFILE": "default",
  "REGION": "eu-west-1",
  "BUCKET": "bucket",
  "MAX_AGE": "10",
  "CRYPTO_BYTE_SIZE": 128,
  "DDB_TABLE": "LambdAuthUsers",
  "IDENTITY_POOL_NAME": "LambdAuth",
  "DEVELOPER_PROVIDER_NAME": "login.mycompany.myapp",
  "EXTERNAL_NAME": "My Authentication",
  "EMAIL_SOURCE": "[email protected]",
  "VERIFICATION_PAGE": "http://bucket.s3.amazonaws.com/verify.html",
  "RESET_PAGE": "http://bucket.s3.amazonaws.com/reset.html"
}

At the end of the init.sh script, you can start creating users pointing your browser to:

http://bucket.s3.amazonaws.com/index.html (replacing bucket with your bucket name)

As an optional step, you may want to configure Amazon S3 for Website Hosting and use Amazon CloudFront to distribute the static content.

A sample deployment script using Bash (deploy.sh) is provided to update the AWS Lambda functions and the sample HTML pages on the Amazon S3 bucket.

Usage

Sample HTML pages are provided to showcase how to use this framework with a JavaScript application:

  • signup.html - to create a new user, the email address will be validated sending a custom link to the verify.html page
  • login.html - to login in, assuming an authenitcated role with Cognito
  • verify.html - to validate the email address of a new user
  • changePassword.html - to change password, knowing the old one
  • lostPassword.html - to ask for a passwrod reser, via email
  • reset.html - to reset the password, linked by the email sent for a lost password

The same use cases can be implemented on a Mobile device using the AWS Mobile SDK.

APIs

The APIs are exposed as AWS Lambda Functions:

Function Input Output
LambdAuthCreateUser email, password created: true / false
LambdAuthVerifyUser email, verify verified: true / false
LambdAuthLogin email, password login: true / false, identityId, token
LambdAuthChangePassword email, oldPassword, newPassword changed: true / false
LambdAuthLostPassword email sent: true / false
LambdAuthResetPassword email, lost, password changed: true / false

More Repositories

1

yas3fs

YAS3FS (Yet Another S3-backed File System) is a Filesystem in Userspace (FUSE) interface to Amazon S3. It was inspired by s3fs but rewritten from scratch to implement a distributed cache synchronized by Amazon SNS notifications. A web console is provided to easily monitor the nodes of a cluster.
Python
643
star
2

ServerlessByDesign

A visual approach to serverless development. Think. Build. Repeat.
JavaScript
289
star
3

AWS_Lambda_in_Action

This source code distribution is a companion to the AWS Lambda in Action book available from Manning Publications.
JavaScript
287
star
4

serverless-chat

A serverless web chat built using AWS Lambda, AWS IoT (for WebSockets) and Amazon DynamoDB
JavaScript
106
star
5

multimodal-chat

A multimodal chat interface with many tools.
Python
66
star
6

serverless-positive-chat

An inclusive chat that avoids negative messages and translates the content in the language that you choose, tracking the main topics of a chat room.
JavaScript
53
star
7

SampleBatchProcessing

Sample Implementation of Batch Processing on Amazon Web Services (AWS)
Shell
50
star
8

evolutionary-serverless-architectures-with-safe-deployments

A sample implementation of an evolutionary architecture for a serverless application using safe deployments, automatically computing the fitness function at deployment time, with the possibility to rollback back if fitness is not improving.
JavaScript
40
star
9

serverless-iot-analytics

Serverless processing of sensor data using AWS IoT, Amazon Kinesis and AWS Lambda to display the result graphically on a static web page.
JavaScript
28
star
10

serverless-observability-sample-app

A sample application you can use to test observability for serverless apps
JavaScript
24
star
11

AutoScaling2IFTTT

A sample AWS Lambda function to push EC2 Auto Scaling notifications to IFTTT via the Maker channel
JavaScript
21
star
12

lambda-rust-and-cdk

TypeScript
19
star
13

SNS2IFTTT

A sample AWS Lambda function to push SNS notifications to IFTTT via the Maker channel
JavaScript
19
star
14

runjop

RunJOP (Run Just Once Please) is a distributed execution framework to run a command (i.e. a job) only once in a group of servers.
Python
19
star
15

events-and-workflows

A sample application showing a serverless retail shop using a workflow to create an order.
JavaScript
18
star
16

oss-for-generative-ai

Open Source Frameworks for Building Generative AI Applications
Python
16
star
17

portable-serverless-app

An example of portable serverless app that can run on multiple platforms.
JavaScript
15
star
18

reInvent2022-BOA310

Code used at re:Invent 2022 for session BOA310 "Building observable applications with OpenTelemetry"
Python
14
star
19

lightbulbSwitch

Sample AWS Lambda function to use AWS IoT Device Shadow to switch a connected lightbulb ON or OFF
JavaScript
14
star
20

first-step-functions

Sample AWS Step Functions application to get practice with SAM templates, Lambda functions, SNS topics and SQS queues.
JavaScript
14
star
21

graphql-api-security-with-aws-appsync-and-amplify

13
star
22

yas3fs-console

A web console to easy monitor the nodes of a YAS3FS cluster.
JavaScript
13
star
23

analyzing-data-aws-lambda

Python
11
star
24

CloudWatchAlarm2IFTTT

A sample AWS Lambda function to push Amazon CloudWatch alarms to IFTTT via the Maker channel
JavaScript
9
star
25

time-series-and-data-lakes

Python
8
star
26

danilop-personal-page

A simple script to populate a web page with links, retrieving link info using the Open Graph protocol. I built it for my personal page.
HTML
8
star
27

commit-message-generator

Elevate your Git workflow with intelligent, context-aware commit messages generated by an AI language model.
Python
7
star
28

ec2-watchdog

EC2-WatchDog is a simple (bash) script for Amazon EC2 to monitor another node for HA and take over a Virtual IP (VIP) if the service on the other node fails.
Shell
7
star
29

security-camera

A DIY Security Camera with a Raspberry Pi and AWS
Python
6
star
30

serverless-time

Sample Serverless App for CI/CD using AWS SAM
JavaScript
5
star
31

serverless-functions-and-containers

HTML
5
star
32

store-and-reply

JavaScript
5
star
33

JustAGame

A (very) simple game to showcase the power of HTML5 + WebSockets and the use of Amazon Web Services (AWS) APIs within an application
JavaScript
4
star
34

snsUnsubscribeNonExistingQueues

This is a sample script using the new AWS CLI and jq to check for SNS subscription by SQS queues that are not existing anymore and remove (unsubscribe) them.
Shell
3
star
35

serverless-ml

Sample serverless data pipeline powered by machine learning
JavaScript
3
star
36

generative-ai-team-building

Your not alone to reach your goal!
Python
2
star
37

first-serverless-functions

A few examples of Lambda functions to start with serverless development
JavaScript
2
star
38

CloudConf2023-observability-demo

Code used in my CloudConf 2023 keynote – From complexity to observability using OpenTelemetry
Python
2
star
39

non-deterministic-software-testing

How to test non-deterministic software, including applications using generative AI and Large Language Models (LLMs).
Python
2
star
40

llm-test-mate

A testing framework for LLM-generated content. Makes it easy to validate outputs from large language models using semantic similarity and LLM-based evaluation.
Python
2
star
41

knn-search-algorithm-comparison

KNN Search Algorithm Comparison – This project compares the performance of different K-Nearest Neighbors (KNN) search algorithms across various dataset sizes and dimensions.
Python
2
star