@tribeca/auth-middleware

0.1.5 • Public • Published

auth-middleware

Actions Status CodeFactor codecov Dependabot Status

Express auth middleware for tribeca auth service.

This middleware verifies JWT tokens against the tribeca auth service. It returns 401 Unauthorized Http Response if the token is not set in the http header (Authorization: Bearer TOKEN), expired or invalid, and set in req.user the decoded JWT when valid.

Installation

$ npm install @tribeca/auth-middleware --save

Example

const express = require("express");
const authMiddleware = require("@tribeca/auth-middleware");

const app = express();

app.get("/", authMiddleware(), function handleRequest(req, res) {
    // If token is valid it set decoded jwt in req.user
    res.json(req.user);
});

const port = process.PORT || 3000;
app.listen(port, function() {
    console.log(`Server listening at port ${port}`);
})

License

Licensed under MIT.

Readme

Keywords

Package Sidebar

Install

npm i @tribeca/auth-middleware

Weekly Downloads

1

Version

0.1.5

License

MIT

Unpacked Size

6.68 kB

Total Files

7

Last publish

Collaborators

  • francesco.rivola
  • juanjofp