npm

Need private packages and team management tools?Check out npm Orgs. »

qwebs-auth-jwt

0.2.21 • Public • Published

qwebs-auth-jwt

Authentication service using JSON Web Token for Qwebs server.

Features

Add the jwt secret key in config.json

{
  "jwt": {
    "secret": "secretCode"
  },
}

Declare and inject $auth

const Qwebs = require("qwebs");
const qwebs = new Qwebs();
 
qwebs.inject("$auth", "qwebs-auth-jwt");

Use $auth to connect user

class MyService {
  constructor($auth) {
    this.$auth = $auth;
  };
 
  connect(request, response) {
    let payload = { 
      login: request.body.login 
    };
    return this.$auth.encode(payload).then(token => {
      return response.send({ request: request, content: { token: token } });
    });
  };
};
 
exports = module.exports = MyService; //Return a class. Qwebs will create it;

Use $auth to authenticate user

class MyService {
  constructor($auth) {
    this.$auth = $auth;
  };
 
  isConnected(request, response) {
    return self.$auth.identify(request, response).then(() => {
        let login = request.payload.login;
        if (login != "myLogin") throw new DataError({ statusCode: 401 });
        return response.send({ request: request, content: { status: "connected" } });
    });
  };
};
 
exports = module.exports = MyService; //Return a class. Qwebs will vreate it;

API

  • encode(payload)
  • identify(request, response)
  • decode(token)

Installation

$ npm install qwebs-auth-jwt

install

npm i qwebs-auth-jwt

Downloadsweekly downloads

2

version

0.2.21

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability