qwebs-auth-jwt
v0.2.21
Published
Authentication service using JSON Web Token for Qwebs server
Downloads
98
Maintainers
Readme
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