0.5.11 • Published 8 months ago

cognito-serverless v0.5.11

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

cognito-serverless

šŸ”‘ AWS Cognito Hosted UI OAuth on Serverless

Installation

npm i cognito-serverless

Usage

Add code in your middleware or route to authenticate user.

import { Auth } from 'cognito-server'

const cognito = new Auth(
  {
    COGNITO_DOMAIN: 'auth.example.com',
    COGNITO_CLIENT_ID: 'client-id',
    COGNITO_CLIENT_SECRET: 'client-secret',
    // State is a random string to prevent CSRF attacks (optional)
    COGNITO_STATE: 'random-string'
  },
  /*
   * The scopes of the access request.
   * @optional
   * @default ['openid', 'profile', 'email']
   */
  scopes: ['openid', 'profile', 'email']

  /*
   * After successful authentication, the user will be redirected to this URL.
   * @optional
   * @default url.origin
   */
  redirect_uri: 'https://example.com/callback'
)

/* UserInfo | URL */
const result = await cognito.auth({
  url: new URL('https://example.com'),
  cookies: {
    get: (key) => {
      /** get cookie */
    }
    set: (key, value, options) => {
      /** set cookie */
    }
  },
  // Override class config (optional)
  redirect_uri: 'https://example.com/callback'
})

if (typeof result === 'string') {
  /* Please redirect to `result` (Cognito Hosted UI) */
}

else {
  /* User is authenticated */
}

License

MIT

0.5.11

8 months ago

0.5.10

9 months ago

0.5.9

9 months ago

0.5.8

11 months ago

0.5.7

12 months ago

0.5.6

1 year ago

0.5.5

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.4

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago

0.0.0

1 year ago