0.4.1 • Published 4 years ago

express-jwt-authorizer v0.4.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

express-jwt-authorizer

npm.io npm.io GitHub license

Express middleware that automatically performs authentication.

you can install it as below

npm install --save express-jwt-authorizer

And you can use it in the same way as the code below.

const express = require("express");
const app = express();
......
const authorizer = require("express-jwt-authorizer");
const key = require("./key/key"); //key value
app.use(
    authorizer({
        needAuthPaths: ["^/*"],
        needAuthPathsExcept: ["^/auth/*"],
        privateKey: key.privateKey,
        expiresIn: "1h", // ms, s, m, h, d, w, y
        logger: console.log,
        additionalAuthorize: (req, res, next) => {
            /* you can check session here */
            return true;
        },
    })
);

The option values ​​are all optional parameters.

  • needAuthPath: URL paths to be authenticated are specified as regular expressions. These routes are not accessible without an authentication token.
  • needAuthPathExcept: This is a regular expression of the path that will not be authenticated. It takes precedence over needAuthPath.
  • privateKey: The key value to encrypt the token.
  • expiresIn: Token expiration time.
  • logger: Logging function to output the error that occurred inside.
  • additionalAuthorize: This function can be used when additional authentication such as session check is required. If authentication is successful, you can return true.

...then

// get login token
const token = req.authorizer.makeToken({user_no:10, user_type:'U'});
// check authorization. true or false
req.authorizer.authorized
// If authorized, the token value will be stored.
req.authorizer.tokenValue
// Authentication is performed by receiving the token value from the authorization of the header.
// It is not necessary to use it directly.
req.authorizer.authorize(req, res, next);
0.4.1

4 years ago

0.4.0

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.1.2

4 years ago

0.2.0

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago