Giter VIP home page Giter VIP logo

cognito-serverless's Introduction

cognito-serverless

npm-version npm-license npm-download-month npm-min-size local.yml remote.yml

๐Ÿ”‘ 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

cognito-serverless's People

Contributors

wraith-ci[bot] avatar renovate[bot] avatar jill64 avatar

Watchers

 avatar

cognito-serverless's Issues

Sanctuary

Detected Project Issues

Performance

  • No specific performance issues identified from the provided files.

Reliability

  • Use of hardcoded values in cognito.ts and Auth.ts could lead to reliability issues if environment variables are not set properly.
  • Dependency on external services (AWS Cognito, Sentry) without fallback mechanisms could affect reliability.

Maintenance

  • Complex setup in Auth.ts for handling authentication might be hard to maintain without thorough documentation.
  • Multiple configurations across different files (vite.config.ts, playwright.config.ts, svelte.config.js) could make maintenance challenging.

Security

  • Potential security risk by not validating or sanitizing the state parameter in Auth.ts before using it.
  • Use of Buffer.from in Auth.ts without explicit character encoding could lead to vulnerabilities.
  • Storing tokens in cookies without SameSite=Strict in Auth.ts could make the application susceptible to CSRF attacks.

Documentation

  • Lack of inline comments in critical files like Auth.ts, cognito.ts, and workflow files (local.yml, remote.yml) could hinder understanding of the codebase.
  • The README does not provide information on environment setup, which is crucial for initial project setup.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/local.yml
  • actions/checkout v4@a5ac7e51b41094c92402da3b24376905380afc29
  • actions/setup-node v4@60edb5dd545a775178f52524783378180af0d1f8
  • pnpm/action-setup v2
  • actions/upload-artifact v4@65462800fd760344b1a7b4382951275a0abb4808
.github/workflows/remote.yml
  • actions/checkout v4@a5ac7e51b41094c92402da3b24376905380afc29
  • actions/setup-node v4@60edb5dd545a775178f52524783378180af0d1f8
  • pnpm/action-setup v2
  • actions/upload-artifact v4@65462800fd760344b1a7b4382951275a0abb4808
npm
package.json
  • @types/cookie 0.6.0
  • buffer 6.0.3
  • dayjs 1.11.11
  • typescanner 0.5.3
  • @jill64/eslint-config-svelte 1.2.27
  • @jill64/playwright-config 2.3.0
  • @jill64/prettier-config 1.0.0
  • @jill64/sentry-sveltekit-cloudflare 1.7.13
  • @playwright/test 1.44.1
  • @sveltejs/adapter-cloudflare 4.4.0
  • @sveltejs/kit 2.5.10
  • @sveltejs/vite-plugin-svelte 3.1.0
  • @types/node 20.12.12
  • dotenv 16.4.5
  • svelte 4.2.17
  • typescript 5.4.5
  • vite 5.2.11
  • svelte ^4.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.