How to use cognito-express - 1 common examples

To help you get started, we’ve selected a few cognito-express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TreeHacks / root / backend / router / authenticatedRoute.ts View on Github external
import CognitoExpress from "cognito-express";
import express from "express";
import {get} from "lodash";
import {ALLOWED_GROUPS} from "../constants";

//Initializing CognitoExpress constructor
const cognitoExpress = new CognitoExpress({
  region: "us-east-1",
  cognitoUserPoolId: process.env.COGNITO_USER_POOL_ID,
  tokenUse: "id", //Possible Values: access | id
  tokenExpiration: 3600000 //Up to default expiration of 1 hour (3600000 ms)
});

export const authenticatedRoute = express.Router();
authenticatedRoute.use(function (req, res, next) {
  let accessTokenFromClient = req.headers.authorization;
  if (!accessTokenFromClient) return res.status(401).send("Access Token missing from header");

  cognitoExpress.validate(accessTokenFromClient, function (err, response) {
    if (err) return res.status(401).send(err);
    res.locals.user = response;
    next();
  });

cognito-express

cognito-express authenticates API requests on a Node-Express application by verifying the signature of AccessToken or IDToken generated by Amazon Cognito.

MIT
Latest version published 11 months ago

Package Health Score

61 / 100
Full package analysis

Popular cognito-express functions