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

authentication-client

v1.0.0-rc1

Published

A browserified clientside library for authenticating users with [AWS Cognito](https://aws.amazon.com/cognito/). It was designed and tested to be used with [auth0](https://auth0.com/) but other authentication providers should work just fine.

Downloads

8

Readme

AWS Cognito for Web

A browserified clientside library for authenticating users with AWS Cognito. It was designed and tested to be used with auth0 but other authentication providers should work just fine.

When combined with the auth0 lock widget, you can set up an entire secure, serverless backend with nearly no effort on your part.

Getting Started

Prerequisties: AWS account, auth0 account; rudimentary knowledge of both

Config

  1. Ignore SAML auth0 + Cognito. I've never been able to get it to work.
  2. Follow this tutorial for setting up auth0 + cognito: https://auth0.com/docs/scenarios/amazon-cognito
  3. (Optional) Edit the generated Cognito auth identity and add the ability to put objects to an S3 bucket

Setting up aws-cognito-for-web (AuthenticationClient)

Set up a browserfied project. (Details on how to do that are outside scope here.)

npm install auth0-lock aws-cognito-for-web --save

// main.js

var joy = function() { s3.putObject({}, console.log.bind(console)); };

var Auth0Lock = require('auth0-lock');
var AuthenticationClient = require('authentication-client');

var identityPoolId = 'your cognito identity pool id';
// this was (probably) automatically created when you created your identity pool
var authRoleArn = 'your cognito authenticated role arn';

// this is your auth0 account.  it will match what you set up in the auth0 + cognito tutorial mentioned above
var auth0Endpoint = '[your host].auth0.com';

var lock = new Auth0Lock('the auth0 app client id', auth0Endpoint);

// AuthenticationClient.resumeSession is sugar that handles serializing/unserialzing the user
// session and all the required bits to make everything work.
var auth = AuthenticationClient.resumeSession({
  identityPoolId: identityPoolId,
  authRoleArn: authRoleArn,
  providerEndpoint: auth0Endpoint,
});

auth.on('authenticated', function() {
  console.info('yay. your user was successfully authenticated and now has a cognito identity');
  joy();
});

auth.on('deauthenticated', function(err) {
  console.info('user signed out or error occurred', err);
  lock.show({
    sso: true,
  }, function (err, profile, token) {
    if (err) {
      auth.close();
      alert('Error:\n\n' + err.message);
      return;
    }
    auth.session.profile = profile; // stores the user profile in session
    auth.open(token); // sends token to cognito; leads to emit authenticated if successful
  });
});

Setting up env for tests

Some tests have been built to run against a live auth0 and AWS account. If you run tests yourself without doing some configuration you will see failed tests.

Setting up test env

In order to set up your local env to run the tests:

  1. Copy .env-template to .env
  2. Enter all the required info
  3. run npm test

If you entered valid info and your live environment has been properly configured all tests should pass.

.env example

TEST_COGNITO_POOL=us-east-1:c52axxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
TEST_COGNITO_POOL_REGION=us-east-1
TEST_COGNITO_ROLE=arn:aws:iam::170xxxxxxxxx:role/Cognito_pool_for_auth_testsAuth_Role
TEST_AUTH0_DOMAIN=example.auth0.com
TEST_AUTH0_CLIENT=Hnc4yxxxxxxxxxxxxxxxxxxxx
# in your auth0 app, create a user and enter the info here
[email protected]
TEST_AUTH0_PASS=password1234
# the auth0 connection to use for auth (probably just the auth0 users database)
TEST_AUTH0_CONN=for-auth-tests