moleculer-auth
v0.0.3
Published
Moleculer auth client service
Downloads
6
Maintainers
Readme
WIP
Usage:
authentication.service.js
const AuthService = require('moleculer-auth');
module.exports = {
name: "authentication",
mixins: [AuthService],
/**
* Default settings
*/
settings: {
providers: {
google: {
client: {
id: 'oauth2-google-id',
secret: 'oauth2-google-isecret'
},
redirect_uri: 'http://localhost:3000/auth/google/callback'
},
facebook: {
client: {
id: 'facebook-id',
secret: 'facebook-secret'
},
redirect_uri: 'http://localhost:3000/auth/facebook/callback'
},
twitter: {
client: {
id: 'twitter-id',
secret: 'twitter-secret'
},
redirect_uri: 'http://localhost:3000/auth/twitter/callback'
}
}
},
};
Api gateway service:
...
aliases: {
"GET /auth/:provider/login"(route, req, res) {
this.login(route, req, res)
},
"GET /auth/:provider/callback"(route, req, res) {
this.callback(route, req, res)
},
// Login
// "POST /users/login": "users.login"
},
methods: {
login(route, req, res){
this.broker.call('authentication.getAuthorizationURI', {provider: route.$params.provider})
.then(
uri => this.sendRedirect(req, uri)
);
},
callback(route, req, res){
this.broker.call('authentication.login', {provider: route.$params.provider, query: route.query})
.then(id => "store user_id in session")
.catch(error => {
this.logger.error(error);
});
// })
},
...
...