# refresh-token

> Returns a new oauth2 access token when expired.

Latest version **1.0.0** (published 2017-04-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install refresh-token
pnpm add refresh-token
yarn add refresh-token
bun add refresh-token
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-04-24 |
| First published | 2012-12-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | José F. Romaniello |
| Maintainers | jfromaniello |
| Keywords | oauth2, oauth, refresh, token |

## Links

- npm: https://www.npmjs.com/package/refresh-token
- npm.io page: https://npm.io/package/refresh-token

## Dependencies (1)

- [request](https://npm.io/package/request.md) ^2.68.0

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-04-24
- 0.1.1 — 2016-11-03
- 0.1.0 — 2014-10-06
- 0.0.2 — 2013-09-27
- 0.0.1 — 2012-12-26

## README

Helper function to get always an oauth 2 valid token given a refresh token. 

[The mechanism is explained here](http://tools.ietf.org/html/draft-ietf-oauth-v2-10#section-4.2).

If the token has expired, it will fetch a newone, otherwise it will return the current access token. 


## Install  

    npm install refresh-token

## Usage

~~~javascript
var TokenProvider = require('refresh-token');

var tokenProvider = new TokenProvider('http://token-url', {
    refresh_token: 'refresh token', 
    client_id:     'client id', 
    client_secret: 'client secret'
    /* you can pass an access token optionally
    access_token:  'fdlaksd',
    expires_in:    2133
    */
  });

tokenProvider.getToken(function (err, token) {
 //token will be a valid access token.
});
~~~

There is also a GoogleTokenProvider which has the url already set:

~~~javascript
var GoogleTokenProvider = require('refresh-token').GoogleTokenProvider;

var tokenProvider = new GoogleTokenProvider({
    refresh_token: 'refresh token', 
    client_id:     'client id', 
    client_secret: 'client secret'
  });
~~~

## License 

**MIT**

---
_Source: https://npm.io/package/refresh-token · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
