Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

README

        

# microauth
> Collection of authentication modules for zeit's micro.


covr

## 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)