{"id":19163276,"url":"https://github.com/oada/oada-id-client-js","last_synced_at":"2025-05-07T11:21:58.144Z","repository":{"id":20162488,"uuid":"23433125","full_name":"OADA/oada-id-client-js","owner":"OADA","description":"JavaScript client library for OADA identity.","archived":false,"fork":false,"pushed_at":"2023-03-14T23:57:51.000Z","size":4275,"stargazers_count":3,"open_issues_count":14,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-19T21:25:49.090Z","etag":null,"topics":["jwt","middleware","oada","oauth2","openid-connect"],"latest_commit_sha":null,"homepage":"client.oada-dev.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OADA.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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-08-28T15:29:20.000Z","updated_at":"2022-04-02T06:50:59.000Z","dependencies_parsed_at":"2025-04-20T15:15:26.755Z","dependency_job_id":null,"html_url":"https://github.com/OADA/oada-id-client-js","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Foada-id-client-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Foada-id-client-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Foada-id-client-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OADA%2Foada-id-client-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OADA","download_url":"https://codeload.github.com/OADA/oada-id-client-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252866124,"owners_count":21816397,"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","middleware","oada","oauth2","openid-connect"],"created_at":"2024-11-09T09:14:42.234Z","updated_at":"2025-05-07T11:21:58.109Z","avatar_url":"https://github.com/OADA.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @oada/id-client\n\n[![Coverage Status](https://coveralls.io/repos/OADA/oada-id-client-js/badge.svg?branch=master)](https://coveralls.io/r/OADA/oada-id-client-js?branch=master)\n[![npm](https://img.shields.io/npm/v/@oada/id-client)](https://www.npmjs.com/package/@oada/id-client)\n[![Downloads/week](https://img.shields.io/npm/dw/@oada/id-client.svg)](https://npmjs.org/package/@oada/id-client)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![License](https://img.shields.io/github/license/OADA/oada-id-client-js)](LICENSE)\n\nTypeScript/JavaScript client library for OADA identity.\nCan be used both in NodeJS and in the browser.\n\n## Getting Started\n\n### Installation\n\nFor use in NodeJS or with something like webpack:\n\n```sh\nyarn add @oada/id-client\n```\n\n### Browser Code Generation\n\nThe code to use in the browser can be generated with the following command:\n\n```sh\nyarn bundle\n```\n\nThis will create the file `bundle.js`.\n\n## Examples\n\n- [On Server Example][]\n- [In Browser Example][]\n\n## High-Level Node.JS wrapper Usage\n\nThis version of the library wraps the core functionality\nfor easy use in typical Node.JS uses.\n\nIt will pop up a window using the default browser\nto take the user through the needed flows\nand the return the resulting token(s).\n\n### getIDToken(domain, options)\n\nAsynchronous function for generating an ID token request against\nan OADA identity provider.\n\n#### Parameters\n\n`domain` string of domain with which to log in the user.\n\n`options` object containing at least the following properties:\n\n- `metadata` object containing [client metadata][],\n  or string of a [`software_statement`][] JWT\n- `privateKey` a private JWK for use in the JWT bearer client auth\n  (required for code flow)\n- `params` [Optional OpenID Connect parameters][oidparams] placed in `params` as\n  string properties will be used (e.g. `display`, `prompt`, `login_hint`)\n\n[Optional OpenID Connect parameters][oidparams] placed in options as\nstring properties will be used (e.g. `display`, `prompt`, `login_hint`).\n\n#### Usage Example\n\n```typescript\nconst options = {\n  metadata: {\n    /* See spec linked above */\n  },\n};\n\nconst domain = /* Set domain based on text box, dropdown, etc. */;\n\n// Promise will resolve after user completes the flow in the browser\nconst idToken = await oadaIdClient.getIDToken(domain, options);\nconsole.dir(idToken);\n```\n\n### getAccessToken(domain, options)\n\nAsynchronous function for generating an access token request against an\nOADA compliant API.\n\n#### Parameters\n\n`domain` string of domain from which to get an OADA API access token.\nThe value passed to the function can be overridden by a query or form\nparameter with a name of `domain`.\n\n`options` object containing at least the following properties:\n\n- `metadata` object containing [client metadata][],\n  or string of a [`software_statement`][] JWT\n- [`scope`][] space separated string of OAuth scopes for the request access\n  token to have.\n- `privateKey` a private JWK for use in the JWT bearer client auth\n  (required for code flow)\n- `params` [Optional OpenID Connect parameters][oidparams] placed in `params` as\n  string properties will be used (e.g. `display`, `prompt`, `login_hint`)\n\n#### Usage Example\n\n```typescript\nconst options = {\n  metadata: {\n    /* See spec linked above */\n  },\n  scope: 'some.oada.defined.scope',\n};\n\nconst domain = /* Set domain based on text box, dropdown, etc. */;\n\n// Promise will resolve after user completes the flow in the browser\nconst accessToken = await oadaIdClient.getAccessToken(domain, options);\nconsole.dir(accessToken);\n```\n\n## Connect Style \"Middleware\" Wrapper Usage\n\nThis version of the library wraps the core functionality\nfor use as connect style \"middleware\".\nThis can be used in a Node.JS server using a compatible web development\nframework, such as express.\n\nFor a working example of using this wrapper, see the [on server example][].\n\n### getIDToken(domain, options)\n\nMiddleware for generating an ID token request against an OADA identity\nprovider.\n\n#### Parameters\n\n`domain` string of domain with which to log in the user.\nThe value passed to the function can be overridden by a query or form\nparameter with a name of `domain`.\n\n`options` object containing at least the following properties:\n\n- `metadata` object containing [client metadata][],\n  or string of a [`software_statement`][] JWT\n- `privateKey` a private JWK for use in the JWT bearer client auth\n  (required for code flow)\n- `params` [Optional OpenID Connect parameters][oidparams] placed in `params` as\n  string properties will be used (e.g. `display`, `prompt`, `login_hint`)\n\n#### Usage Example\n\n```typescript\nconst options = {\n  metadata: {\n    /* See spec linked above */\n  },\n  privateKey: {\n    pem: fs.readFileSync('/path/to/key.pem'),\n    kid: 'key_id_corresponding_to_pem',\n  },\n};\n\napp.use(\n  '/getIdToken',\n  oadaIdClient.getIDToken('some.oada-identity-provider.com', options)\n);\n```\n\n### getAccessToken(domain, options)\n\nMiddleware for generating an access token request against an OADA compliant\nAPI.\n\n#### Parameters\n\n`domain` string of domain from which to get an OADA API access token.\nThe value passed to the function can be overridden by a query or form\nparameter with a name of `domain`.\n\n`options` object containing at least the following properties:\n\n- `metadata` object containing [client metadata][],\n  or string of a [`software_statement`][] JWT\n- `privateKey` a private JWK for use in the JWT bearer client auth\n  (required for code flow)\n- [`scope`][] space separated string of OAuth scopes for the request access\n  token to have.\n- `params` [Optional OpenID Connect parameters][oidparams] placed in `params` as\n  string properties will be used (e.g. `display`, `prompt`, `login_hint`)\n\n#### Usage Example\n\n```typescript\nconst options = {\n  metadata: {\n    /* See spec linked above */\n  },\n  privateKey: {\n    pem: fs.readFileSync('/path/to/key.pem'),\n    kid: 'key_id_corresponding_to_pem',\n  },\n  scope: 'some.oada.defined.scope',\n};\n\napp.use(\n  '/getAccessToken',\n  oadaIdClient.getAccessToken('some.oada-cloud-provider.com', options)\n);\n```\n\n### handleRedirect()\n\nMiddleware for handling redirects from `getIDToken` or `getAccessToken`\nmiddlewares.\nIn most cases, you will apply this middleware in two locations,\none to receive `getIDToken` redirects and\nanother to receive `getAccessToken` redirects.\n\n#### Usage Example\n\n```typescript\n// Handle ID token redirects\napp.use(\n  '/url/referenced/by/getIDToken/redirect_uri',\n  oadaIdClient.handleRedirect()\n);\napp.use(\n  '/url/referenced/by/getIDToken/redirect_uri',\n  function (req, res, next) {\n    // ID token is in req.token\n    console.dir(req.token);\n  }\n);\n\n// Handle access token redirects\napp.use(\n  '/url/referenced/by/getAccessToken/redirect_uri',\n  oadaIdClient.handleRedirect()\n);\napp.use(\n  '/url/referenced/by/getAccessToken/redirect_uri',\n  function (req, res, next) {\n    // Access token is in req.token\n    console.dir(req.token);\n  }\n);\n```\n\n## Browser Wrapper Usage\n\nThis version of the library wraps the core functionality\nfor easy use in the browser.\n\nFor a working example of using this wrapper, see the [in browser example][].\n\n### getIDToken(domain, options)\n\nAsynchronous function for generating an ID token request against\nan OADA identity provider.\n\n#### Parameters\n\n`domain` string of domain with which to log in the user.\n\n`options` object containing at least the following properties:\n\n- `metadata` object containing [client metadata][],\n  or string of a [`software_statement`][] JWT\n- `params` [Optional OpenID Connect parameters][oidparams] placed in `params` as\n  string properties will be used (e.g. `display`, `prompt`, `login_hint`)\n\n[Optional OpenID Connect parameters][oidparams] placed in options as\nstring properties will be used (e.g. `display`, `prompt`, `login_hint`).\n\n#### Usage Example\n\n```typescript\nconst options = {\n  metadata: {\n    /* See spec linked above */\n  },\n};\n\nconst domain = /* Set domain based on text box, dropdown, etc. */;\n\nconst idToken = await oadaIdClient.getIDToken(domain, options);\nconsole.dir(idToken);\n```\n\n### getAccessToken(domain, options)\n\nAsynchronous function for generating an access token request against an\nOADA compliant API.\n\n#### Parameters\n\n`domain` string of domain from which to get an OADA API access token.\nThe value passed to the function can be overridden by a query or form\nparameter with a name of `domain`.\n\n`options` object containing at least the following properties:\n\n- `metadata` object containing [client metadata][],\n  or string of a [`software_statement`][] JWT\n- [`scope`][] space separated string of OAuth scopes for the request access\n  token to have.\n- `params` [Optional OpenID Connect parameters][oidparams] placed in `params` as\n  string properties will be used (e.g. `display`, `prompt`, `login_hint`)\n\n#### Usage Example\n\n```typescript\nconst options = {\n  metadata: {\n    /* See spec linked above */\n  },\n  scope: 'some.oada.defined.scope',\n};\n\nconst domain = /* Set domain based on text box, dropdown, etc. */;\n\nconst accessToken = await oadaIdClient.getAccessToken(domain, options);\nconsole.dir(accessToken);\n```\n\n### handleRedirect()\n\nFunction for handling redirects generated by\n`getIDToken` or `getAccessToken` function.\nSimply needs to be called by the page served from the URL corresponding to\n[`redirect_uri`][].\n\n#### Usage Example\n\n```html\n\u003c!-- Page served at redirect_uri for getIDToken and/or getAccessToken --\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cscript src=\"path/to/library/browser/code.js\"\u003e\u003c/script\u003e\n    \u003cscript\u003e\n      oadaIdClient.handleRedirect();\n    \u003c/script\u003e\n  \u003c/head\u003e\n\u003c/html\u003e\n```\n\n## Base Library Usage\n\nNot yet documented.\n\n## References\n\n[on server example]: examples/server-client/\n[in browser example]: examples/browser-client/\n\n1. [OpenID Connect Core 1.0](http://openid.net/specs/openid-connect-core-1_0.html)\n1. [OAuth 2.0 Authorization Framework](http://tools.ietf.org/html/rfc6749 'RFC6749')\n1. [JSON Web Key (JWK) Draft 31](https://tools.ietf.org/html/draft-ietf-jose-json-web-key-31)\n1. [OAuth 2.0 Dynamic Client Registration Protocol](https://tools.ietf.org/html/draft-ietf-oauth-dyn-reg)\n\n[oidparams]: http://openid.net/specs/openid-connect-core-1_0.html#AuthRequest 'OpenID Connect Core 1.0 Section 3.1.2.1'\n[`client_id`]: http://tools.ietf.org/html/rfc6749#section-2.2 'RFC6794 Section 2.2'\n[`redirect_uri`]: http://tools.ietf.org/html/rfc6749#section-3.1.2 'RFC6794 Section 3.1.2'\n[`scope`]: http://tools.ietf.org/html/rfc6749#section-3.3 'RFC6794 Section 3.3'\n[`kid`]: https://tools.ietf.org/html/draft-ietf-jose-json-web-key-31#section-4.5 'JWK Section 4.5'\n[client metadata]: https://tools.ietf.org/html/draft-ietf-oauth-dyn-reg#section-2 'oauth-dyn-reg Section 2'\n[`software_statement`]: https://tools.ietf.org/html/draft-ietf-oauth-dyn-reg#section-2.3 'oauth-dyn-reg Section 2.3'\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foada%2Foada-id-client-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foada%2Foada-id-client-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foada%2Foada-id-client-js/lists"}