@tribeca/auth-middleware

Express auth middleware for tribeca auth service

Usage no npm install needed!

<script type="module">
  import tribecaAuthMiddleware from 'https://cdn.skypack.dev/@tribeca/auth-middleware';
</script>

README

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.