https://github.com/renddslow/pco-tokens
https://github.com/renddslow/pco-tokens
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/renddslow/pco-tokens
- Owner: Renddslow
- License: other
- Created: 2019-03-20T13:30:52.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-20T13:34:47.000Z (about 6 years ago)
- Last Synced: 2025-02-22T08:19:57.121Z (3 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PCO Tokens
[](https://npmjs.org/package/pco-tokens "View this project on npm")
A quick way to tokenize user data from your Planning Center Online database. This is useful for doing email/sms-based authentication where you want Planning Center to be your primary source of truth.
## Install
```
$ yarn add pco-tokens jsonwebtoken
```## Usage
```js
const pcoTokens = require('pco-tokens')({
pcoAppId: '',
pcoSecret: '',
secret: '',
});(async () => {
await pcoTokens.withEmail('[email protected]');
})();
```## API
*A note up top, in order to use this package you will need to have created a Personal Access Token with Planning Center Online, not an application. [Read more.](https://developer.planning.center/docs/#/introduction/authentication)*
### pcoTokens(options)
#### options
Type: `Object`##### pcoAppId
*Required*Type: `string`
Your [Planning Center App ID](https://api.planningcenteronline.com/oauth/applications).
##### pcoSecret
*Required*Type: `string`
Your [Planning Center Secret](https://api.planningcenteronline.com/oauth/applications).
##### secret
*Required*Type: `string`
A super-secret key that your token will be built off of. This should be kept super-secret and stored so that you can verify the tokens later on.
### pcoTokens.withEmail(email)
Get a list of tokens from a user's email address.
*Required*
Type: `string`
A valid email address.
### Token Response
All `with*` methods return an array of objects in the following format:
```
{
type: 'email' | 'phone',
identifier: '',
token: '',
person: {
id: '',
first_name: '',
last_name: '',
avatar: '',
}
}
```For every matching individual, you will receive a token as well as personally identifiable information of that individual. This is useful when you wish to populate an email with a list of people when the email is associated with multiple persons.
## Verifying the Tokens
In order to run `pco-tokens` you will need to have `jsonwebtoken` installed. `jsonwebtoken` makes it easy to verify a token.
```js
const jwt = require('jsonwebtoken');const SECRET = '';
module.exports = (req, res) => {
const { token } = req.query;
if (!token) {
res.writeHead(401);
return res.end();
}
try {
const person = jwt.verify(token, SECRET);
res.setHeader('Content-Type', 'text/html');
return res.end(`Hello, ${person.first_name}!
`);
} catch (e) {
res.writeHead(401);
return res.end();
}
}
```