First upload version 0.0.1
This commit is contained in:
138
node_modules/@octokit/auth-oauth-device/dist-bundle/index.js
generated
vendored
Normal file
138
node_modules/@octokit/auth-oauth-device/dist-bundle/index.js
generated
vendored
Normal 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
|
||||
};
|
||||
7
node_modules/@octokit/auth-oauth-device/dist-bundle/index.js.map
generated
vendored
Normal file
7
node_modules/@octokit/auth-oauth-device/dist-bundle/index.js.map
generated
vendored
Normal 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\";\nexport {\n VERSION\n};\n"],
|
||||
"mappings": ";AAAA,SAAS,oBAAoB;AAC7B,SAAS,WAAW,sBAAsB;;;ACD1C,SAAS,kBAAkB,0BAA0B;AACrD,eAAe,oBAAoB,OAAO,SAAS;AACjD,QAAM,uBAAuB,wBAAwB,OAAO,QAAQ,IAAI;AACxE,MAAI,qBAAsB,QAAO;AACjC,QAAM,EAAE,MAAM,aAAa,IAAI,MAAM,iBAAiB;AAAA,IACpD,YAAY,MAAM;AAAA,IAClB,UAAU,MAAM;AAAA,IAChB,SAAS,QAAQ,WAAW,MAAM;AAAA;AAAA,IAElC,QAAQ,QAAQ,KAAK,UAAU,MAAM;AAAA,EACvC,CAAC;AACD,QAAM,MAAM,eAAe,YAAY;AACvC,QAAM,iBAAiB,MAAM;AAAA,IAC3B,QAAQ,WAAW,MAAM;AAAA,IACzB,MAAM;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACF;AACA,QAAM,iBAAiB;AACvB,SAAO;AACT;AACA,SAAS,wBAAwB,OAAOA,OAAM;AAC5C,MAAIA,MAAK,YAAY,KAAM,QAAO;AAClC,MAAI,CAAC,MAAM,eAAgB,QAAO;AAClC,MAAI,MAAM,eAAe,cAAc;AACrC,WAAO,MAAM;AAAA,EACf;AACA,QAAM,iBAAiB,MAAM;AAC7B,QAAM,YAAY,YAAYA,SAAQA,MAAK,UAAU,MAAM,QA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