https://github.com/microauth/microauth-slack
Slack oauth for micro
https://github.com/microauth/microauth-slack
auth authentication javascript js micro microauth microservice nodejs slack
Last synced: 6 months ago
JSON representation
Slack oauth for micro
- Host: GitHub
- URL: https://github.com/microauth/microauth-slack
- Owner: microauth
- License: mit
- Created: 2017-04-14T13:56:29.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-23T00:07:24.000Z (over 1 year ago)
- Last Synced: 2025-04-15T05:48:28.267Z (7 months ago)
- Topics: auth, authentication, javascript, js, micro, microauth, microservice, nodejs, slack
- Language: JavaScript
- Size: 549 KB
- Stars: 8
- Watchers: 1
- Forks: 3
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-micro - microauth-slack
README
# microauth-slack
> Slack oauth for [micro](https://github.com/zeit/micro/)
[](https://travis-ci.org/microauth/microauth-slack)
[](https://github.com/sindresorhus/xo)
[](https://greenkeeper.io/)
Add [slack](https://slack.com) authentication to your [micro](https://github.com/zeit/micro/) service as easy as a flick of your fingers.
This module is a part of [microauth](https://github.com/microauth/microauth) collection.
## Installation
```sh
npm install --save microauth-slack
# or
yarn add microauth-slack
```
## Usage
app.js
```js
const { send } = require('micro');
const microAuthSlack = require('microauth-slack');
const options = {
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(options);
// Third `auth` argument will provide error or result of authentication
// so it will { err: errorObject} or { result: {
// provider: 'slack',
// accessToken: 'blahblah',
// info: userInfo
// }}
const handler = async (req, res, auth) => {
if (!auth) {
return send(res, 404, 'Not Found');
}
if (auth.err) {
// Error handler
console.error(auth.err);
return send(res, 403, 'Forbidden');
}
// Save something in database here
return `Hello ${auth.result.info.user.name}`;
};
module.exports = slackAuth(handler);
```
Run:
```sh
micro app.js
```
Now visit `http://localhost:3000/auth/slack`
## Author
[Artem Karpovich](https://github.com/artemkarpovich)