# @nickpolyakov/token-watcher

> Update your oauth2 jwt tokens in realtime

Latest version **0.0.1** (published 2019-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nickpolyakov/token-watcher
pnpm add @nickpolyakov/token-watcher
yarn add @nickpolyakov/token-watcher
bun add @nickpolyakov/token-watcher
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2019-11-18 |
| First published | 2019-11-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 20.8 KB |
| Known vulnerabilities | 0 (+26 in 2 direct dependencies) |
| Install scripts | no |
| Author | Nikita Polyakov |
| Maintainers | nickpolyakov |
| Keywords | oauth2, tokens, access token, refresh token, jwt |

## Links

- npm: https://www.npmjs.com/package/@nickpolyakov/token-watcher
- Repository: https://github.com/Enjee3o/tokens-watcher
- Homepage: https://github.com/Enjee3o/tokens-watcher#readme
- Issues: https://github.com/Enjee3o/tokens-watcher/issues
- npm.io page: https://npm.io/package/@nickpolyakov/token-watcher

## Dependencies (3)

- [axios](https://npm.io/package/axios.md) ^0.19.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [js-cookie](https://npm.io/package/js-cookie.md) ^2.2.1

## 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

- 0.0.1 (latest) — 2019-11-18

## README

This is library to update your jwt tokens (oauth2 specification)

## Installation
```
yarn add @nickpolyakov/token-watcher
npm -i --save @nickpolyakov/token-watcher
```

You should use TokenWatcher only on production environments, because:
1. localhost:3000 or 127.0.0.1 - this is NOT domains
2. localhost cookies doesn't sending in HTTP request headers to oauth api - different domains security

## Usage
```javascript
// import the TokenWatcher
import { TokenWatcher } from '@nickpolyakov/token-watcher';
// or AuthCookies
import { AuthCookies } from '@nickpolyakov/token-watcher';

// create new instance of TokenWatcher
const tw = new TokenWatcher();

// run TokenWatcher
tw.run();
```

## Options
```javascript
const defaultOptions = {
    axiosConfig: {
        headers: { 
            "X-API-VERSION": "2" 
        },
        withCredentials: true
    },
    jwtIntervalCheckSeconds: 10,
    endOfLifeTokenInSeconds: 43200,
    shiftForDieTimeInSeconds: 120,
    lockCookieExpireInSeconds: 10,
    lockCookie: {
        name: "lock_cookie",
        value: "this_is_lock_cookie_for_watcher"
    },
    oauth: {
        entryPoint: "https://oauth2.example.com",
        grantType: "refresh_token",
        clientId: "web-client",
        clientSecret: "60cfb46215e4058f39e69c1f4a103e4c",
        tokens: {
            accessToken: "jwt_access_token",
            refreshToken: "jwt_refresh_token"
        },
        methods: {
            tokenRefresh: "/token/refresh"
        }
    }
}

new TokenWatcher(defaultOptions).run();
```

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