{"id":15062851,"url":"https://github.com/cmd-johnson/deno-oauth2-client","last_synced_at":"2025-04-24T04:04:41.243Z","repository":{"id":46597702,"uuid":"300549565","full_name":"cmd-johnson/deno-oauth2-client","owner":"cmd-johnson","description":"Minimalistic OAuth 2.0 client for Deno.","archived":false,"fork":false,"pushed_at":"2024-11-20T08:31:53.000Z","size":154,"stargazers_count":53,"open_issues_count":15,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-24T04:04:12.174Z","etag":null,"topics":["deno","hacktoberfest","oauth2","oauth2-client"],"latest_commit_sha":null,"homepage":"","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/cmd-johnson.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":"2020-10-02T08:24:58.000Z","updated_at":"2025-03-14T10:37:22.000Z","dependencies_parsed_at":"2022-09-22T19:51:09.686Z","dependency_job_id":"8c565fdb-45bf-4d81-8fb4-40514d919dea","html_url":"https://github.com/cmd-johnson/deno-oauth2-client","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.02564102564102566,"last_synced_commit":"95c0db3e65c8fd696d307e4278099cfb2615fe32"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmd-johnson%2Fdeno-oauth2-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmd-johnson%2Fdeno-oauth2-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmd-johnson%2Fdeno-oauth2-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmd-johnson%2Fdeno-oauth2-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmd-johnson","download_url":"https://codeload.github.com/cmd-johnson/deno-oauth2-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250560050,"owners_count":21450171,"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":["deno","hacktoberfest","oauth2","oauth2-client"],"created_at":"2024-09-24T23:47:29.054Z","updated_at":"2025-04-24T04:04:41.223Z","avatar_url":"https://github.com/cmd-johnson.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# OAuth2 Client for Deno\n\n[![JSR](https://jsr.io/badges/@cmd-johnson/oauth2-client)](https://jsr.io/@cmd-johnson/oauth2-client)\n![Tests](https://github.com/cmd-johnson/deno-oauth2-client/workflows/Tests/badge.svg)\n[![deno doc](https://doc.deno.land/badge.svg)](https://jsr.io/@cmd-johnson/oauth2-client/doc)\n\n\u003e [!IMPORTANT]\n\u003e This package will no longer be published to https://deno.land/x or support\n\u003e `http:` imports starting from version 2.0.0. Instead, future versions will be\n\u003e published to [JSR](https://jsr.io/) and require `jsr:` imports. See the\n\u003e [migration guide](#v1---v2) for instructions on how to migrate.\n\nMinimalistic OAuth 2.0 client for Deno. Inspired by\n[js-client-oauth2](https://github.com/mulesoft/js-client-oauth2/).\n\nThis module tries not to make assumptions on your use-cases. As such, it\n\n- has no external dependencies outside of Deno's standard library\n- can be used with Deno's [http module](https://deno.land/std@0.71.0/http) or\n  any other library for handling http requests, like\n  [oak](https://deno.land/x/oak)\n- only implements OAuth 2.0 grants, letting you take care of storing and\n  retrieving sessions, managing state parameters, etc.\n\nCurrently supported OAuth 2.0 grants:\n\n- [Authorization Code Grant (for clients with and without client secrets)](https://www.rfc-editor.org/rfc/rfc6749#section-4.1)\n  - Out of the box support for\n    [Proof Key for Code Exchange (PKCE)](https://www.rfc-editor.org/rfc/rfc7636)\n- [Implicit Grant](https://www.rfc-editor.org/rfc/rfc6749#section-4.2)\n- [Resource Owner Password Credentials Grant](https://www.rfc-editor.org/rfc/rfc6749#section-4.3)\n- [Client Credentials Grant](https://www.rfc-editor.org/rfc/rfc6749#section-4.4)\n- [Refresh Tokens](https://www.rfc-editor.org/rfc/rfc6749#section-6)\n\n## Usage\n\n### GitHub API example using [oak](https://jsr.io/@oak/oak)\n\n```ts ignore\nimport { Application } from \"jsr:@oak/oak@^17.1.3/application\";\nimport { Router } from \"jsr:@oak/oak@^17.1.3/router\";\nimport {\n  MemoryStore,\n  Session,\n} from \"https://deno.land/x/oak_sessions@v9.0.0/mod.ts\";\nimport { OAuth2Client } from \"jsr:@cmd-johnson/oauth2-client@^2.0.0\";\n\nconst oauth2Client = new OAuth2Client({\n  clientId: Deno.env.get(\"CLIENT_ID\")!,\n  clientSecret: Deno.env.get(\"CLIENT_SECRET\")!,\n  authorizationEndpointUri: \"https://github.com/login/oauth/authorize\",\n  tokenUri: \"https://github.com/login/oauth/access_token\",\n  redirectUri: \"http://localhost:8000/oauth2/callback\",\n  defaults: {\n    scope: \"read:user\",\n  },\n});\n\ntype AppState = {\n  session: Session;\n};\n\nconst router = new Router\u003cAppState\u003e();\nrouter.get(\"/login\", async (ctx) =\u003e {\n  // Construct the URL for the authorization redirect and get a PKCE codeVerifier\n  const { uri, codeVerifier } = await oauth2Client.code.getAuthorizationUri();\n\n  // Store both the state and codeVerifier in the user session\n  ctx.state.session.flash(\"codeVerifier\", codeVerifier);\n\n  // Redirect the user to the authorization endpoint\n  ctx.response.redirect(uri);\n});\nrouter.get(\"/oauth2/callback\", async (ctx) =\u003e {\n  // Make sure the codeVerifier is present for the user's session\n  const codeVerifier = ctx.state.session.get(\"codeVerifier\");\n  if (typeof codeVerifier !== \"string\") {\n    throw new Error(\"invalid codeVerifier\");\n  }\n\n  // Exchange the authorization code for an access token\n  const tokens = await oauth2Client.code.getToken(ctx.request.url, {\n    codeVerifier,\n  });\n\n  // Use the access token to make an authenticated API request\n  const userResponse = await fetch(\"https://api.github.com/user\", {\n    headers: {\n      Authorization: `Bearer ${tokens.accessToken}`,\n    },\n  });\n  const { login } = await userResponse.json();\n\n  ctx.response.body = `Hello, ${login}!`;\n});\n\nconst app = new Application\u003cAppState\u003e();\napp.use(Session.initMiddleware());\napp.use(router.allowedMethods(), router.routes());\n\nawait app.listen({ port: 8000 });\n```\n\n### More Examples\n\nFor more examples, check out the examples directory.\n\n## Migration\n\n### `v0.*.*` -\u003e `v1.*.*`\n\nWith `v1.0.0`:\n\n- we introduced PKCE by default for the Authorization Code Grant\n- enabled `stateValidator` callbacks to return a Promise, to allow for e.g.\n  accessing a database\n- cleaned up interface names to prevent name clashes between e.g. the\n  `AuthorizationCodeGrant` and `ImplicitGrant` option objects.\n\n#### `AuthorizationCodeGrant`\n\n- The `GetUriOptions` interface was renamed to `AuthorizationUriOptions`\n- `getAuthorizationUri(...)` now always returns a `Promise\u003c{ uri: URL }\u003e`\n  instead of a plain `URL`.\n  - when using PKCE (which is now the default), `getAuthorizationUri(...)`\n    returns an object containing both an URI and the `codeVerifier` that you'll\n    have to pass to the `getToken(...)` call inside the OAuth 2.0 redirection\n    URI handler. Check out the examples on how to achieve that by using session\n    cookies.\n  - while you should always use PKCE if possible, there are still OAuth 2.0\n    servers that don't support it. To opt out of PKCE, pass\n    `{ disablePkce: true }` to `getAuthorizationUri`.\n\n#### `ClientCredentialsGrant`\n\n- The `GetClientCredentialsTokenOptions` interface was renamed to\n  `ClientCredentialsTokenOptions`\n\n#### `ImplicitGrant`\n\n- The `GetUriOptions` interface was renamed to `ImplicitUriOptions`\n- The `GetTokenOptions` interface was renamed to `ImplicitTokenOptions`\n\n#### `ResourceOwnerPasswordCredentialsGrant`\n\n- The `GetROPCTokenOptions` interface was renamed to\n  `ResourceOwnerPasswordCredentialsTokenOptions`\n\n#### `RefreshTokenGrant`\n\n- No changes necessary\n\n### `v1.*.*` -\u003e `v2.*.*`\n\nThis package is now published to [JSR](https://jsr.io/) and no longer to\nhttps://deno.land/x. To migrate, replace HTTP imports with the root\n[`jsr:` import](https://jsr.io/docs/native-imports).\n\n```diff\n- import { OAuth2Client } from \"https://deno.land/x/oauth2_client/mod.ts\";\n+ import { OAuth2Client } from \"jsr:@cmd-johnson/oauth2-client\";\n\n// ...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmd-johnson%2Fdeno-oauth2-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmd-johnson%2Fdeno-oauth2-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmd-johnson%2Fdeno-oauth2-client/lists"}