{"id":17596579,"url":"https://github.com/pauldijou/jwt-client","last_synced_at":"2025-07-25T07:34:18.942Z","repository":{"id":20700908,"uuid":"23984593","full_name":"pauldijou/jwt-client","owner":"pauldijou","description":"Micro service to read, write and save JWT headers","archived":false,"fork":false,"pushed_at":"2017-03-24T14:22:34.000Z","size":19,"stargazers_count":35,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-30T08:07:53.902Z","etag":null,"topics":["javascript","jwt"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pauldijou.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":"2014-09-13T03:16:08.000Z","updated_at":"2022-01-19T14:59:01.000Z","dependencies_parsed_at":"2022-09-09T12:03:11.943Z","dependency_job_id":null,"html_url":"https://github.com/pauldijou/jwt-client","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/pauldijou/jwt-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldijou%2Fjwt-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldijou%2Fjwt-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldijou%2Fjwt-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldijou%2Fjwt-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pauldijou","download_url":"https://codeload.github.com/pauldijou/jwt-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pauldijou%2Fjwt-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266973465,"owners_count":24014701,"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-07-25T02:00:09.625Z","response_time":70,"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":["javascript","jwt"],"created_at":"2024-10-22T08:44:45.048Z","updated_at":"2025-07-25T07:34:18.915Z","avatar_url":"https://github.com/pauldijou.png","language":"JavaScript","readme":"# JWT Client\n\n## Install\n\n~~~ shell\nbower install jwt-client\n~~~\n\n~~~ shell\nnpm install jwt-client\n~~~\n\n## Basic usage\n\n~~~ javascript\nvar jwtHeader = '[here you need to write a way to retrieve such header value from HTTP response]';\nvar jwtValue = JWT.read(jwtHeader);\n\n// Let's test if the token is a valid one\nif (JWT.validate(jwtValue)) {\n  // If so, save it for further use\n  // (by default inside localStorage)\n  JWT.keep(jwtValue);\n  // Alternatively, you could also directly save the token itself\n  JWT.keep(jwtHeader);\n} else {\n  // If not, we might want to remove\n  // the last token. Or not. Depends on you...\n  JWT.forget();\n}\n~~~\n\n~~~ javascript\n// You can access the parsed version of the token anytime\nvar session = JWT.remember();\n\n// And access any useful info inside the claim\nvar userId = session.claim.userId;\n~~~\n\n~~~ javascript\n// Don't forget to set the correct HTTP header when sending a request to your server\nrequest.setHeader('Authorization', JWT.get());\n~~~\n\n## API\n\nValue between brackets (like `[key]`) are optional and `JWT.defaults` will be used when missing. Most of the time, you should leave them empty.\n\n### JWT.read(header)\n\nParse a JWT token string as a JavaScript object. It will decode the Base64 and parse the resulting string as a JSON.\n\n### JWT.write(value)\n\nStringify a JavaScript object representing a JWT token into the actual JWT token string. The JavaScript object need at least a `header` and a `claim` properties.\n\n### JWT.keep(value, [key], [storage])\n\nStore `value` inside the default storage using the specified or default key. If `value` is a JavaScript object, `JWT.write` will be used to convert it to a string.\n\n### JWT.remember()\n\nRetrieve the token from the storage and parse it.\n\n### JWT.forget()\n\nRemove the token form the storage.\n\n### JWT.validate(value, [issuer], [audience])\n\nCheck if `value` is a valid token. It can be either a JWT token string or a JavaScript object representing it. It will check both the `expiration` and `not before` dates but also the `issuer` and the `audience` if provided.\n\n## Configuration\n\nYou can override any configuration parameter to make JWT client work the way you want. Impose your style!\n\n~~~ javascript\nJWT.defaults = {\n  // The key used to store the token\n  key: 'JWT_TOKEN',\n  // This is the official token to use for JWT but feel free to use another one if you want\n  tokenPrefix: 'Bearer ',\n  // Where to store the token, by default localStorage\n  storage: global.localStorage,\n  // In Base64 url-safe mode, padding isn't mandatory, so we will disable it by default\n  // but you can force it by setting this param to true if you want\n  padding: false\n};\n~~~\n\nTo change a value, just do something lile :\n\n~~~ javascript\nJWT.defaults.padding = true;\n~~~\n\n## Examples\n\n~~~ javascript\n// Let's say we have our JWT token\nvar token =\n  'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.' +\n  'eyJzdWIiOjEyMzQ1Njc4OTAsIm5hbWUiOiJKb2huIERvZSIsImFkbWluIjp0cnVlfQ.' +\n  'eoaDVGTClRdfxUZXiPs3f8FmJDkDE_VCQFXqKxpLsts';\n\n// We can parse it\nvar session = JWT.read(token);\n// return a JavaScript object\n// {\n//   header: { alg: \"HS256\", typ: \"JWT\" },\n//   claim: { sub: 1234567890, name: \"John Doe\", admin: true },\n//   signature: 'eoaDVGTClRdfxUZXiPs3f8FmJDkDE_VCQFXqKxpLsts'\n// }\n\n// We can validate it\nJWT.validate(token); // return true\nJWT.validate(session); // also return true\n\n// We can save it in a client-side storage\nJWT.keep(token);\n// Equivalent to\nJWT.keep(session);\n\n// We can retrieve it from the storage\nvar session2 = JWT.remember();\n// Now, we have session == session2\n// Not as a reference of course, but all their properties\n// are the same\n\n// If we need to retrieve the raw token\nvar token2 = JWT.get();\n// token === token2\n\n// If we need to stringify a session to a JWT token\nvar token3 = JWT.write(session2);\n// token === token3\n~~~\n\n## Test\n\n~~~ shell\nnpm install\nnpm test\n~~~\n\n## License\n\nThis software is licensed under the Apache 2 license, quoted below.\n\nCopyright 2015 Paul Dijou (http://pauldijou.fr).\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauldijou%2Fjwt-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpauldijou%2Fjwt-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpauldijou%2Fjwt-client/lists"}