@getcolo/colo
v1.0.6
Published
The purpose of this library is to provide a easy-to-use, universal OAuth abstraction to 3rd party identity providers. With Colo, you will be able to abstract away messy OAuth protocol logic when implementing integrations with 3rd party systems. The main
Downloads
4
Readme
Colo.js
The purpose of this library is to provide a easy-to-use, universal OAuth abstraction to 3rd party identity providers. With Colo, you will be able to abstract away messy OAuth protocol logic when implementing integrations with 3rd party systems. The main use case right now is linking an existing user's account to a 3rd-party provider with the motivation of being able to authorized requests.
Installation
yarn add @colo
Quickstart
In your API, create a route for generating the state value, which we will use to relate the user back to.
import { generateStateValue } from '@colo/middleware';
function genStateValueRouteHandler(req, res) {
stateValue = generateStateValue(req.body.user_id);
res.send(200)
}
In your React app, where you will ask the end-user to link their account with a 3rd party provider, include this:
import ColoLink from '@colo/ColoLink';
<ColoLink
integration={'your 3rd party provider e.g. slack'}
genStateUrl={'https://your-state-url.com/generate-state'}
redirectUrl={'https://your-callback-url.com/callback'}
userId={'[email protected]'}
/>
In your callback url method (server-side), include this:
import { getAccessToken } from '@colo/middleware';
// ...
function callbackUrl(req, res) {
const access_token = getAccessToken(req, 'integration')
// store access token in your db (encrypted appropriately of course, please)
}
Supported Providers
Currently, Colo supports the following provider strategies:
- Slack
In Development
- Jira
- GitHub
- Salesforce
ColoLink
ColoLink is the React button component that directs the end-user to the appropriate authorization URL. It has the following parameters:
integration
- the provider you're connecting with i.e. 'slack'redirectUrl
- the callback url the end-user goes to after authorizing your app access. This endpoint will also be responsible for getting the user access tokengenerateStateValueUrl
- the url that generates and stores a unique state value for the end-useruserId
- a unique id for the end-user (can be their email; doesn't have to be the pk in the database)