npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cognito-at-bleeding-edge

v0.0.8

Published

Cognito Backed, Lambda@Edge Enforced Authentication for your CloudFront Distribution

Downloads

16

Readme

cognito-at-bleeding-ege

Install

npm install cognito-at-bleeding-edge

Quickstart

import { DefaultAuthenticator } from 'cognito-at-bleeding-edge';

const authenticator = new DefaultAuthenticator({
    cognitoConfiguration: {
        userPoolId: "us-east-1_abcdef123",
        userPoolDomain: "some-cognito-pool-domain.auth.us-east-1.amazoncognito.com",
        userPoolAppId: "123456789abcdefghijklmnopq",
        userPoolAppSecret: undefined,
    },
});

export const authenticationHandler = ({ event }: { event: CloudFrontRequestEvent }) => {
    return authenticator.handle(event);
};

export const lambdaOriginS3 = async (event: CloudFrontRequestEvent): Promise<CloudFrontRequestResult> => {
    const response = await authenticationHandler({ event });

    // NOTE: Intercept Response & Chain Handler(s)
    //  e.g., Perform Path Rewrite for `/` => `/index.html` Behavior...
    //  e.g., `if (response.isAuthenticated) { ... }`

    return response.actual;
};

Why cognito-at-bleeding-edge

Well, the default library is cognito-at-edge, and it kind-of sucks. As a library, it spits in the face of several decades of good practice. Single-Responsiblitity and Composability of the inner-workings of the library? No, it's a God-class with a ball-of-yarn approach to software.

Our library offers distinct advantages over the cognito-at-edge library:

  • Composability and Single-Responsiblity as First-Order Philosophies.

Not liking our logging implementation, cookie naming scheme, or want to customize the business logic of the overall application? One can easily override a single in interface and plug it in. No need to fork the entire library to change basic functionality of this library.

  • Composable Return Value(s)

We don't just return an opaque CloudFrontRequestResult, we return an enriched object on top of the business-logic ridden response object. We enable one to compose our authentication library with any other library capable of handling off-the-shelf Amazon class structures.

For instance, if you wanted to add some default path handling functionality a la the DocumentRoot behavior of Apache HTTPD fame:

const response = authenticator.handle(request);

if (response.isAuthenticated) {
    // Alter `response.actual` here!

    return response.actual;
} else {
    return response.actual;
}

Why not cognito-at-bleeding-edge

We don't currently the following features implemented in cognito-at-edge:

  • CSRF Token

We feel this is out of scope of the project, feel free to use an off-the-shelf solution or publish one and compose it with our library.

  • Logout URL

We will implement this feature shortly, we just had the good fortune of starting our rewrite before this feature was accepted into cognito-at-edge.

  • Custom URL(s) for Endpoint(s)

We will implement this feature shortly, we just had the good fortune of starting our rewrite before this feature was accepted into cognito-at-edge.

Develop & Deploy

Quickstart

(
VERSION="0.0.28"
rm -rf .serverless/*.zip
npx sls package
aws s3 cp \
    "./.serverless/lambda_origin_s3.zip" \
    "s3://gnelson-test-cognito-at-bleeding-edge-lambda/lambda_origin_s3-${VERSION}.zip"
)
(
VERSION="0.0.28"
# `lambda_version = "0.0.0"` => `lambda_version = "$VERSION"`
sed -i "/lambda_version = \".*\"/c lambda_version = \"${VERSION}\"" \
    "./vars/development.tfvars"

terraform apply --var-file=./vars/development.tfvars
)

Initialization

terraform apply -target "aws_s3_bucket.cloudfront_origin_bucket"
terraform apply -target "aws_s3_bucket_public_access_block.cloudfront_origin_bucket"
terraform apply -target "aws_s3_bucket_acl.cloudfront_origin_bucket"

terraform apply -target "aws_s3_bucket.cloudfront_origin_bucket"