{"id":20896191,"url":"https://github.com/waitingsong/egg-jwt","last_synced_at":"2025-09-02T11:42:00.900Z","repository":{"id":57169295,"uuid":"203496338","full_name":"waitingsong/egg-jwt","owner":"waitingsong","description":"egg-plugin jwt","archived":false,"fork":false,"pushed_at":"2021-07-05T04:40:10.000Z","size":340,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-11T17:28:53.704Z","etag":null,"topics":["authentication","egg","jwt","middleware","midway","sign","typescript","verify"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/waitingsong.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2019-08-21T03:09:25.000Z","updated_at":"2021-11-16T12:44:01.000Z","dependencies_parsed_at":"2022-09-13T19:31:12.401Z","dependency_job_id":null,"html_url":"https://github.com/waitingsong/egg-jwt","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waitingsong%2Fegg-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waitingsong%2Fegg-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waitingsong%2Fegg-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waitingsong%2Fegg-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waitingsong","download_url":"https://codeload.github.com/waitingsong/egg-jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225028633,"owners_count":17409613,"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":["authentication","egg","jwt","middleware","midway","sign","typescript","verify"],"created_at":"2024-11-18T10:34:12.297Z","updated_at":"2024-11-18T10:34:12.975Z","avatar_url":"https://github.com/waitingsong.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [egg-jwt](https://waitingsong.github.io/egg-jwt/)\n\n[jwt](https://www.npmjs.com/package/@waiting/egg-jwt) siging,\nverifying and authentication for midway/egg framework.\n\n\n[![Version](https://img.shields.io/npm/v/@waiting/egg-jwt.svg)](https://www.npmjs.com/package/@waiting/egg-jwt)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n![](https://img.shields.io/badge/lang-TypeScript-blue.svg)\n[![ci](https://github.com/waitingsong/egg-jwt/workflows/ci/badge.svg)](https://github.com/waitingsong/egg-jwt/actions?query=workflow%3A%22ci%22)\n[![codecov](https://codecov.io/gh/waitingsong/egg-jwt/branch/master/graph/badge.svg?token=oe8oDJp6Ol)](https://codecov.io/gh/waitingsong/egg-jwt)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n\n\n## Installation\n```sh\nnpm install @waiting/egg-jwt\n```\n\n\n## Configuration\n\n### Enable Plugin\n\nEdit `${app_root}/src/config/plugin.ts`:\n\n```ts\nexport const jwt = {\n  enable: true,\n  package: '@waiting/egg-jwt',\n}\n```\n\n### Add Configurations\n\n```ts\n/* location: ${app_root}/src/config/config.${env}.ts */\n\nimport { JwtEggConfig } from '@waiting/egg-jwt'\n\nexport const jwt: JwtEggConfig = {\n  agent: false,\n  enable: true, // enable middleware\n  client: {\n    debug: false,\n    secret: '123456abc',\n  },\n  // https://github.com/eggjs/egg-path-matching \n  ignore: ['/signup', '/login'],\n}\n```\n\n\n## Usage\n\n```ts\nimport { Provide, Plugin } from '@midwayjs/decorator'\nimport { Jwt } from '@waiting/egg-jwt'\nimport assert from 'assert'\n\n@provide()\nexport class UserService {\n\n  constructor(\n    @plugin() private readonly jwt: Jwt,\n  ) { }\n\n  @get('/siginup')\n  public signup(ctx: Context) {\n    const payload = { foo: 'bar', iat: 1566629919 }\n    const token = this.jwt.sign(payload)\n    const valid = this.jwt.verify(token)\n    assert.deepStrictEqual(valid, payload)\n    ctx.body = `\\nToken: ${token}`\n  }\n\n  @get('/')\n  public index(ctx: Context): void {\n    ctx.body = `\\nPayload: ${ctx.jwtState \u0026\u0026 ctx.jwtState.user ? JSON.stringify(ctx.jwtState.user) : 'Not found'}`\n  }\n\n}\n```\n\nThen:\n```sh\ncurl -I 127.0.0.1:7001\n// response HTTP/1.1 401 Unauthorized\n\ncurl 127.0.0.1:7001/signup\n// response ends with signature 'PZkACzct30IcrymoodYlW0LW0Fc1r6Hs1l8yOZSeNpk'\n\ncurl 127.0.0.1:7001/ \\\n-H \"Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE1NjY2Mjk5MTl9.PZkACzct30IcrymoodYlW0LW0Fc1r6Hs1l8yOZSeNpk\"\n// response payload: {\"foo\":\"bar\",\"iat\":1566629919}\n```\n\n\n## License\n[MIT](LICENSE)\n\n\n### Languages\n- [English](README.md)\n- [中文](README.zh-CN.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaitingsong%2Fegg-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaitingsong%2Fegg-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaitingsong%2Fegg-jwt/lists"}