0.0.1 • Published 5 years ago
@nickpolyakov/token-watcher v0.0.1
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
// 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
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();
0.0.1
5 years ago