{"id":27259537,"url":"https://github.com/pnxtech/jwt-simple-auth","last_synced_at":"2025-04-11T04:06:07.734Z","repository":{"id":45475377,"uuid":"89270693","full_name":"pnxtech/jwt-simple-auth","owner":"pnxtech","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-22T19:03:26.000Z","size":70,"stargazers_count":1,"open_issues_count":3,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T04:06:02.704Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/pnxtech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-24T17:55:56.000Z","updated_at":"2021-11-14T23:57:32.000Z","dependencies_parsed_at":"2023-01-30T16:17:02.400Z","dependency_job_id":null,"html_url":"https://github.com/pnxtech/jwt-simple-auth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnxtech%2Fjwt-simple-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnxtech%2Fjwt-simple-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnxtech%2Fjwt-simple-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pnxtech%2Fjwt-simple-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pnxtech","download_url":"https://codeload.github.com/pnxtech/jwt-simple-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339281,"owners_count":21087215,"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","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":[],"created_at":"2025-04-11T04:06:07.234Z","updated_at":"2025-04-11T04:06:07.718Z","avatar_url":"https://github.com/pnxtech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jwt-simple-auth\n\n[![npm version](https://badge.fury.io/js/jwt-simple-auth.svg)](https://badge.fury.io/js/jwt-simple-auth) \u003cspan class=\"badge-npmdownloads\"\u003e\u003ca href=\"https://npmjs.org/package/jwt-simple-auth\" title=\"View this project on NPM\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/jwt-simple-auth.svg\" alt=\"NPM downloads\" /\u003e\u003c/a\u003e\u003c/span\u003e [![npm](https://img.shields.io/npm/l/jwt-simple-auth.svg)]()\n\n[JSON Web Token](https://en.wikipedia.org/wiki/JSON_Web_Token) Authentication.\n\n### Using jwt-simple-auth\n`jwt-simple-auth` is intended for use by servers / services and relies on external RSA digital certificates in order to carry out its operations.\nUse the supplied `keygen.sh` script if you need to create a public/private key pair.\n\nSome services might use a private certificate to create a JSON Web Token, while another service might just use the public certificate to validate the authenticity of a token.\n\njwt-simple-auth works with two types of tokens: an access token and a refresh token. Access tokens are short lived (one hour by default) and will expire upon that time. You may use a refresh token to obtain a fresh new access token. The refresh token will also expire (one week by default) and at that point you'll need to create a new refresh token. In systems where users sign-in requesting a new refresh token requires entering valid credentials.\n\nLoad jwt-simple-auth as you would normally and load the private and public certificates.  You can replace the loadCerts parameters with `null` if you only need to load a private or public certificate.\n\n```javascript\nconst jwtAuth = require('jwt-simple-auth');\njwtAuth.loadCerts('./server.pem', './server.pub');\n```\n\nOverriding default options:\n\nThe jwt-auth init member can be used to override default values. At this time there's only two default values: `accessTokenExpirationInSeconds` which as a default set to 3600 seconds or one hour and `refreshTokenExpirationInSeconds` which defaults to 2419200 or four weeks.\n\nTo set an access token expiration to only 10 seconds and a refresh token expiration to 60 seconds:\n\n```javascript\njwtAuth.init({\n  accessTokenExpirationInSeconds: 10,\n  refreshTokenExpirationInSeconds: 60\n});\n```\n\nTo create a JWT token:\n\n```javascript\nconst payload = {\n  userID: 34,\n  admin: true\n};\njwtAuth.createToken(payload, 'access')\n  .then((token) =\u003e {\n    // token is now ready for use.\n  });\n```\n\nTo verify a JWT token:\n\n```javascript\njwtAuth.verifyToken(token, 'access')\n  .then((response) =\u003e {\n    // if valid, the response is decoded JWT payload, see verify token response below.\n  });\n```\n\nVerify token response\n```javascript\n{\n  \"userID\": 34,\n  \"admin\": true,\n  \"iss\": \"urn:auth\",\n  \"jti\": \"2fd6th6tqfz101\",\n  \"exp\": 1466614755,\n  \"iat\": 1466614754\n}\n```\n\nTo refresh a valid token:\n\n```javascript\njwtAuth.refreshToken(token)\n  .then((newToken) =\u003e {\n    // if original token was valid then a newToken is returned.\n  });\n```\n\nTo retrieve a hash of an existing token:\n\n```javascript\nlet hash = jwtAuth.getTokenHash(token);\n```\n\nThis is useful when implementing a token management scheme.\n\n### Creating private and public certificates\nYou can use the supplied `keygen.sh` script to create certificates for use with jwt-auth.\n\n```shell\n$ ./keygen.sh\n```\n\n### Tests\nThis project includes mocha/chai tests.  Make sure you have mocha installed globally.\n\n```shell\n$ npm install mocha -g\n```\n\nThen run:\n\n```shell\n$ npm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnxtech%2Fjwt-simple-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpnxtech%2Fjwt-simple-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpnxtech%2Fjwt-simple-auth/lists"}