{"name":"@octokit/auth-token","description":"GitHub API token authentication for browsers and Node.js","version":"2.4.5","license":"MIT","pika":true,"sideEffects":false,"keywords":["github","octokit","authentication","api"],"homepage":"https://github.com/octokit/auth-token.js#readme","bugs":{"url":"https://github.com/octokit/auth-token.js/issues"},"repository":{"type":"git","url":"git+https://github.com/octokit/auth-token.js.git"},"dependencies":{"@octokit/types":"^6.0.3"},"devDependencies":{"@octokit/core":"^3.0.0","@octokit/request":"^5.3.0","@pika/pack":"^0.5.0","@pika/plugin-build-node":"^0.9.0","@pika/plugin-build-web":"^0.9.0","@pika/plugin-ts-standard-pkg":"^0.9.0","@types/fetch-mock":"^7.3.1","@types/jest":"^26.0.0","fetch-mock":"^9.0.0","jest":"^26.0.0","semantic-release":"^17.0.0","ts-jest":"^26.0.0","typescript":"^4.0.0"},"publishConfig":{"access":"public"},"source":"dist-src/index.js","types":"dist-types/index.d.ts","main":"dist-node/index.js","module":"dist-web/index.js","_id":"@octokit/auth-token@2.4.5","_nodeVersion":"12.20.0","_npmVersion":"6.14.11","dist":{"integrity":"sha512-BpGYsPgJt05M7/L/5FoE1PiAbdxXFZkX/3kDYcsvd1v6UhlnE5e96dTDr0ezX/EFwciQxf3cNV0loipsURU+WA==","shasum":"568ccfb8cb46f36441fac094ce34f7a875b197f3","tarball":"http://registry-npm.ywwl.com/@octokit/auth-token/download/@octokit/auth-token-2.4.5.tgz","fileCount":17,"unpackedSize":22340,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgDwPvCRA9TVsSAnZWagAAvWYP/jAk/fLUMZm6BqSUvnH0\nctjhbQj4iPYB1Y0CDTuq+LKpfp2ihzzev+D/8llTkO4fM4HhaFCN+wd2RuM0\n3gVNJsslZm9mxhlOFUKVVSJ0rTNfv01+xPKWF1c1KVZHNE4lwGVQz+sqdj50\nMOdC7D8QECOrrGLjrrMZQ+dhoMy1KxOJ13hstCDw8OJBz4Sz9S3SI6i1JSii\nliFElFBb7JfbJ0mI66kDiyHXSmMWA3hucUq0k5jxHxbEDCLvEDiaMzVQKlL8\nWcR1V2Acpkj0xj4JpbgQpjtXkYd2UHvVtsCKAYYJD1rxclplJn6n2FZ7aeOJ\nClC2Lwe5w1f1/6ZWf1AwkFHlJQnHUjvigBmfWYwDumuZCznGRLKnplQQzyoW\nxYp7DinkDEMZAyp83uDIDdWZdeb3zDsHTZL6kas5QVD9mNARmsTfdUV4ZHUe\nExcbu9Q6oh9hQoqsJKzTC2mV9ve0WiLLBlIK6v07ZKEPHYAE5Cp27ewAEa3E\nvd0p8n0oM7JjBX4wP54bHFDIBTfqBSc5/OWRTf+4LG4MBpHhPgzJuwQ9/Lqc\noJEYOJ+ssqqkhmkzu4Ipc/VXwAy3KI+6YwK1BJ1Ii+P2v02e6jTwpYd2OLCe\nIssxED5KNkVUQcukZDDdwSTzuUIV8o+JppOLAZ8AFyFoppgYNXI6CL8tUUN1\nEF2r\r\n=F96s\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCl7MM3oqEBoq5CgxLanj+48dyWVCKyKvKzKkUJ9yMsXgIgBJpR7c7VWcgsUiV86linNVI+H+pWJ6czCIOQ1oCaIao="}],"size":6447,"noattachment":false,"key":"/@octokit/auth-token/-/@octokit/auth-token-2.4.5.tgz"},"_npmUser":{"name":"octokitbot","email":"octokitbot@martynus.net"},"directories":{},"maintainers":[{"name":"gr2m","email":"gregor@martynus.net"},{"name":"octokitbot","email":"octokitbot@martynus.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/auth-token_2.4.5_1611596783219_0.694523529217467"},"_hasShrinkwrap":false,"readme":"# auth-token.js\n\n> GitHub API token authentication for browsers and Node.js\n\n[![@latest](https://img.shields.io/npm/v/@octokit/auth-token.svg)](https://www.npmjs.com/package/@octokit/auth-token)\n[![Build Status](https://github.com/octokit/auth-token.js/workflows/Test/badge.svg)](https://github.com/octokit/auth-token.js/actions?query=workflow%3ATest)\n\n`@octokit/auth-token` is the simplest of [GitHub’s authentication strategies](https://github.com/octokit/auth.js).\n\nIt is useful if you want to support multiple authentication strategies, as it’s API is compatible with its sibling packages for [basic](https://github.com/octokit/auth-basic.js), [GitHub App](https://github.com/octokit/auth-app.js) and [OAuth app](https://github.com/octokit/auth.js) authentication.\n\n<!-- toc -->\n\n- [Usage](#usage)\n- [`createTokenAuth(token) options`](#createtokenauthtoken-options)\n- [`auth()`](#auth)\n- [Authentication object](#authentication-object)\n- [`auth.hook(request, route, options)` or `auth.hook(request, options)`](#authhookrequest-route-options-or-authhookrequest-options)\n- [Find more information](#find-more-information)\n  - [Find out what scopes are enabled for oauth tokens](#find-out-what-scopes-are-enabled-for-oauth-tokens)\n  - [Find out if token is a personal access token or if it belongs to an OAuth app](#find-out-if-token-is-a-personal-access-token-or-if-it-belongs-to-an-oauth-app)\n  - [Find out what permissions are enabled for a repository](#find-out-what-permissions-are-enabled-for-a-repository)\n  - [Use token for git operations](#use-token-for-git-operations)\n- [License](#license)\n\n<!-- tocstop -->\n\n## Usage\n\n<table>\n<tbody valign=top align=left>\n<tr><th>\nBrowsers\n</th><td width=100%>\n\nLoad `@octokit/auth-token` directly from [esm.sh](https://esm.sh)\n\n```html\n<script type=\"module\">\n  import { createTokenAuth } from \"https://esm.sh/@octokit/auth-token\";\n</script>\n```\n\n</td></tr>\n<tr><th>\nNode\n</th><td>\n\nInstall with <code>npm install @octokit/auth-token</code>\n\n```js\nimport { createTokenAuth } from \"@octokit/auth-token\";\n```\n\n</td></tr>\n</tbody>\n</table>\n\n```js\nconst auth = createTokenAuth(\"ghp_PersonalAccessToken01245678900000000\");\nconst authentication = await auth();\n// {\n//   type: 'token',\n//   token: 'ghp_PersonalAccessToken01245678900000000',\n//   tokenType: 'oauth'\n// }\n```\n\n## `createTokenAuth(token) options`\n\nThe `createTokenAuth` method accepts a single argument of type string, which is the token. The passed token can be one of the following:\n\n- [Personal access token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line)\n- [OAuth access token](https://developer.github.com/apps/building-oauth-apps/authorizing-oauth-apps/)\n- [GITHUB_TOKEN provided to GitHub Actions](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables)\n- Installation access token ([server-to-server](https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-an-installation))\n- User authentication for installation ([user-to-server](https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps))\n\nExamples\n\n```js\n// Personal access token or OAuth access token\ncreateTokenAuth(\"ghp_PersonalAccessToken01245678900000000\");\n// {\n//   type: 'token',\n//   token: 'ghp_PersonalAccessToken01245678900000000',\n//   tokenType: 'oauth'\n// }\n\n// Installation access token or GitHub Action token\ncreateTokenAuth(\"ghs_InstallallationOrActionToken00000000\");\n// {\n//   type: 'token',\n//   token: 'ghs_InstallallationOrActionToken00000000',\n//   tokenType: 'installation'\n// }\n\n// Installation access token or GitHub Action token\ncreateTokenAuth(\"ghu_InstallationUserToServer000000000000\");\n// {\n//   type: 'token',\n//   token: 'ghu_InstallationUserToServer000000000000',\n//   tokenType: 'user-to-server'\n// }\n```\n\n## `auth()`\n\nThe `auth()` method has no options. It returns a promise which resolves with the the authentication object.\n\n## Authentication object\n\n<table width=\"100%\">\n  <thead align=left>\n    <tr>\n      <th width=150>\n        name\n      </th>\n      <th width=70>\n        type\n      </th>\n      <th>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tbody align=left valign=top>\n    <tr>\n      <th>\n        <code>type</code>\n      </th>\n      <th>\n        <code>string</code>\n      </th>\n      <td>\n        <code>\"token\"</code>\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>token</code>\n      </th>\n      <th>\n        <code>string</code>\n      </th>\n      <td>\n        The provided token.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>tokenType</code>\n      </th>\n      <th>\n        <code>string</code>\n      </th>\n      <td>\n        Can be either <code>\"oauth\"</code> for personal access tokens and OAuth tokens, <code>\"installation\"</code> for installation access tokens (includes <code>GITHUB_TOKEN</code> provided to GitHub Actions), <code>\"app\"</code> for a GitHub App JSON Web Token, or <code>\"user-to-server\"</code> for a user authentication token through an app installation.\n      </td>\n    </tr>\n  </tbody>\n</table>\n\n## `auth.hook(request, route, options)` or `auth.hook(request, options)`\n\n`auth.hook()` hooks directly into the request life cycle. It authenticates the request using the provided token.\n\nThe `request` option is an instance of [`@octokit/request`](https://github.com/octokit/request.js#readme). The `route`/`options` parameters are the same as for the [`request()` method](https://github.com/octokit/request.js#request).\n\n`auth.hook()` can be called directly to send an authenticated request\n\n```js\nconst { data: authorizations } = await auth.hook(\n  request,\n  \"GET /authorizations\",\n);\n```\n\nOr it can be passed as option to [`request()`](https://github.com/octokit/request.js#request).\n\n```js\nconst requestWithAuth = request.defaults({\n  request: {\n    hook: auth.hook,\n  },\n});\n\nconst { data: authorizations } = await requestWithAuth(\"GET /authorizations\");\n```\n\n## Find more information\n\n`auth()` does not send any requests, it only transforms the provided token string into an authentication object.\n\nHere is a list of things you can do to retrieve further information\n\n### Find out what scopes are enabled for oauth tokens\n\nNote that this does not work for installations. There is no way to retrieve permissions based on an installation access tokens.\n\n```js\nconst TOKEN = \"ghp_PersonalAccessToken01245678900000000\";\n\nconst auth = createTokenAuth(TOKEN);\nconst authentication = await auth();\n\nconst response = await request(\"HEAD /\");\nconst scopes = response.headers[\"x-oauth-scopes\"].split(/,\\s+/);\n\nif (scopes.length) {\n  console.log(\n    `\"${TOKEN}\" has ${scopes.length} scopes enabled: ${scopes.join(\", \")}`,\n  );\n} else {\n  console.log(`\"${TOKEN}\" has no scopes enabled`);\n}\n```\n\n### Find out if token is a personal access token or if it belongs to an OAuth app\n\n```js\nconst TOKEN = \"ghp_PersonalAccessToken01245678900000000\";\n\nconst auth = createTokenAuth(TOKEN);\nconst authentication = await auth();\n\nconst response = await request(\"HEAD /\");\nconst clientId = response.headers[\"x-oauth-client-id\"];\n\nif (clientId) {\n  console.log(\n    `\"${token}\" is an OAuth token, its app’s client_id is ${clientId}.`,\n  );\n} else {\n  console.log(`\"${token}\" is a personal access token`);\n}\n```\n\n### Find out what permissions are enabled for a repository\n\nNote that the `permissions` key is not set when authenticated using an installation access token.\n\n```js\nconst TOKEN = \"ghp_PersonalAccessToken01245678900000000\";\n\nconst auth = createTokenAuth(TOKEN);\nconst authentication = await auth();\n\nconst response = await request(\"GET /repos/{owner}/{repo}\", {\n  owner: \"octocat\",\n  repo: \"hello-world\",\n});\n\nconsole.log(response.data.permissions);\n// {\n//   admin: true,\n//   push: true,\n//   pull: true\n// }\n```\n\n### Use token for git operations\n\nBoth OAuth and installation access tokens can be used for git operations. However, when using with an installation, [the token must be prefixed with `x-access-token`](https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#http-based-git-access-by-an-installation).\n\nThis example is using the [`execa`](https://github.com/sindresorhus/execa) package to run a `git push` command.\n\n```js\nconst TOKEN = \"ghp_PersonalAccessToken01245678900000000\";\n\nconst auth = createTokenAuth(TOKEN);\nconst { token, tokenType } = await auth();\nconst tokenWithPrefix =\n  tokenType === \"installation\" ? `x-access-token:${token}` : token;\n\nconst repositoryUrl = `https://${tokenWithPrefix}@github.com/octocat/hello-world.git`;\n\nconst { stdout } = await execa(\"git\", [\"push\", repositoryUrl]);\nconsole.log(stdout);\n```\n\n## License\n\n[MIT](LICENSE)\n","publish_time":1611596783344,"_cnpm_publish_time":1611596783344,"dist-tags":{"beta":"5.0.0-beta.1","latest":"6.0.0","release-4.x":"4.0.0"}}