{"id":15570162,"url":"https://github.com/nfroidure/jwt-service","last_synced_at":"2025-04-24T02:11:08.977Z","repository":{"id":33018802,"uuid":"149969115","full_name":"nfroidure/jwt-service","owner":"nfroidure","description":"A simple wrapper around `jsonwebtoken`","archived":false,"fork":false,"pushed_at":"2025-02-06T14:44:55.000Z","size":2558,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T04:51:24.327Z","etag":null,"topics":["hacktoberfest","jwt","knifecycle"],"latest_commit_sha":null,"homepage":"https://insertafter.com/en/blog/unobstrusive_dependency_injection_with_knifecycle.html","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/nfroidure.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-23T09:13:58.000Z","updated_at":"2025-02-06T14:44:58.000Z","dependencies_parsed_at":"2023-01-14T23:04:32.916Z","dependency_job_id":null,"html_url":"https://github.com/nfroidure/jwt-service","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfroidure%2Fjwt-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfroidure%2Fjwt-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfroidure%2Fjwt-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nfroidure%2Fjwt-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nfroidure","download_url":"https://codeload.github.com/nfroidure/jwt-service/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250546086,"owners_count":21448260,"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":["hacktoberfest","jwt","knifecycle"],"created_at":"2024-10-02T17:41:27.240Z","updated_at":"2025-04-24T02:11:08.959Z","avatar_url":"https://github.com/nfroidure.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"[//]: # ( )\n[//]: # (This file is automatically generated by a `metapak`)\n[//]: # (module. Do not change it  except between the)\n[//]: # (`content:start/end` flags, your changes would)\n[//]: # (be overridden.)\n[//]: # ( )\n# jwt-service\n\u003e A simple wrapper for a simpler JWT surface API\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/jwt-service/blob/main/LICENSE)\n\n\n[//]: # (::contents:start)\n\nThis wrapper is directly usable with\n[Knifecycle](https://github.com/nfroidure/knifecycle).\n\n## Overriding\n\nLet's say you wanna create a sub-service of this one with custom inputs, for\nsay, refresh tokens in a [Whook](https://github.com/nfroidure/whook) project,\nhere is how you would do:\n\n```ts\nimport initJWT, { JWTServiceConfig } from 'jwt_service';\nimport { inject } from 'knifecycle';\n\nexport type RefreshJWTServiceConfig = {\n  ENV: JWTServiceConfig['ENV'];\n  REFRESH_JWT_SECRET_ENV_NAME: JWTServiceConfig['JWT_SECRET_ENV_NAME'];\n  REFRESH_JWT: JWTServiceConfig['JWT'];\n};\n\nexport default inject(\n  [\n    '?JWT_SECRET_ENV_NAME\u003eREFRESH_JWT_SECRET_ENV_NAME',\n    'JWT\u003eREFRESH_JWT',\n    '?ENV',\n    '?log',\n    '?time',\n  ],\n  initJWT,\n);\n```\n\n[//]: # (::contents:end)\n\n# API\n## Functions\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#initJWT\"\u003einitJWT(services)\u003c/a\u003e ⇒ \u003ccode\u003e\u003ca href=\"#JWTService\"\u003ePromise.\u0026lt;JWTService\u0026gt;\u003c/a\u003e\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003cp\u003eInstantiate the JWT service\u003c/p\u003e\n\u003c/dd\u003e\n\u003c/dl\u003e\n\n## Typedefs\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#JWTService\"\u003eJWTService\u003c/a\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003c/dd\u003e\n\u003c/dl\u003e\n\n\u003ca name=\"initJWT\"\u003e\u003c/a\u003e\n\n## initJWT(services) ⇒ [\u003ccode\u003ePromise.\u0026lt;JWTService\u0026gt;\u003c/code\u003e](#JWTService)\nInstantiate the JWT service\n\n**Kind**: global function  \n**Returns**: [\u003ccode\u003ePromise.\u0026lt;JWTService\u0026gt;\u003c/code\u003e](#JWTService) - A promise of the jwt service  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| services | \u003ccode\u003eObject\u003c/code\u003e | The services to inject |\n| [services.JWT_SECRET_ENV_NAME] | \u003ccode\u003efunction\u003c/code\u003e | The environment variable name in which to pick-up the  JWT secret |\n| [services.ENV] | \u003ccode\u003eObject\u003c/code\u003e | An environment object |\n| services.JWT | \u003ccode\u003efunction\u003c/code\u003e | The JWT service configuration object |\n| [services.log] | \u003ccode\u003efunction\u003c/code\u003e | A logging function |\n| [services.time] | \u003ccode\u003efunction\u003c/code\u003e | A function returning the current timestamp |\n\n**Example**  \n```js\nimport initJWTService from 'jwt-service';\n\nconst jwt = await initJWTService({\n  JWT: {\n    secret: 'secret',\n    duration: '2d',\n    tolerance: '2h',\n    algorithms: ['HS256'],\n  },\n  log: console.log.bind(console),\n  time: Date.now.bind(Date),\n});\n\nconst token = await jwt.sign({ my: 'payload' });\n```\n\u003ca name=\"JWTService\"\u003e\u003c/a\u003e\n\n## JWTService\n**Kind**: global typedef  \n\n* [JWTService](#JWTService)\n    * [.sign(payload, [algorithm])](#JWTService.sign) ⇒ \u003ccode\u003ePromise.\u0026lt;JWTSignResult\u0026gt;\u003c/code\u003e\n    * [.verify([token])](#JWTService.verify) ⇒ \u003ccode\u003ePromise.\u0026lt;Object\u0026gt;\u003c/code\u003e\n\n\u003ca name=\"JWTService.sign\"\u003e\u003c/a\u003e\n\n### JWTService.sign(payload, [algorithm]) ⇒ \u003ccode\u003ePromise.\u0026lt;JWTSignResult\u0026gt;\u003c/code\u003e\nSign the given payload\n\n**Kind**: static method of [\u003ccode\u003eJWTService\u003c/code\u003e](#JWTService)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;JWTSignResult\u0026gt;\u003c/code\u003e - A promise to be resolved with the signed token.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| payload | \u003ccode\u003eObject\u003c/code\u003e | The payload to sign |\n| [algorithm] | \u003ccode\u003eString\u003c/code\u003e | The signing algorithm |\n\n**Example**  \n```js\nconst token = await jwt.sign({ my: 'payload' });\n```\n\u003ca name=\"JWTService.verify\"\u003e\u003c/a\u003e\n\n### JWTService.verify([token]) ⇒ \u003ccode\u003ePromise.\u0026lt;Object\u0026gt;\u003c/code\u003e\nVerify and decode the given token\n\n**Kind**: static method of [\u003ccode\u003eJWTService\u003c/code\u003e](#JWTService)  \n**Returns**: \u003ccode\u003ePromise.\u0026lt;Object\u0026gt;\u003c/code\u003e - A promise to be resolved with the token payload.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| [token] | \u003ccode\u003eString\u003c/code\u003e | The token to decode |\n\n**Example**  \n```js\nconst payload = await jwt.verify('my.jwt.token');\n```\n\n# Authors\n- [Nicolas Froidure](https://insertafter.com/en/index.html)\n\n# License\n[MIT](https://github.com/nfroidure/jwt-service/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfroidure%2Fjwt-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnfroidure%2Fjwt-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnfroidure%2Fjwt-service/lists"}