Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anytv/freedom-accounts-util
Utility helper for OAuth2.0 calls to Freedom! Accounts
https://github.com/anytv/freedom-accounts-util
Last synced: about 1 month ago
JSON representation
Utility helper for OAuth2.0 calls to Freedom! Accounts
- Host: GitHub
- URL: https://github.com/anytv/freedom-accounts-util
- Owner: anyTV
- Created: 2017-12-08T05:53:09.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-05T03:38:11.000Z (over 5 years ago)
- Last Synced: 2024-12-17T01:52:23.959Z (about 1 month ago)
- Language: JavaScript
- Size: 46.9 KB
- Stars: 2
- Watchers: 22
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Freedom! Accounts Util
A utility helper for OAuth2.0 calls to Freedom! Accounts that supports caching.## Installation:
With NPM:
```
npm install freedom-accounts-util --save
```With Yarn:
```
yarn add freedom-accounts-util
```## Setup:
```
const accounts = require('freedom-accounts-util');accounts.configure({
base_url: '',
path: '',
client_id: '',
client_secret: '',
client_expiry: 300,
server_expiry: 300,
disable_caching: false,
retry_count: 3}
);
// or
accounts.configure(config.ACCOUNTS);
```
Notes:
* Client and server expiry are in seconds.
* `disable_caching` disables caching when true (useful for tests).
* `retry_count` refers to the maximum number of retries for cuddle requests to accounts. Default value is 3 but it can be configured by service that uses it.## Usage:
For Express Servers:
```
accounts.verify_scopes([...scopes]); // Express middleware
```
For calls to
```
accounts.generate_token([...scopes]); // Returns promise
accounts.refresh_token('refresh_token'); // Returns promise
```## Caching:
Caching works in the following way:
* Access tokens with the same scopes are cached together (regardless of order)
* Refreshing an access token will look for a cached scopes with that refresh token and update that key to contain the new access token
* The verify_scopes middleware caches the output of tokeninfo with the access token as the key