Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/microauth/microauth
Collection of authentication modules for ▲zeit's micro.
https://github.com/microauth/microauth
auth authentication javascript js micro microauth microservice nodejs
Last synced: 26 days ago
JSON representation
Collection of authentication modules for ▲zeit's micro.
- Host: GitHub
- URL: https://github.com/microauth/microauth
- Owner: microauth
- Created: 2017-04-12T13:32:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-23T11:51:37.000Z (about 7 years ago)
- Last Synced: 2024-08-03T09:04:57.107Z (4 months ago)
- Topics: auth, authentication, javascript, js, micro, microauth, microservice, nodejs
- Homepage:
- Size: 98.6 KB
- Stars: 72
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list-microservice - microauth
README
# microauth
> Collection of authentication modules for zeit's micro.
## List of modules
- [microauth-twitter](https://github.com/microauth/microauth-twitter)
- [microauth-github](https://github.com/microauth/microauth-github)
- [microauth-facebook](https://github.com/microauth/microauth-facebook)
- [microauth-slack](https://github.com/microauth/microauth-slack)
- [microauth-vkontakte](https://github.com/microauth/microauth-vkontakte)
- [microauth-google](https://github.com/microauth/microauth-google)More providers, examples and documentation soon.
## Usage example
Composing several `microauth` modules:
```js
const { send } = require('micro');
const compose = require('micro-compose');
const microAuthSlack = require('microauth-slack');
const microAuthGithub = require('microauth-github');const githubOptions = {
clientId: 'client_id',
clientSecret: 'client_secret',
callbackUrl: 'http://localhost:3000/auth/github/callback',
path: '/auth/github',
scope: 'user'
};const slackOptions = {
clientId: 'client_id',
clientSecret: 'client_secret',
callbackUrl: 'http://localhost:3000/auth/slack/callback',
path: '/auth/slack',
scope: 'identity.basic,identity.team,identity.avatar'
};const slackAuth = microAuthSlack(slackOptions);
const githubAuth = microAuthGithub(githubOptions);const handler = async (req, res, auth) => {
if (!auth) {
return send(res, 404, 'Not Found');
}if (auth.err) {
console.error(auth.err);
return send(res, 403, 'Forbidden');
}if (auth.result.provider === 'github') {
return `${auth.result.provider} provider. Hello ${auth.result.info.login}`;
} else if (auth.result.provider === 'slack') {
return `${auth.result.provider} provider. Hello ${auth.result.info.user.name}`;
} else {
return 'Unknown provider';
}};
module.exports = compose(
slackAuth,
githubAuth
)(handler);```
Now go to `http://localhost:3000/auth/github` for github authentication or go to `http://localhost:3000/auth/slack` for slack authentication.
## Authors
- [Dima Paloskin](https://github.com/dimapaloskin)
- [Artem Karpovich](https://github.com/artemkarpovich)
- [Cody Brunner](https://github.com/rockchalkwushock)
- [Rui Lima](https://github.com/rapzo)