{"id":23318790,"url":"https://github.com/noderaider/jwt-autorefresh","last_synced_at":"2025-08-22T17:31:29.973Z","repository":{"id":57287707,"uuid":"59813638","full_name":"noderaider/jwt-autorefresh","owner":"noderaider","description":"Extremely lightweight and tested universal refresh token scheduler.","archived":false,"fork":false,"pushed_at":"2016-11-03T03:20:47.000Z","size":209,"stargazers_count":50,"open_issues_count":1,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-08-20T02:55:27.889Z","etag":null,"topics":["jwt","jwt-authentication","jwt-autorefresh","oauth2","openid","refresh-tokens","scheduler","synchronization"],"latest_commit_sha":null,"homepage":"http://jwt-autorefresh.js.org","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noderaider.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-27T07:24:19.000Z","updated_at":"2025-05-15T11:27:27.000Z","dependencies_parsed_at":"2022-09-16T06:10:48.540Z","dependency_job_id":null,"html_url":"https://github.com/noderaider/jwt-autorefresh","commit_stats":null,"previous_names":["cchamberlain/jwt-autorefresh"],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/noderaider/jwt-autorefresh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noderaider%2Fjwt-autorefresh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noderaider%2Fjwt-autorefresh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noderaider%2Fjwt-autorefresh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noderaider%2Fjwt-autorefresh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noderaider","download_url":"https://codeload.github.com/noderaider/jwt-autorefresh/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noderaider%2Fjwt-autorefresh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271673565,"owners_count":24800717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jwt","jwt-authentication","jwt-autorefresh","oauth2","openid","refresh-tokens","scheduler","synchronization"],"created_at":"2024-12-20T17:19:19.294Z","updated_at":"2025-08-22T17:31:28.958Z","avatar_url":"https://github.com/noderaider.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jwt-autorefresh\n\n**Extremely lightweight and tested universal refresh token scheduler. Ensures access tokens are always refreshed in advance of their expiration automatically and integrates with any third party api / persistence architecture.**\n\n[![NPM](https://nodei.co/npm/jwt-autorefresh.png?stars=true\u0026downloads=true)](https://nodei.co/npm/jwt-autorefresh/)\n\n## Install\n\n`npm i -S jwt-autorefresh`\n\n\n## How to use\n\n\n```js\nimport autorefresh from 'jwt-autorefresh'\nimport { onAuthorize, onDeauthorize } from './events'\n\n/** Function that returns a promise which will resolve to a simple jwt access_token (you handle the persistence mechanism) */\nconst refresh = () =\u003e {\n  const init =  { method: 'POST'\n                , headers: { 'Content-Type': `application/x-www-form-urlencoded` }\n                , body: `refresh_token=${localStorage.refresh_token}\u0026grant_type=refresh_token`\n                }\n  return fetch('/oauth/token', init)\n    .then(res =\u003e res.json())\n    .then(({ token_type, access_token, expires_in, refresh_token }) =\u003e {\n      localStorage.access_token = access_token\n      localStorage.refresh_token = refresh_token\n      return access_token\n    })\n}\n\n/** You supply a leadSeconds number or function that generates a number of seconds that the refresh should occur prior to the access token expiring */\nconst leadSeconds = () =\u003e {\n  /** Generate random additional seconds (up to 30 in this case) to append to the lead time to ensure multiple clients dont schedule simultaneous refresh */\n  const jitter = Math.floor(Math.random() * 30)\n\n  /** Schedule autorefresh to occur 60 to 90 seconds prior to token expiration */\n  return 60 + jitter\n}\n\nlet start = autorefresh({ refresh, leadSeconds })\nlet cancel = () =\u003e {}\nonAuthorize(access_token =\u003e {\n  cancel()\n  cancel = start(access_token)\n})\n\nonDeauthorize(() =\u003e cancel())\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoderaider%2Fjwt-autorefresh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoderaider%2Fjwt-autorefresh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoderaider%2Fjwt-autorefresh/lists"}