First upload version 0.0.1

This commit is contained in:
Neyra
2026-02-05 15:27:49 +08:00
commit 8e9b7201ed
4182 changed files with 593136 additions and 0 deletions

9
node_modules/@octokit/auth-oauth-device/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) 2021 Octokit contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

662
node_modules/@octokit/auth-oauth-device/README.md generated vendored Normal file
View File

@@ -0,0 +1,662 @@
# auth-oauth-device.js
> GitHub OAuth Device authentication strategy for JavaScript
[![@latest](https://img.shields.io/npm/v/@octokit/auth-oauth-device.svg)](https://www.npmjs.com/package/@octokit/auth-oauth-device)
[![Build Status](https://github.com/octokit/auth-oauth-device.js/workflows/Test/badge.svg)](https://github.com/octokit/auth-oauth-device.js/actions?query=workflow%3ATest+branch%3Amain)
`@octokit/auth-oauth-device` is implementing one of [GitHubs OAuth Device Flow](https://docs.github.com/en/developers/apps/authorizing-oauth-apps#device-flow).
<!-- toc -->
- [Usage](#usage)
- [For OAuth Apps](#for-oauth-apps)
- [For GitHub Apps](#for-github-apps)
- [`createOAuthDeviceAuth(options)`](#createoauthdeviceauthoptions)
- [`auth(options)`](#authoptions)
- [Authentication object](#authentication-object)
- [OAuth APP user authentication](#oauth-app-user-authentication)
- [GitHub APP user authentication with expiring tokens disabled](#github-app-user-authentication-with-expiring-tokens-disabled)
- [GitHub APP user authentication with expiring tokens enabled](#github-app-user-authentication-with-expiring-tokens-enabled)
- [`auth.hook(request, route, parameters)` or `auth.hook(request, options)`](#authhookrequest-route-parameters-or-authhookrequest-options)
- [Types](#types)
- [How it works](#how-it-works)
- [Contributing](#contributing)
- [License](#license)
<!-- tocstop -->
## Usage
<table>
<tbody valign=top align=left>
<tr><th>
Browsers
</th><td width=100%>
Load `@octokit/auth-oauth-device` directly from [esm.sh](https://esm.sh)
```html
<script type="module">
import { createOAuthDeviceAuth } from "https://esm.sh/@octokit/auth-oauth-device";
</script>
```
</td></tr>
<tr><th>
Node
</th><td>
Install with `npm install @octokit/core @octokit/auth-oauth-device`
```js
import { createOAuthDeviceAuth } from "@octokit/auth-oauth-device";
```
</td></tr>
</tbody>
</table>
> [!IMPORTANT]
> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json` by setting `"moduleResolution": "node16", "module": "node16"`.
>
> See the TypeScript docs on [package.json "exports"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).<br>
> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus)
### For OAuth Apps
```js
const auth = createOAuthDeviceAuth({
clientType: "oauth-app",
clientId: "1234567890abcdef1234",
scopes: ["public_repo"],
onVerification(verification) {
// verification example
// {
// device_code: "3584d83530557fdd1f46af8289938c8ef79f9dc5",
// user_code: "WDJB-MJHT",
// verification_uri: "https://github.com/login/device",
// expires_in: 900,
// interval: 5,
// };
console.log("Open %s", verification.verification_uri);
console.log("Enter code: %s", verification.user_code);
},
});
const tokenAuthentication = await auth({
type: "oauth",
});
// resolves with
// {
// type: "token",
// tokenType: "oauth",
// clientType: "oauth-app",
// clientId: "1234567890abcdef1234",
// token: "...", /* the created oauth token */
// scopes: [] /* depend on request scopes by OAuth app */
// }
```
### For GitHub Apps
GitHub Apps do not support `scopes`. Client IDs of GitHub Apps have a `lv1.` prefix. If the GitHub App has expiring user tokens enabled, the resulting `authentication` object has extra properties related to expiration and refreshing the token.
```js
const auth = createOAuthDeviceAuth({
clientType: "github-app",
clientId: "lv1.1234567890abcdef",
onVerification(verification) {
// verification example
// {
// device_code: "3584d83530557fdd1f46af8289938c8ef79f9dc5",
// user_code: "WDJB-MJHT",
// verification_uri: "https://github.com/login/device",
// expires_in: 900,
// interval: 5,
// };
console.log("Open %s", verification.verification_uri);
console.log("Enter code: %s", verification.user_code);
},
});
const tokenAuthentication = await auth({
type: "oauth",
});
// resolves with
// {
// type: "token",
// tokenType: "oauth",
// clientType: "github-app",
// clientId: "lv1.1234567890abcdef",
// token: "...", /* the created oauth token */
// }
// or if expiring user tokens are enabled
// {
// type: "token",
// tokenType: "oauth",
// clientType: "github-app",
// clientId: "lv1.1234567890abcdef",
// token: "...", /* the created oauth token */
// refreshToken: "...",
// expiresAt: "2022-01-01T08:00:0.000Z",
// refreshTokenExpiresAt: "2021-07-01T00:00:0.000Z",
// }
```
## `createOAuthDeviceAuth(options)`
The `createOAuthDeviceAuth` method accepts a single `options` parameter
<table width="100%">
<thead align=left>
<tr>
<th width=150>
name
</th>
<th width=70>
type
</th>
<th>
description
</th>
</tr>
</thead>
<tbody align=left valign=top>
<tr>
<th>
<code>clientId</code>
</th>
<th>
<code>string</code>
</th>
<td>
<strong>Required</strong>. Find your OAuth apps <code>Client ID</code> in your accounts developer settings.
</td>
</tr>
<tr>
<th>
<code>onVerification</code>
</th>
<th>
<code>function</code>
</th>
<td>
<strong>Required</strong>. A function that is called once the device and user codes were retrieved
The `onVerification()` callback can be used to pause until the user completes step 2, which might result in a better user experience.
```js
const auth = createOAuthDeviceAuth({
clientId: "1234567890abcdef1234",
onVerification(verification) {
console.log("Open %s", verification.verification_uri);
console.log("Enter code: %s", verification.user_code);
await prompt("press enter when you are ready to continue");
},
});
```
</td>
</tr>
<tr>
<th>
<code>clientType</code>
</th>
<th>
<code>string</code>
</th>
<td>
Must be either `oauth-app` or `github-app`. Defaults to `oauth-app`.
</td>
</tr>
<tr>
<th>
<code>request</code>
</th>
<th>
<code>function</code>
</th>
<td>
You can pass in your own <a href="https://github.com/octokit/request.js"><code>@octokit/request</code></a> instance. For usage with enterprise, set <code>baseUrl</code> to the API root endpoint. Example:
```js
import { request } from "@octokit/request";
createOAuthDeviceAuth({
clientId: "1234567890abcdef1234",
clientSecret: "secret",
request: request.defaults({
baseUrl: "https://ghe.my-company.com/api/v3",
}),
});
```
</td></tr>
<tr>
<th>
<code>scopes</code>
</th>
<th>
<code>array of strings</code>
</th>
<td>
Only relevant if `clientType` is set to `"oauth-app"`.
Array of scope names enabled for the token. Defaults to `[]`. See [available scopes](https://docs.github.com/en/developers/apps/scopes-for-oauth-apps#available-scopes).
</td>
</tr>
</tbody>
</table>
## `auth(options)`
The async `auth()` method returned by `createOAuthDeviceAuth(options)` accepts the following options
<table width="100%">
<thead align=left>
<tr>
<th width=150>
name
</th>
<th width=70>
type
</th>
<th>
description
</th>
</tr>
</thead>
<tbody align=left valign=top>
<tr>
<th>
<code>type</code>
</th>
<th>
<code>string</code>
</th>
<td>
<strong>Required.</strong> Must be set to <code>"oauth"</code>
</td>
</tr>
<tr>
<th>
<code>scopes</code>
</th>
<th>
<code>array of strings</code>
</th>
<td>
Only relevant if the `clientType` strategy options was set to `"oauth-app"`
Array of scope names enabled for the token. Defaults to what was set in the [strategy options](#createoauthdeviceauthoptions). See <a href="https://docs.github.com/en/developers/apps/scopes-for-oauth-apps#available-scopes">available scopes</a>
</td>
</tr>
<tr>
<th>
<code>refresh</code>
</th>
<th>
<code>boolean</code>
</th>
<td>
Defaults to `false`. When set to `false`, calling `auth(options)` will resolve with a token that was previously created for the same scopes if it exists. If set to `true` a new token will always be created.
</td>
</tr>
</tbody>
</table>
## Authentication object
The async `auth(options)` method resolves to one of three possible objects
1. OAuth APP user authentication
1. GitHub APP user authentication with expiring tokens disabled
1. GitHub APP user authentication with expiring tokens enabled
The differences are
1. `scopes` is only present for OAuth Apps
2. `refreshToken`, `expiresAt`, `refreshTokenExpiresAt` are only present for GitHub Apps, and only if token expiration is enabled
### OAuth APP user authentication
<table width="100%">
<thead align=left>
<tr>
<th width=150>
name
</th>
<th width=70>
type
</th>
<th>
description
</th>
</tr>
</thead>
<tbody align=left valign=top>
<tr>
<th>
<code>type</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"token"</code>
</td>
</tr>
<tr>
<th>
<code>tokenType</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"oauth"</code>
</td>
</tr>
<tr>
<th>
<code>clientType</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"github-app"</code>
</td>
</tr>
<tr>
<th>
<code>clientId</code>
</th>
<th>
<code>string</code>
</th>
<td>
The app's <code>Client ID</code>
</td>
</tr>
<tr>
<th>
<code>token</code>
</th>
<th>
<code>string</code>
</th>
<td>
The personal access token
</td>
</tr>
<tr>
<th>
<code>scopes</code>
</th>
<th>
<code>array of strings</code>
</th>
<td>
array of scope names enabled for the token
</td>
</tr>
</tbody>
</table>
### GitHub APP user authentication with expiring tokens disabled
<table width="100%">
<thead align=left>
<tr>
<th width=150>
name
</th>
<th width=70>
type
</th>
<th>
description
</th>
</tr>
</thead>
<tbody align=left valign=top>
<tr>
<th>
<code>type</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"token"</code>
</td>
</tr>
<tr>
<th>
<code>tokenType</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"oauth"</code>
</td>
</tr>
<tr>
<th>
<code>clientType</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"github-app"</code>
</td>
</tr>
<tr>
<th>
<code>clientId</code>
</th>
<th>
<code>string</code>
</th>
<td>
The app's <code>Client ID</code>
</td>
</tr>
<tr>
<th>
<code>token</code>
</th>
<th>
<code>string</code>
</th>
<td>
The personal access token
</td>
</tr>
</tbody>
</table>
### GitHub APP user authentication with expiring tokens enabled
<table width="100%">
<thead align=left>
<tr>
<th width=150>
name
</th>
<th width=70>
type
</th>
<th>
description
</th>
</tr>
</thead>
<tbody align=left valign=top>
<tr>
<th>
<code>type</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"token"</code>
</td>
</tr>
<tr>
<th>
<code>tokenType</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"oauth"</code>
</td>
</tr>
<tr>
<th>
<code>clientType</code>
</th>
<th>
<code>string</code>
</th>
<td>
<code>"github-app"</code>
</td>
</tr>
<tr>
<th>
<code>clientId</code>
</th>
<th>
<code>string</code>
</th>
<td>
The app's <code>Client ID</code>
</td>
</tr>
<tr>
<th>
<code>token</code>
</th>
<th>
<code>string</code>
</th>
<td>
The user access token
</td>
</tr>
<tr>
<th>
<code>refreshToken</code>
</th>
<th>
<code>string</code>
</th>
<td>
The refresh token
</td>
</tr>
<tr>
<th>
<code>expiresAt</code>
</th>
<th>
<code>string</code>
</th>
<td>
Date timestamp in <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString">ISO 8601</a> standard. Example: <code>2022-01-01T08:00:0.000Z</code>
</td>
</tr>
<tr>
<th>
<code>refreshTokenExpiresAt</code>
</th>
<th>
<code>string</code>
</th>
<td>
Date timestamp in <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString">ISO 8601</a> standard. Example: <code>2021-07-01T00:00:0.000Z</code>
</td>
</tr>
</tbody>
</table>
## `auth.hook(request, route, parameters)` or `auth.hook(request, options)`
`auth.hook()` hooks directly into the request life cycle. It amends the request to authenticate correctly based on the request URL.
The `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).
`auth.hook()` can be called directly to send an authenticated request
```js
const { data: user } = await auth.hook(request, "GET /user");
```
Or it can be passed as option to [`request()`](https://github.com/octokit/request.js#request).
```js
const requestWithAuth = request.defaults({
request: {
hook: auth.hook,
},
});
const { data: user } = await requestWithAuth("GET /user");
```
## Types
```ts
import {
OAuthAppStrategyOptions,
OAuthAppAuthOptions,
OAuthAppAuthentication,
GitHubAppStrategyOptions,
GitHubAppAuthOptions,
GitHubAppAuthentication,
GitHubAppAuthenticationWithExpiration,
} from "@octokit/auth-oauth-device";
```
## How it works
GitHub's OAuth Device flow is different from the web flow in two ways
1. It does not require a URL redirect, which makes it great for devices and CLI apps
2. It does not require the OAuth client secret, which means there is no user-owned server component required.
The flow has 3 parts (see [GitHub documentation](https://docs.github.com/en/developers/apps/authorizing-oauth-apps#device-flow))
1. `@octokit/auth-oauth-device` requests a device and user code
2. Then the user has to open https://github.com/login/device (or it's GitHub Enterprise Server equivalent) and enter the user code
3. While the user enters the code, `@octokit/auth-oauth-device` is sending requests in the background to retrieve the OAuth access token. Once the user completed step 2, the request will succeed and the token will be returned
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md)
## License
[MIT](LICENSE)

View File

@@ -0,0 +1,138 @@
// pkg/dist-src/index.js
import { getUserAgent } from "universal-user-agent";
import { request as octokitRequest } from "@octokit/request";
// pkg/dist-src/get-oauth-access-token.js
import { createDeviceCode, exchangeDeviceCode } from "@octokit/oauth-methods";
async function getOAuthAccessToken(state, options) {
const cachedAuthentication = getCachedAuthentication(state, options.auth);
if (cachedAuthentication) return cachedAuthentication;
const { data: verification } = await createDeviceCode({
clientType: state.clientType,
clientId: state.clientId,
request: options.request || state.request,
// @ts-expect-error the extra code to make TS happy is not worth it
scopes: options.auth.scopes || state.scopes
});
await state.onVerification(verification);
const authentication = await waitForAccessToken(
options.request || state.request,
state.clientId,
state.clientType,
verification
);
state.authentication = authentication;
return authentication;
}
function getCachedAuthentication(state, auth2) {
if (auth2.refresh === true) return false;
if (!state.authentication) return false;
if (state.clientType === "github-app") {
return state.authentication;
}
const authentication = state.authentication;
const newScope = ("scopes" in auth2 && auth2.scopes || state.scopes).join(
" "
);
const currentScope = authentication.scopes.join(" ");
return newScope === currentScope ? authentication : false;
}
async function wait(seconds) {
await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
}
async function waitForAccessToken(request, clientId, clientType, verification) {
try {
const options = {
clientId,
request,
code: verification.device_code
};
const { authentication } = clientType === "oauth-app" ? await exchangeDeviceCode({
...options,
clientType: "oauth-app"
}) : await exchangeDeviceCode({
...options,
clientType: "github-app"
});
return {
type: "token",
tokenType: "oauth",
...authentication
};
} catch (error) {
if (!error.response) throw error;
const errorType = error.response.data.error;
if (errorType === "authorization_pending") {
await wait(verification.interval);
return waitForAccessToken(request, clientId, clientType, verification);
}
if (errorType === "slow_down") {
await wait(verification.interval + 7);
return waitForAccessToken(request, clientId, clientType, verification);
}
throw error;
}
}
// pkg/dist-src/auth.js
async function auth(state, authOptions) {
return getOAuthAccessToken(state, {
auth: authOptions
});
}
// pkg/dist-src/hook.js
async function hook(state, request, route, parameters) {
let endpoint = request.endpoint.merge(
route,
parameters
);
if (/\/login\/(oauth\/access_token|device\/code)$/.test(endpoint.url)) {
return request(endpoint);
}
const { token } = await getOAuthAccessToken(state, {
request,
auth: { type: "oauth" }
});
endpoint.headers.authorization = `token ${token}`;
return request(endpoint);
}
// pkg/dist-src/version.js
var VERSION = "0.0.0-development";
// pkg/dist-src/index.js
function createOAuthDeviceAuth(options) {
const requestWithDefaults = options.request || octokitRequest.defaults({
headers: {
"user-agent": `octokit-auth-oauth-device.js/${VERSION} ${getUserAgent()}`
}
});
const { request = requestWithDefaults, ...otherOptions } = options;
const state = options.clientType === "github-app" ? {
...otherOptions,
clientType: "github-app",
request
} : {
...otherOptions,
clientType: "oauth-app",
request,
scopes: options.scopes || []
};
if (!options.clientId) {
throw new Error(
'[@octokit/auth-oauth-device] "clientId" option must be set (https://github.com/octokit/auth-oauth-device.js#usage)'
);
}
if (!options.onVerification) {
throw new Error(
'[@octokit/auth-oauth-device] "onVerification" option must be a function (https://github.com/octokit/auth-oauth-device.js#usage)'
);
}
return Object.assign(auth.bind(null, state), {
hook: hook.bind(null, state)
});
}
export {
createOAuthDeviceAuth
};

View File

@@ -0,0 +1,7 @@
{
"version": 3,
"sources": ["../dist-src/index.js", "../dist-src/get-oauth-access-token.js", "../dist-src/auth.js", "../dist-src/hook.js", "../dist-src/version.js"],
"sourcesContent": ["import { getUserAgent } from \"universal-user-agent\";\nimport { request as octokitRequest } from \"@octokit/request\";\nimport { auth } from \"./auth.js\";\nimport { hook } from \"./hook.js\";\nimport { VERSION } from \"./version.js\";\nfunction createOAuthDeviceAuth(options) {\n const requestWithDefaults = options.request || octokitRequest.defaults({\n headers: {\n \"user-agent\": `octokit-auth-oauth-device.js/${VERSION} ${getUserAgent()}`\n }\n });\n const { request = requestWithDefaults, ...otherOptions } = options;\n const state = options.clientType === \"github-app\" ? {\n ...otherOptions,\n clientType: \"github-app\",\n request\n } : {\n ...otherOptions,\n clientType: \"oauth-app\",\n request,\n scopes: options.scopes || []\n };\n if (!options.clientId) {\n throw new Error(\n '[@octokit/auth-oauth-device] \"clientId\" option must be set (https://github.com/octokit/auth-oauth-device.js#usage)'\n );\n }\n if (!options.onVerification) {\n throw new Error(\n '[@octokit/auth-oauth-device] \"onVerification\" option must be a function (https://github.com/octokit/auth-oauth-device.js#usage)'\n );\n }\n return Object.assign(auth.bind(null, state), {\n hook: hook.bind(null, state)\n });\n}\nexport {\n createOAuthDeviceAuth\n};\n", "import { createDeviceCode, exchangeDeviceCode } from \"@octokit/oauth-methods\";\nasync function getOAuthAccessToken(state, options) {\n const cachedAuthentication = getCachedAuthentication(state, options.auth);\n if (cachedAuthentication) return cachedAuthentication;\n const { data: verification } = await createDeviceCode({\n clientType: state.clientType,\n clientId: state.clientId,\n request: options.request || state.request,\n // @ts-expect-error the extra code to make TS happy is not worth it\n scopes: options.auth.scopes || state.scopes\n });\n await state.onVerification(verification);\n const authentication = await waitForAccessToken(\n options.request || state.request,\n state.clientId,\n state.clientType,\n verification\n );\n state.authentication = authentication;\n return authentication;\n}\nfunction getCachedAuthentication(state, auth) {\n if (auth.refresh === true) return false;\n if (!state.authentication) return false;\n if (state.clientType === \"github-app\") {\n return state.authentication;\n }\n const authentication = state.authentication;\n const newScope = (\"scopes\" in auth && auth.scopes || state.scopes).join(\n \" \"\n );\n const currentScope = authentication.scopes.join(\" \");\n return newScope === currentScope ? authentication : false;\n}\nasync function wait(seconds) {\n await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));\n}\nasync function waitForAccessToken(request, clientId, clientType, verification) {\n try {\n const options = {\n clientId,\n request,\n code: verification.device_code\n };\n const { authentication } = clientType === \"oauth-app\" ? await exchangeDeviceCode({\n ...options,\n clientType: \"oauth-app\"\n }) : await exchangeDeviceCode({\n ...options,\n clientType: \"github-app\"\n });\n return {\n type: \"token\",\n tokenType: \"oauth\",\n ...authentication\n };\n } catch (error) {\n if (!error.response) throw error;\n const errorType = error.response.data.error;\n if (errorType === \"authorization_pending\") {\n await wait(verification.interval);\n return waitForAccessToken(request, clientId, clientType, verification);\n }\n if (errorType === \"slow_down\") {\n await wait(verification.interval + 7);\n return waitForAccessToken(request, clientId, clientType, verification);\n }\n throw error;\n }\n}\nexport {\n getOAuthAccessToken\n};\n", "import { getOAuthAccessToken } from \"./get-oauth-access-token.js\";\nasync function auth(state, authOptions) {\n return getOAuthAccessToken(state, {\n auth: authOptions\n });\n}\nexport {\n auth\n};\n", "import { getOAuthAccessToken } from \"./get-oauth-access-token.js\";\nasync function hook(state, request, route, parameters) {\n let endpoint = request.endpoint.merge(\n route,\n parameters\n );\n if (/\\/login\\/(oauth\\/access_token|device\\/code)$/.test(endpoint.url)) {\n return request(endpoint);\n }\n const { token } = await getOAuthAccessToken(state, {\n request,\n auth: { type: \"oauth\" }\n });\n endpoint.headers.authorization = `token ${token}`;\n return request(endpoint);\n}\nexport {\n hook\n};\n", "const VERSION = \"0.0.0-development\";\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ACD,QAAM,EAAE,UAAU,qBAAqB,GAAG,aAAa,IAAI;AAC3D,QAAM,QAAQ,QAAQ,eAAe,eAAe;AAAA,IAClD,GAAG;AAAA,IACH,YAAY;AAAA,IACZ;AAAA,EACF,IAAI;AAAA,IACF,GAAG;AAAA,IACH,YAAY;AAAA,IACZ;AAAA,IACA,QAAQ,QAAQ,UAAU,CAAC;AAAA,EAC7B;AACA,MAAI,CAAC,QAAQ,UAAU;AACrB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,MAAI,CAAC,QAAQ,gBAAgB;AAC3B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,OAAO,OAAO,KAAK,KAAK,MAAM,KAAK,GAAG;AAAA,IAC3C,MAAM,KAAK,KAAK,MAAM,KAAK;AAAA,EAC7B,CAAC;AACH;",
"names": ["auth"]
}

View File

@@ -0,0 +1,9 @@
import { getOAuthAccessToken } from "./get-oauth-access-token.js";
async function auth(state, authOptions) {
return getOAuthAccessToken(state, {
auth: authOptions
});
}
export {
auth
};

View File

@@ -0,0 +1,73 @@
import { createDeviceCode, exchangeDeviceCode } from "@octokit/oauth-methods";
async function getOAuthAccessToken(state, options) {
const cachedAuthentication = getCachedAuthentication(state, options.auth);
if (cachedAuthentication) return cachedAuthentication;
const { data: verification } = await createDeviceCode({
clientType: state.clientType,
clientId: state.clientId,
request: options.request || state.request,
// @ts-expect-error the extra code to make TS happy is not worth it
scopes: options.auth.scopes || state.scopes
});
await state.onVerification(verification);
const authentication = await waitForAccessToken(
options.request || state.request,
state.clientId,
state.clientType,
verification
);
state.authentication = authentication;
return authentication;
}
function getCachedAuthentication(state, auth) {
if (auth.refresh === true) return false;
if (!state.authentication) return false;
if (state.clientType === "github-app") {
return state.authentication;
}
const authentication = state.authentication;
const newScope = ("scopes" in auth && auth.scopes || state.scopes).join(
" "
);
const currentScope = authentication.scopes.join(" ");
return newScope === currentScope ? authentication : false;
}
async function wait(seconds) {
await new Promise((resolve) => setTimeout(resolve, seconds * 1e3));
}
async function waitForAccessToken(request, clientId, clientType, verification) {
try {
const options = {
clientId,
request,
code: verification.device_code
};
const { authentication } = clientType === "oauth-app" ? await exchangeDeviceCode({
...options,
clientType: "oauth-app"
}) : await exchangeDeviceCode({
...options,
clientType: "github-app"
});
return {
type: "token",
tokenType: "oauth",
...authentication
};
} catch (error) {
if (!error.response) throw error;
const errorType = error.response.data.error;
if (errorType === "authorization_pending") {
await wait(verification.interval);
return waitForAccessToken(request, clientId, clientType, verification);
}
if (errorType === "slow_down") {
await wait(verification.interval + 7);
return waitForAccessToken(request, clientId, clientType, verification);
}
throw error;
}
}
export {
getOAuthAccessToken
};

View File

@@ -0,0 +1,19 @@
import { getOAuthAccessToken } from "./get-oauth-access-token.js";
async function hook(state, request, route, parameters) {
let endpoint = request.endpoint.merge(
route,
parameters
);
if (/\/login\/(oauth\/access_token|device\/code)$/.test(endpoint.url)) {
return request(endpoint);
}
const { token } = await getOAuthAccessToken(state, {
request,
auth: { type: "oauth" }
});
endpoint.headers.authorization = `token ${token}`;
return request(endpoint);
}
export {
hook
};

View File

@@ -0,0 +1,39 @@
import { getUserAgent } from "universal-user-agent";
import { request as octokitRequest } from "@octokit/request";
import { auth } from "./auth.js";
import { hook } from "./hook.js";
import { VERSION } from "./version.js";
function createOAuthDeviceAuth(options) {
const requestWithDefaults = options.request || octokitRequest.defaults({
headers: {
"user-agent": `octokit-auth-oauth-device.js/${VERSION} ${getUserAgent()}`
}
});
const { request = requestWithDefaults, ...otherOptions } = options;
const state = options.clientType === "github-app" ? {
...otherOptions,
clientType: "github-app",
request
} : {
...otherOptions,
clientType: "oauth-app",
request,
scopes: options.scopes || []
};
if (!options.clientId) {
throw new Error(
'[@octokit/auth-oauth-device] "clientId" option must be set (https://github.com/octokit/auth-oauth-device.js#usage)'
);
}
if (!options.onVerification) {
throw new Error(
'[@octokit/auth-oauth-device] "onVerification" option must be a function (https://github.com/octokit/auth-oauth-device.js#usage)'
);
}
return Object.assign(auth.bind(null, state), {
hook: hook.bind(null, state)
});
}
export {
createOAuthDeviceAuth
};

View File

@@ -0,0 +1,4 @@
const VERSION = "8.0.3";
export {
VERSION
};

View File

@@ -0,0 +1,2 @@
import type { OAuthAppAuthOptions, GitHubAppAuthOptions, OAuthAppAuthentication, GitHubAppAuthentication, OAuthAppState, GitHubAppState } from "./types.js";
export declare function auth(state: OAuthAppState | GitHubAppState, authOptions: OAuthAppAuthOptions | GitHubAppAuthOptions): Promise<OAuthAppAuthentication | GitHubAppAuthentication>;

View File

@@ -0,0 +1,6 @@
import type { RequestInterface } from "@octokit/types";
import type { OAuthAppState, GitHubAppState, OAuthAppAuthOptions, GitHubAppAuthOptions, OAuthAppAuthentication, GitHubAppAuthentication } from "./types.js";
export declare function getOAuthAccessToken(state: OAuthAppState | GitHubAppState, options: {
request?: RequestInterface;
auth: OAuthAppAuthOptions | GitHubAppAuthOptions;
}): Promise<OAuthAppAuthentication | GitHubAppAuthentication>;

View File

@@ -0,0 +1,3 @@
import type { RequestInterface, OctokitResponse, EndpointOptions, RequestParameters, Route } from "@octokit/types";
import type { OAuthAppState, GitHubAppState } from "./types.js";
export declare function hook(state: OAuthAppState | GitHubAppState, request: RequestInterface, route: Route | EndpointOptions, parameters?: RequestParameters): Promise<OctokitResponse<any>>;

View File

@@ -0,0 +1,4 @@
import type { GitHubAppAuthInterface, GitHubAppStrategyOptions, OAuthAppAuthInterface, OAuthAppStrategyOptions } from "./types.js";
export type { OAuthAppStrategyOptions, OAuthAppAuthOptions, OAuthAppAuthentication, GitHubAppStrategyOptions, GitHubAppAuthOptions, GitHubAppAuthentication, GitHubAppAuthenticationWithExpiration, } from "./types.js";
export declare function createOAuthDeviceAuth(options: OAuthAppStrategyOptions): OAuthAppAuthInterface;
export declare function createOAuthDeviceAuth(options: GitHubAppStrategyOptions): GitHubAppAuthInterface;

View File

@@ -0,0 +1,68 @@
import type { RequestInterface, Route, EndpointOptions, RequestParameters, OctokitResponse } from "@octokit/types";
import type * as OAuthMethodsTypes from "@octokit/oauth-methods";
export type ClientType = "oauth-app" | "github-app";
export type OAuthAppStrategyOptions = {
clientId: string;
clientType?: "oauth-app";
onVerification: OnVerificationCallback;
scopes?: string[];
request?: RequestInterface;
};
export type GitHubAppStrategyOptions = {
clientId: string;
clientType: "github-app";
onVerification: OnVerificationCallback;
request?: RequestInterface;
};
export interface OAuthAppAuthInterface {
(options: OAuthAppAuthOptions): Promise<OAuthAppAuthentication>;
hook(request: RequestInterface, route: Route | EndpointOptions, parameters?: RequestParameters): Promise<OctokitResponse<any>>;
}
export interface GitHubAppAuthInterface {
(options: GitHubAppAuthOptions): Promise<GitHubAppAuthentication | GitHubAppAuthenticationWithExpiration>;
hook(request: RequestInterface, route: Route | EndpointOptions, parameters?: RequestParameters): Promise<OctokitResponse<any>>;
}
export type OAuthAppAuthOptions = {
type: "oauth";
scopes?: string[];
refresh?: boolean;
};
export type GitHubAppAuthOptions = {
type: "oauth";
refresh?: boolean;
};
export type OAuthAppAuthentication = {
type: "token";
tokenType: "oauth";
} & Omit<OAuthMethodsTypes.OAuthAppAuthentication, "clientSecret">;
export type GitHubAppAuthentication = {
type: "token";
tokenType: "oauth";
} & Omit<OAuthMethodsTypes.GitHubAppAuthenticationWithExpirationDisabled, "clientSecret">;
export type GitHubAppAuthenticationWithExpiration = {
type: "token";
tokenType: "oauth";
} & Omit<OAuthMethodsTypes.GitHubAppAuthenticationWithRefreshToken, "clientSecret">;
export type Verification = {
device_code: string;
user_code: string;
verification_uri: string;
expires_in: number;
interval: number;
};
export type OnVerificationCallback = (verification: Verification) => any | Promise<any>;
export type OAuthAppState = {
clientId: string;
clientType: "oauth-app";
onVerification: OnVerificationCallback;
scopes: string[];
request: RequestInterface;
authentication?: OAuthAppAuthentication;
};
export type GitHubAppState = {
clientId: string;
clientType: "github-app";
onVerification: OnVerificationCallback;
request: RequestInterface;
authentication?: GitHubAppAuthentication | GitHubAppAuthenticationWithExpiration;
};

View File

@@ -0,0 +1 @@
export declare const VERSION = "8.0.3";

53
node_modules/@octokit/auth-oauth-device/package.json generated vendored Normal file
View File

@@ -0,0 +1,53 @@
{
"name": "@octokit/auth-oauth-device",
"version": "8.0.3",
"description": "GitHub OAuth Device authentication strategy for JavaScript",
"type": "module",
"repository": "github:octokit/auth-oauth-device.js",
"keywords": [
"github",
"api",
"sdk",
"toolkit"
],
"author": "Gregor Martynus (https://dev.to/gr2m)",
"license": "MIT",
"dependencies": {
"@octokit/oauth-methods": "^6.0.2",
"@octokit/request": "^10.0.6",
"@octokit/types": "^16.0.0",
"universal-user-agent": "^7.0.0"
},
"devDependencies": {
"@octokit/tsconfig": "^4.0.0",
"@types/node": "^24.0.0",
"@vitest/coverage-v8": "^3.0.0",
"esbuild": "^0.25.0",
"fetch-mock": "^12.0.0",
"glob": "^11.0.0",
"prettier": "3.6.2",
"semantic-release-plugin-update-version-in-files": "^2.0.0",
"typescript": "^5.0.0",
"vitest": "^3.0.0"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"engines": {
"node": ">= 20"
},
"files": [
"dist-*/**",
"bin/**"
],
"types": "./dist-types/index.d.ts",
"exports": {
".": {
"types": "./dist-types/index.d.ts",
"import": "./dist-bundle/index.js",
"default": "./dist-bundle/index.js"
}
},
"sideEffects": false
}