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

awscognito-js

v0.2.5

Published

AwsCognito library to support the AWS authentication

Downloads

52

Readme

AWSCognito-JS

AWSCognito-JS library to simplify the integration of the AWS cognito authentication on javascript projects.

License

MIT License

Features

  • Configure
  • Register User
  • Verify User
  • Resend Verification Code
  • Authenticate User
  • Refresh Session
  • Forgot Password
  • Reset Password
  • Update Password
  • SignOut User
  • Update User Attributes
  • Get User Attributes

Installation

  npm i awscognito-js --save

Usage/Examples

Configure Cognito Library

    const cognito = require("awscognito-js");        
    cognito.configure({
        clientId: "Cognito Client ID",
        userPoolId: "Cognito UserPool ID",
        cookieStorage: "Domain Name"
    });

| Parameter | Description | Required | | :-------- | :------------------------- | :------------------------- | | clientId | ClientId from AWS Cognito | True | | userPoolId | userPoolId from Cognito | True | | cookieStorage | Your Domain | False |

Usage

Register User

    const attributes = { email: "[email protected]", "name": "Test User" }
    const userName="testUser";
    const password="Test1234!3"
    cognito.register(userName, password, attributes).then(async (response)=>{
        console.log(response)
    }).catch(e=>{
        console.log(e)
    });

Output

 { 
    user: { CognitoUser-object }
 }

Verify Account

    const userName="testUser";
    const code="345232"
    cognito.verifyAccount(userName, code).then(async (response)=>{
        console.log(response)
    }).catch(e=>{
        console.log(e)
    });

Resend Code

    const userName="testUser";
    cognito.resendCode(userName).then(async (response)=>{
        console.log(response)
    }).catch(e=>{
        console.log(e)
    });

Authenticate User

    const userName="testUser";
    const password="Test1234!3";
    cognito.authenticate(userName, password).then(async (response)=>{
        console.log(response)
    }).catch(e=>{
        console.log(e)
    });

Output

{
  idToken:  {
    jwtToken: 'eyJraWQiOiJcLzFOamU4SWRXYjVxMjhtM1dmb0RvWUNHNnNaang3OXc2QWI0cm5ZVFZhRT0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhNjM0NDk4My05NDM0LTRhNjgtYmNlYy0zNDJhZGYyMzRlNmUiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC5hcC1zb3V0aGVhc3QtMS5hbWF6b25hd3MuY...',
    payload: { user payload }
  },
  refreshToken:  {
    token: 'eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.rJYiWqo3pQ91UfGez8y4mGiZdJHbaLvTU-hXiwB32aKh3jd3xax6JObsy3AYHobVMBsbtP002k47PWhB...'
  },
  accessToken:  {
    jwtToken: 'eyJraWQiOiJWRzZkUGJvSHlRUzFaR1N3cmtYK2prQmRDbmlrXC9lZnNCN2FTWVFWWFRZZz0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhNjM0NDk4My05NDM0LTRhNjgtYmNlYy0zNDJhZGYyMzRl...',
    payload: { user payload }
  },
  clockDrift: 0
}

Refresh User Session

    const userName="testUser";
    const refreshToken="eyJjdHkiOiJKV1QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ....";
    cognito.refreshSession(userName, refreshToken).then(async (response)=>{
        console.log(response)
    }).catch(e=>{
        console.log(e)
    });

Output

    SUCCCESS

Forgot Password

    const userName="testUser";
    cognito.forgotPassword(userName).then(async (response)=>{
        console.log(response)
    }).catch(e=>{
        console.log(e)
    });

Reset Password

    const userName="testUser";
    const code="632869";
    const password="Test1234!3";
    cognito.resetPassword(userName, code, password).then(async (response)=>{
        console.log(response)
    }).catch(e=>{
        console.log(e)
    });

Update Password

    const oldPassword="Test1234!3";
    const newPassword="Test1234!4";
    cognito.updatePassword(oldPassword, newPassword).then(async (response)=>{
        console.log(response)
    }).catch(e=>{
        console.log(e)
    });

Signout User Session

    cognito.signOut()