[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-3235":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":15,"forks30d":15,"starsTrendScore":19,"compositeScore":20,"rankGlobal":9,"rankLanguage":9,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":9,"pushedAt":9,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":15,"starSnapshotCount":15,"syncStatus":16,"lastSyncTime":29,"discoverSource":30},3235,"node-jsonwebtoken","auth0\u002Fnode-jsonwebtoken","auth0","JsonWebToken implementation for node.js http:\u002F\u002Fself-issued.info\u002Fdocs\u002Fdraft-ietf-oauth-json-web-token.html",null,"JavaScript",18172,1276,246,136,0,2,5,16,6,44.32,"MIT License",false,"master",true,[],"2026-06-12 02:00:47","# jsonwebtoken\n\n| **Build**                                                                                                                               | **Dependency**                                                                                                         |\n|-----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|\n| [![Build Status](https:\u002F\u002Fsecure.travis-ci.org\u002Fauth0\u002Fnode-jsonwebtoken.svg?branch=master)](http:\u002F\u002Ftravis-ci.org\u002Fauth0\u002Fnode-jsonwebtoken) | [![Dependency Status](https:\u002F\u002Fdavid-dm.org\u002Fauth0\u002Fnode-jsonwebtoken.svg)](https:\u002F\u002Fdavid-dm.org\u002Fauth0\u002Fnode-jsonwebtoken) |\n\n\nAn implementation of [JSON Web Tokens](https:\u002F\u002Ftools.ietf.org\u002Fhtml\u002Frfc7519).\n\nThis was developed against `draft-ietf-oauth-json-web-token-08`. It makes use of [node-jws](https:\u002F\u002Fgithub.com\u002Fbrianloveswords\u002Fnode-jws)\n\n# Install\n\n```bash\n$ npm install jsonwebtoken\n```\n\n# Migration notes\n\n* [From v8 to v9](https:\u002F\u002Fgithub.com\u002Fauth0\u002Fnode-jsonwebtoken\u002Fwiki\u002FMigration-Notes:-v8-to-v9)\n* [From v7 to v8](https:\u002F\u002Fgithub.com\u002Fauth0\u002Fnode-jsonwebtoken\u002Fwiki\u002FMigration-Notes:-v7-to-v8)\n\n# Usage\n\n### jwt.sign(payload, secretOrPrivateKey, [options, callback])\n\n(Asynchronous) If a callback is supplied, the callback is called with the `err` or the JWT.\n\n(Synchronous) Returns the JsonWebToken as string\n\n`payload` could be an object literal, buffer or string representing valid JSON. \n> **Please _note_ that** `exp` or any other claim is only set if the payload is an object literal. Buffer or string payloads are not checked for JSON validity.\n\n> If `payload` is not a buffer or a string, it will be coerced into a string using `JSON.stringify`.\n\n`secretOrPrivateKey` is a string (utf-8 encoded), buffer, object, or KeyObject containing either the secret for HMAC algorithms or the PEM\nencoded private key for RSA and ECDSA. In case of a private key with passphrase an object `{ key, passphrase }` can be used (based on [crypto documentation](https:\u002F\u002Fnodejs.org\u002Fapi\u002Fcrypto.html#crypto_sign_sign_private_key_output_format)), in this case be sure you pass the `algorithm` option.\nWhen signing with RSA algorithms the minimum modulus length is 2048 except when the allowInsecureKeySizes option is set to true. Private keys below this size will be rejected with an error.\n\n`options`:\n\n* `algorithm` (default: `HS256`)\n* `expiresIn`: expressed in seconds or a string describing a time span [vercel\u002Fms](https:\u002F\u002Fgithub.com\u002Fvercel\u002Fms). \n  > Eg: `60`, `\"2 days\"`, `\"10h\"`, `\"7d\"`. A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default (`\"120\"` is equal to `\"120ms\"`).\n* `notBefore`: expressed in seconds or a string describing a time span [vercel\u002Fms](https:\u002F\u002Fgithub.com\u002Fvercel\u002Fms). \n  > Eg: `60`, `\"2 days\"`, `\"10h\"`, `\"7d\"`. A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default (`\"120\"` is equal to `\"120ms\"`).\n* `audience`\n* `issuer`\n* `jwtid`\n* `subject`\n* `noTimestamp`\n* `header`\n* `keyid`\n* `mutatePayload`: if true, the sign function will modify the payload object directly. This is useful if you need a raw reference to the payload after claims have been applied to it but before it has been encoded into a token.\n* `allowInsecureKeySizes`: if true allows private keys with a modulus below 2048 to be used for RSA\n* `allowInvalidAsymmetricKeyTypes`: if true, allows asymmetric keys which do not match the specified algorithm. This option is intended only for backwards compatability and should be avoided.\n\n\n\n> There are no default values for `expiresIn`, `notBefore`, `audience`, `subject`, `issuer`.  These claims can also be provided in the payload directly with `exp`, `nbf`, `aud`, `sub` and `iss` respectively, but you **_can't_** include in both places.\n\nRemember that `exp`, `nbf` and `iat` are **NumericDate**, see related [Token Expiration (exp claim)](#token-expiration-exp-claim)\n\n\nThe header can be customized via the `options.header` object.\n\nGenerated jwts will include an `iat` (issued at) claim by default unless `noTimestamp` is specified. If `iat` is inserted in the payload, it will be used instead of the real timestamp for calculating other things like `exp` given a timespan in `options.expiresIn`.\n\nSynchronous Sign with default (HMAC SHA256)\n\n```js\nvar jwt = require('jsonwebtoken');\nvar token = jwt.sign({ foo: 'bar' }, 'shhhhh');\n```\n\nSynchronous Sign with RSA SHA256\n```js\n\u002F\u002F sign with RSA SHA256\nvar privateKey = fs.readFileSync('private.key');\nvar token = jwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' });\n```\n\nSign asynchronously\n```js\njwt.sign({ foo: 'bar' }, privateKey, { algorithm: 'RS256' }, function(err, token) {\n  console.log(token);\n});\n```\n\nBackdate a jwt 30 seconds\n```js\nvar older_token = jwt.sign({ foo: 'bar', iat: Math.floor(Date.now() \u002F 1000) - 30 }, 'shhhhh');\n```\n\n#### Token Expiration (exp claim)\n\nThe standard for JWT defines an `exp` claim for expiration. The expiration is represented as a **NumericDate**:\n\n> A JSON numeric value representing the number of seconds from 1970-01-01T00:00:00Z UTC until the specified UTC date\u002Ftime, ignoring leap seconds.  This is equivalent to the IEEE Std 1003.1, 2013 Edition [POSIX.1] definition \"Seconds Since the Epoch\", in which each day is accounted for by exactly 86400 seconds, other than that non-integer values can be represented.  See RFC 3339 [RFC3339] for details regarding date\u002Ftimes in general and UTC in particular.\n\nThis means that the `exp` field should contain the number of seconds since the epoch.\n\nSigning a token with 1 hour of expiration:\n\n```javascript\njwt.sign({\n  exp: Math.floor(Date.now() \u002F 1000) + (60 * 60),\n  data: 'foobar'\n}, 'secret');\n```\n\nAnother way to generate a token like this with this library is:\n\n```javascript\njwt.sign({\n  data: 'foobar'\n}, 'secret', { expiresIn: 60 * 60 });\n\n\u002F\u002For even better:\n\njwt.sign({\n  data: 'foobar'\n}, 'secret', { expiresIn: '1h' });\n```\n\n### jwt.verify(token, secretOrPublicKey, [options, callback])\n\n(Asynchronous) If a callback is supplied, function acts asynchronously. The callback is called with the decoded payload if the signature is valid and optional expiration, audience, or issuer are valid. If not, it will be called with the error.\n\n(Synchronous) If a callback is not supplied, function acts synchronously. Returns the payload decoded if the signature is valid and optional expiration, audience, or issuer are valid. If not, it will throw the error.\n\n> __Warning:__ When the token comes from an untrusted source (e.g. user input or external requests), the returned decoded payload should be treated like any other user input; please make sure to sanitize and only work with properties that are expected\n\n`token` is the JsonWebToken string\n\n`secretOrPublicKey` is a string (utf-8 encoded), buffer, or KeyObject containing either the secret for HMAC algorithms, or the PEM\nencoded public key for RSA and ECDSA.\nIf `jwt.verify` is called asynchronous, `secretOrPublicKey` can be a function that should fetch the secret or public key. See below for a detailed example\n\nAs mentioned in [this comment](https:\u002F\u002Fgithub.com\u002Fauth0\u002Fnode-jsonwebtoken\u002Fissues\u002F208#issuecomment-231861138), there are other libraries that expect base64 encoded secrets (random bytes encoded using base64), if that is your case you can pass `Buffer.from(secret, 'base64')`, by doing this the secret will be decoded using base64 and the token verification will use the original random bytes.\n\n`options`\n\n* `algorithms`: List of strings with the names of the allowed algorithms. For instance, `[\"HS256\", \"HS384\"]`. \n  > If not specified a defaults will be used based on the type of key provided\n  > * secret - ['HS256', 'HS384', 'HS512']\n  > * rsa - ['RS256', 'RS384', 'RS512']\n  > * ec - ['ES256', 'ES384', 'ES512']\n  > * default - ['RS256', 'RS384', 'RS512']\n* `audience`: if you want to check audience (`aud`), provide a value here. The audience can be checked against a string, a regular expression or a list of strings and\u002For regular expressions. \n  > Eg: `\"urn:foo\"`, `\u002Furn:f[o]{2}\u002F`, `[\u002Furn:f[o]{2}\u002F, \"urn:bar\"]`\n* `complete`: return an object with the decoded `{ payload, header, signature }` instead of only the usual content of the payload.\n* `issuer` (optional): string or array of strings of valid values for the `iss` field.\n* `jwtid` (optional): if you want to check JWT ID (`jti`), provide a string value here.\n* `ignoreExpiration`: if `true` do not validate the expiration of the token.\n* `ignoreNotBefore`...\n* `subject`: if you want to check subject (`sub`), provide a value here\n* `clockTolerance`: number of seconds to tolerate when checking the `nbf` and `exp` claims, to deal with small clock differences among different servers\n* `maxAge`: the maximum allowed age for tokens to still be valid. It is expressed in seconds or a string describing a time span [vercel\u002Fms](https:\u002F\u002Fgithub.com\u002Fvercel\u002Fms). \n  > Eg: `1000`, `\"2 days\"`, `\"10h\"`, `\"7d\"`. A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default (`\"120\"` is equal to `\"120ms\"`).\n* `clockTimestamp`: the time in seconds that should be used as the current time for all necessary comparisons.\n* `nonce`: if you want to check `nonce` claim, provide a string value here. It is used on Open ID for the ID Tokens. ([Open ID implementation notes](https:\u002F\u002Fopenid.net\u002Fspecs\u002Fopenid-connect-core-1_0.html#NonceNotes))\n* `allowInvalidAsymmetricKeyTypes`: if true, allows asymmetric keys which do not match the specified algorithm. This option is intended only for backwards compatability and should be avoided.\n\n```js\n\u002F\u002F verify a token symmetric - synchronous\nvar decoded = jwt.verify(token, 'shhhhh');\nconsole.log(decoded.foo) \u002F\u002F bar\n\n\u002F\u002F verify a token symmetric\njwt.verify(token, 'shhhhh', function(err, decoded) {\n  console.log(decoded.foo) \u002F\u002F bar\n});\n\n\u002F\u002F invalid token - synchronous\ntry {\n  var decoded = jwt.verify(token, 'wrong-secret');\n} catch(err) {\n  \u002F\u002F err\n}\n\n\u002F\u002F invalid token\njwt.verify(token, 'wrong-secret', function(err, decoded) {\n  \u002F\u002F err\n  \u002F\u002F decoded undefined\n});\n\n\u002F\u002F verify a token asymmetric\nvar cert = fs.readFileSync('public.pem');  \u002F\u002F get public key\njwt.verify(token, cert, function(err, decoded) {\n  console.log(decoded.foo) \u002F\u002F bar\n});\n\n\u002F\u002F verify audience\nvar cert = fs.readFileSync('public.pem');  \u002F\u002F get public key\njwt.verify(token, cert, { audience: 'urn:foo' }, function(err, decoded) {\n  \u002F\u002F if audience mismatch, err == invalid audience\n});\n\n\u002F\u002F verify issuer\nvar cert = fs.readFileSync('public.pem');  \u002F\u002F get public key\njwt.verify(token, cert, { audience: 'urn:foo', issuer: 'urn:issuer' }, function(err, decoded) {\n  \u002F\u002F if issuer mismatch, err == invalid issuer\n});\n\n\u002F\u002F verify jwt id\nvar cert = fs.readFileSync('public.pem');  \u002F\u002F get public key\njwt.verify(token, cert, { audience: 'urn:foo', issuer: 'urn:issuer', jwtid: 'jwtid' }, function(err, decoded) {\n  \u002F\u002F if jwt id mismatch, err == invalid jwt id\n});\n\n\u002F\u002F verify subject\nvar cert = fs.readFileSync('public.pem');  \u002F\u002F get public key\njwt.verify(token, cert, { audience: 'urn:foo', issuer: 'urn:issuer', jwtid: 'jwtid', subject: 'subject' }, function(err, decoded) {\n  \u002F\u002F if subject mismatch, err == invalid subject\n});\n\n\u002F\u002F alg mismatch\nvar cert = fs.readFileSync('public.pem'); \u002F\u002F get public key\njwt.verify(token, cert, { algorithms: ['RS256'] }, function (err, payload) {\n  \u002F\u002F if token alg != RS256,  err == invalid signature\n});\n\n\u002F\u002F Verify using getKey callback\n\u002F\u002F Example uses https:\u002F\u002Fgithub.com\u002Fauth0\u002Fnode-jwks-rsa as a way to fetch the keys.\nvar jwksClient = require('jwks-rsa');\nvar client = jwksClient({\n  jwksUri: 'https:\u002F\u002Fsandrino.auth0.com\u002F.well-known\u002Fjwks.json'\n});\nfunction getKey(header, callback){\n  client.getSigningKey(header.kid, function(err, key) {\n    var signingKey = key.publicKey || key.rsaPublicKey;\n    callback(null, signingKey);\n  });\n}\n\njwt.verify(token, getKey, options, function(err, decoded) {\n  console.log(decoded.foo) \u002F\u002F bar\n});\n\n```\n\n\u003Cdetails>\n\u003Csummary>\u003Cem>\u003C\u002Fem>Need to peek into a JWT without verifying it? (Click to expand)\u003C\u002Fsummary>\n\n### jwt.decode(token [, options])\n\n(Synchronous) Returns the decoded payload without verifying if the signature is valid.\n\n> __Warning:__ This will __not__ verify whether the signature is valid. You should __not__ use this for untrusted messages. You most likely want to use `jwt.verify` instead.\n\n> __Warning:__ When the token comes from an untrusted source (e.g. user input or external request), the returned decoded payload should be treated like any other user input; please make sure to sanitize and only work with properties that are expected\n\n\n`token` is the JsonWebToken string\n\n`options`:\n\n* `json`: force JSON.parse on the payload even if the header doesn't contain `\"typ\":\"JWT\"`.\n* `complete`: return an object with the decoded payload and header.\n\nExample\n\n```js\n\u002F\u002F get the decoded payload ignoring signature, no secretOrPrivateKey needed\nvar decoded = jwt.decode(token);\n\n\u002F\u002F get the decoded payload and header\nvar decoded = jwt.decode(token, {complete: true});\nconsole.log(decoded.header);\nconsole.log(decoded.payload)\n```\n\n\u003C\u002Fdetails>\n\n## Errors & Codes\nPossible thrown errors during verification.\nError is the first argument of the verification callback.\n\n### TokenExpiredError\n\nThrown error if the token is expired.\n\nError object:\n\n* name: 'TokenExpiredError'\n* message: 'jwt expired'\n* expiredAt: [ExpDate]\n\n```js\njwt.verify(token, 'shhhhh', function(err, decoded) {\n  if (err) {\n    \u002F*\n      err = {\n        name: 'TokenExpiredError',\n        message: 'jwt expired',\n        expiredAt: 1408621000\n      }\n    *\u002F\n  }\n});\n```\n\n### JsonWebTokenError\nError object:\n\n* name: 'JsonWebTokenError'\n* message:\n  * 'invalid token' - the header or payload could not be parsed\n  * 'jwt malformed' - the token does not have three components (delimited by a `.`)\n  * 'jwt signature is required'\n  * 'invalid signature'\n  * 'jwt audience invalid. expected: [OPTIONS AUDIENCE]'\n  * 'jwt issuer invalid. expected: [OPTIONS ISSUER]'\n  * 'jwt id invalid. expected: [OPTIONS JWT ID]'\n  * 'jwt subject invalid. expected: [OPTIONS SUBJECT]'\n\n```js\njwt.verify(token, 'shhhhh', function(err, decoded) {\n  if (err) {\n    \u002F*\n      err = {\n        name: 'JsonWebTokenError',\n        message: 'jwt malformed'\n      }\n    *\u002F\n  }\n});\n```\n\n### NotBeforeError\nThrown if current time is before the nbf claim.\n\nError object:\n\n* name: 'NotBeforeError'\n* message: 'jwt not active'\n* date: 2018-10-04T16:10:44.000Z\n\n```js\njwt.verify(token, 'shhhhh', function(err, decoded) {\n  if (err) {\n    \u002F*\n      err = {\n        name: 'NotBeforeError',\n        message: 'jwt not active',\n        date: 2018-10-04T16:10:44.000Z\n      }\n    *\u002F\n  }\n});\n```\n\n\n## Algorithms supported\n\nArray of supported algorithms. The following algorithms are currently supported.\n\n| alg Parameter Value | Digital Signature or MAC Algorithm                                     |\n|---------------------|------------------------------------------------------------------------|\n| HS256               | HMAC using SHA-256 hash algorithm                                      |\n| HS384               | HMAC using SHA-384 hash algorithm                                      |\n| HS512               | HMAC using SHA-512 hash algorithm                                      |\n| RS256               | RSASSA-PKCS1-v1_5 using SHA-256 hash algorithm                         |\n| RS384               | RSASSA-PKCS1-v1_5 using SHA-384 hash algorithm                         |\n| RS512               | RSASSA-PKCS1-v1_5 using SHA-512 hash algorithm                         |\n| PS256               | RSASSA-PSS using SHA-256 hash algorithm (only node ^6.12.0 OR >=8.0.0) |\n| PS384               | RSASSA-PSS using SHA-384 hash algorithm (only node ^6.12.0 OR >=8.0.0) |\n| PS512               | RSASSA-PSS using SHA-512 hash algorithm (only node ^6.12.0 OR >=8.0.0) |\n| ES256               | ECDSA using P-256 curve and SHA-256 hash algorithm                     |\n| ES384               | ECDSA using P-384 curve and SHA-384 hash algorithm                     |\n| ES512               | ECDSA using P-521 curve and SHA-512 hash algorithm                     |\n| none                | No digital signature or MAC value included                             |\n\n## Refreshing JWTs\n\nFirst of all, we recommend you to think carefully if auto-refreshing a JWT will not introduce any vulnerability in your system.\n\nWe are not comfortable including this as part of the library, however, you can take a look at [this example](https:\u002F\u002Fgist.github.com\u002Fziluvatar\u002Fa3feb505c4c0ec37059054537b38fc48) to show how this could be accomplished.\nApart from that example there are [an issue](https:\u002F\u002Fgithub.com\u002Fauth0\u002Fnode-jsonwebtoken\u002Fissues\u002F122) and [a pull request](https:\u002F\u002Fgithub.com\u002Fauth0\u002Fnode-jsonwebtoken\u002Fpull\u002F172) to get more knowledge about this topic.\n\n# TODO\n\n* X.509 certificate chain is not checked\n\n## Issue Reporting\n\nIf you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https:\u002F\u002Fauth0.com\u002Fwhitehat) details the procedure for disclosing security issues.\n\n## Author\n\n[Auth0](https:\u002F\u002Fauth0.com)\n\n## License\n\nThis project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.\n","该项目是一个用于Node.js环境的JSON Web Token (JWT)实现，遵循IETF OAuth JSON Web Token标准。核心功能包括生成和验证JWT，支持多种加密算法如HMAC、RSA和ECDSA，并允许自定义过期时间等选项。技术特点上，它依赖于node-jws库来处理底层加密逻辑，确保了数据的安全性和完整性。适用于需要在分布式系统中安全传输信息的场景，比如API认证、单点登录(SSO)等。其简洁的API设计使得开发者能够轻松集成到现有的Node.js项目中。","2026-06-11 02:52:59","top_language"]