{"id":22813096,"url":"https://github.com/coderivan/jwt-util","last_synced_at":"2025-03-30T21:42:21.770Z","repository":{"id":42700757,"uuid":"303618409","full_name":"CoderIvan/jwt-util","owner":"CoderIvan","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-07T21:44:28.000Z","size":369,"stargazers_count":0,"open_issues_count":11,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-06T01:47:11.992Z","etag":null,"topics":["jwt","nodejs","started","tutorial"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CoderIvan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-13T07:10:42.000Z","updated_at":"2020-10-16T02:32:57.000Z","dependencies_parsed_at":"2023-02-08T02:18:50.329Z","dependency_job_id":null,"html_url":"https://github.com/CoderIvan/jwt-util","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/CoderIvan%2Fjwt-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderIvan%2Fjwt-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderIvan%2Fjwt-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoderIvan%2Fjwt-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CoderIvan","download_url":"https://codeload.github.com/CoderIvan/jwt-util/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246385410,"owners_count":20768668,"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":["jwt","nodejs","started","tutorial"],"created_at":"2024-12-12T12:15:03.236Z","updated_at":"2025-03-30T21:42:21.743Z","avatar_url":"https://github.com/CoderIvan.png","language":"JavaScript","readme":"# jwt-util\r\n\r\n![Node.js CI](https://github.com/CoderIvan/jwt-util/workflows/Node.js%20CI/badge.svg)\r\n\r\n## 目的\r\n\r\n通过自己撸代码实现，加深对[JWT](https://jwt.io/introduction/)技术原理的理解\r\n\r\nAPI接口参照[node-jsonwebtoken](https://github.com/auth0/node-jsonwebtoken)\r\n\r\n目前只实现了`HS256`、`RS256`、`ES256`\r\n\r\n## 使用\r\n```javascript\r\nconst jwt = require('../../lib')\r\n\r\nconst secret = 'your-256-bit-secret'\r\n\r\nconst token = jwt.sign(\r\n\t{\r\n\t\tsub: '1234567890',\r\n\t\tname: 'John Doe',\r\n\t\tadmin: true,\r\n\t\tiat: 1516239022,\r\n\t},\r\n\tsecret,\r\n\t{\r\n\t\talgorithm: 'HS256',\r\n\t}\r\n)\r\n\r\nconsole.log(token) // 输出: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.reGQzG3OKdoIMWLDKOZ4TICJit3EW69cQE72E2CfzRE\r\n\r\nconst isValid = jwt.verify(token, secret)\r\n\r\nconsole.log(isValid) // 输出: true\r\n```\r\n\r\n其它见[example](https://github.com/CoderIvan/jwt-util/tree/main/example)\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderivan%2Fjwt-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoderivan%2Fjwt-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoderivan%2Fjwt-util/lists"}