Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cognito-gateway

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cognito-gateway

A gateway lambda for dealing with cognito apis

  • 0.8.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Cognito Gateway API

cognito-gateway npm cognito-gateway circle

Usage

import cognitoGateway from 'cognito-gateway';

export const {
    signIn,
    signUp,
    signOutGlobal,
    signUpConfirm,
    signUpConfirmResend,
    refreshToken,
    changePassword,
    forgotPasswordRequest,
    forgotPasswordConfirm,
    userGet,
    userDelete
} from cognitoGateway({
    headers: {
        'Access-Control-Allow-Origin': '*'
    },
    preSignIn: (requestBody) => requestBody, // custom pre auth logic
    postSignIn: (responseBody) => responseBody, // custom post auth logic
    // more hooks
});

Config

headers: Object<string, string>

An object containing any headers to be added to the http response.

Hooks

Hooks are called at various points throughout the signup and authentication process. They can be used to add custom authentication or perform additional actions in response to authentication or signup. All hooks are async so you can return a promise. The promise should resolve to an object in the same structure as the request or response body. If the promise is rejected or an error is thrown during the hook execution then cognitoGateway will create a http response from the err.statusCode and err.message properies of the promise rejection payload or thrown error.

The available hooks are:

preSignIn(
    requestBody: {
        username: string,
        password: string
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postSignIn(
    error: ?GromitError,
    responseBody: ?{
        accessToken: string,
        refreshToken: string,
        idToken: string,
        time: number
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preSignUp(
    requestBody: {
        username: string,
        password: string,
        attributes: Object
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postSignUp(
    error: ?GromitError,
    responseBody: ?{
        user: {
            username: string,
            attributes: Object
        }
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preSignOutGlobal(
    requestBody: {},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postSignOutGlobal(
    error: ?GromitError,
    responseBody: ?{status: 'success'},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preSignUpConfirm(
    requestBody: {
        username: string,
        verificationCode: string
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postSignUpConfirm(
    error: ?GromitError,
    responseBody: ?{status: 'success'},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preSignUpConfirmResend(
    requestBody: {
        username: string
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postSignUpConfirmResend(
    error: ?GromitError,
    responseBody: ?{status: 'success'},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preRefreshToken(
    requestBody: {refreshToken: string},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postRefreshToken(
    error: ?GromitError,
    responseBody: ?{
        accessToken: string,
        idToken: string
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preChangePassword(
    requestBody: {
        password: string,
        newPassword: string,
        accessToken: string
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postChangePassword(
    error: ?GromitError,
    responseBody: ?{status: 'success'},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preForgotPasswordRequest(
    requestBody: {
        username: string
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postForgotPasswordRequest(
    error: ?GromitError,
    responseBody: ?{status: 'success'},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preForgotPasswordConfirm(
    requestBody: {
        username: string,
        confirmationCode: string,
        password: string
    },
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postForgotPasswordConfirm(
    error: ?GromitError,
    responseBody: ?{status: 'success'},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preUserGet(
    requestBody: {},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postUserGet(
    error: ?GromitError,
    responseBody: ?{status: 'success'},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

preUserDelete(
    requestBody: {},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<requestBody>

postUserDelete(
    error: ?GromitError,
    responseBody: ?{status: 'success'},
    httpEvent: AWSLambdaEvent,
    lambdaContext: AWSLambdaContext
) => Promise<responseBody>

Auth

/signIn [post]

Request a set of tokens via a username and password

path: /signIn
method: post
requestBody:
    username: string
    password: string
responseBody:
    accessToken: string
    refreshToken: string
    idToken: string
    time: int

/refreshToken [post]

Request a new access and id token via a refresh token

path: /refreshToken
method: post
requestBody:
    refreshToken: string
responseBody:
    accessToken: string
    idToken: string

/signOutGlobal [post]

Sign a user out from all services.

path: /signOutGlobal
method: post
headers:
    Authorization: 'Bearer {accessToken}'
responseBody:
    status: string

/signUp [post]

Request the creation of a new user

path: /signUp
method: post
requestBody:
    username: string
    password: string
    attributes: array
responseBody: 
    user: cognitoUser
    verificationAttribute: string
    verificationMedium: string
    verificationValue: string

/signUpConfirm [post]

Confirm a user via a verification code

path: /signUpConfirm
method: post
requestBody:
    username: string
    verificationCode: string
responseBody:
    status: string

/signUpConfirmResend [post]

Request a new verification code via username

path: /signUpConfirmResend
method: post
requestBody:
    username: string
responseBody:
    verificationAttribute: string
    verificationMedium: string
    verificationValue: string

Users

/user [get]

Request user information via a token

path: /user
method: get
headers:
    Authorization: 'Bearer {accessToken}'
responseBody: CognitoUser

/user [delete]

Delete a user via a token

path: /user
method: delete
headers:
    Authorization: 'Bearer {accessToken}'
responseBody:
    status: string

FAQs

Package last updated on 27 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc