{"id":24529278,"url":"https://github.com/opencomponents/oc-plugin-jwt","last_synced_at":"2025-03-15T17:46:05.986Z","repository":{"id":139897208,"uuid":"122643616","full_name":"opencomponents/oc-plugin-jwt","owner":"opencomponents","description":null,"archived":false,"fork":false,"pushed_at":"2020-02-20T13:52:57.000Z","size":11,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-01-22T07:37:57.232Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/opencomponents.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-23T16:13:09.000Z","updated_at":"2018-02-28T15:48:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"e92ba8dc-1458-4f11-9609-0f5d6930ac80","html_url":"https://github.com/opencomponents/oc-plugin-jwt","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/opencomponents%2Foc-plugin-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-plugin-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-plugin-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-plugin-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opencomponents","download_url":"https://codeload.github.com/opencomponents/oc-plugin-jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243769949,"owners_count":20345215,"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":[],"created_at":"2025-01-22T07:35:43.251Z","updated_at":"2025-03-15T17:46:05.977Z","avatar_url":"https://github.com/opencomponents.png","language":"JavaScript","readme":"# oc-plugin-jwt [![Greenkeeper badge](https://badges.greenkeeper.io/opencomponents/oc-plugin-jwt.svg)](https://greenkeeper.io/) [![Build Status](https://travis-ci.org/opencomponents/oc-plugin-jwt.svg?branch=master)](https://travis-ci.org/opencomponents/oc-plugin-jwt)\n\n\n[OpenComponents](https://github.com/opentable/oc) plugin for validating [JSON Web Token (JWT)](https://tools.ietf.org/html/rfc7519) inside OC components.\n\n## Requirements\n* Node version: min **6**\n* [OC Registry](https://github.com/opentable/oc)\n\n## Install\n\n```bash\nnpm i oc-plugin-jwt --save\n```\n\n## Registry setup\n\nMore info about integrating OC plugins: [here](https://github.com/opentable/oc/wiki/Registry#plugins)\n\n\nRegistering using the simple in-memory keystore.\n\n```js\nconst registry = oc.registry(configuration);\n\nregistry.register(\n  {\n    name: 'jwtVerify',\n    register: require('oc-plugin-jwt').verify,\n    options: {\n      keys: {\n        'key-id-1': {\n          publicKey: fs.readFileSync('certificate.pem')\n        },\n        'key-id-2': {\n          secret: 'super-secret-password'\n        }\n      }\n    }\n  }\n);\n\nregistry.start(callback);\n```\n\nOr custom using a custom keystore\n```js\nconst registry = oc.registry(configuration);\n\nregistry.register(\n  {\n    name: 'jwtVerify',\n    register: require('oc-plugin-jwt').verify,\n    options: {\n      keyStore: {\n        getSecretOrPublicKey(keyId, callback) {\n          // Get the public key or secret by some method\n          return callback(null, key);\n        }\n      }\n    }\n  }\n);\n\nregistry.start(callback);\n```\n\n## Using it inside components\n\nExample for a component's server.js:\n\n```js\nmodule.exports.data = (context, callback) =\u003e {\n  const exampleToken =\n    'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImtleS1pZC0yIn0.' +\n    'eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.' +\n    'bQVxleqAX7NQzI_RkIPFVfTl44-iEY0UYPUBm10789o';\n  context.plugins.jwtVerify(exampleToken, (error, verifiedToken) =\u003e {\n    if (error) {\n      // Handle token verification errors\n      callback(error);\n    }\n    callback(null, { verifiedToken: verifiedToken });\n  });\n};\n```\n\n## Generating Tokens\n\n* [See Here](https://github.com/opencomponents/oc-plugin-jwt-examples)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencomponents%2Foc-plugin-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopencomponents%2Foc-plugin-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencomponents%2Foc-plugin-jwt/lists"}