First upload version 0.0.1
This commit is contained in:
98
node_modules/@octokit/auth-oauth-user/dist-src/auth.js
generated
vendored
Normal file
98
node_modules/@octokit/auth-oauth-user/dist-src/auth.js
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
import { getAuthentication } from "./get-authentication.js";
|
||||
import {
|
||||
checkToken,
|
||||
deleteAuthorization,
|
||||
deleteToken,
|
||||
refreshToken,
|
||||
resetToken
|
||||
} from "@octokit/oauth-methods";
|
||||
async function auth(state, options = {}) {
|
||||
if (!state.authentication) {
|
||||
state.authentication = state.clientType === "oauth-app" ? await getAuthentication(state) : await getAuthentication(state);
|
||||
}
|
||||
if (state.authentication.invalid) {
|
||||
throw new Error("[@octokit/auth-oauth-user] Token is invalid");
|
||||
}
|
||||
const currentAuthentication = state.authentication;
|
||||
if ("expiresAt" in currentAuthentication) {
|
||||
if (options.type === "refresh" || new Date(currentAuthentication.expiresAt) < /* @__PURE__ */ new Date()) {
|
||||
const { authentication } = await refreshToken({
|
||||
clientType: "github-app",
|
||||
clientId: state.clientId,
|
||||
clientSecret: state.clientSecret,
|
||||
refreshToken: currentAuthentication.refreshToken,
|
||||
request: state.request
|
||||
});
|
||||
state.authentication = {
|
||||
tokenType: "oauth",
|
||||
type: "token",
|
||||
...authentication
|
||||
};
|
||||
}
|
||||
}
|
||||
if (options.type === "refresh") {
|
||||
if (state.clientType === "oauth-app") {
|
||||
throw new Error(
|
||||
"[@octokit/auth-oauth-user] OAuth Apps do not support expiring tokens"
|
||||
);
|
||||
}
|
||||
if (!currentAuthentication.hasOwnProperty("expiresAt")) {
|
||||
throw new Error("[@octokit/auth-oauth-user] Refresh token missing");
|
||||
}
|
||||
await state.onTokenCreated?.(state.authentication, {
|
||||
type: options.type
|
||||
});
|
||||
}
|
||||
if (options.type === "check" || options.type === "reset") {
|
||||
const method = options.type === "check" ? checkToken : resetToken;
|
||||
try {
|
||||
const { authentication } = await method({
|
||||
// @ts-expect-error making TS happy would require unnecessary code so no
|
||||
clientType: state.clientType,
|
||||
clientId: state.clientId,
|
||||
clientSecret: state.clientSecret,
|
||||
token: state.authentication.token,
|
||||
request: state.request
|
||||
});
|
||||
state.authentication = {
|
||||
tokenType: "oauth",
|
||||
type: "token",
|
||||
// @ts-expect-error TBD
|
||||
...authentication
|
||||
};
|
||||
if (options.type === "reset") {
|
||||
await state.onTokenCreated?.(state.authentication, {
|
||||
type: options.type
|
||||
});
|
||||
}
|
||||
return state.authentication;
|
||||
} catch (error) {
|
||||
if (error.status === 404) {
|
||||
error.message = "[@octokit/auth-oauth-user] Token is invalid";
|
||||
state.authentication.invalid = true;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
if (options.type === "delete" || options.type === "deleteAuthorization") {
|
||||
const method = options.type === "delete" ? deleteToken : deleteAuthorization;
|
||||
try {
|
||||
await method({
|
||||
// @ts-expect-error making TS happy would require unnecessary code so no
|
||||
clientType: state.clientType,
|
||||
clientId: state.clientId,
|
||||
clientSecret: state.clientSecret,
|
||||
token: state.authentication.token,
|
||||
request: state.request
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.status !== 404) throw error;
|
||||
}
|
||||
state.authentication.invalid = true;
|
||||
return state.authentication;
|
||||
}
|
||||
return state.authentication;
|
||||
}
|
||||
export {
|
||||
auth
|
||||
};
|
||||
50
node_modules/@octokit/auth-oauth-user/dist-src/get-authentication.js
generated
vendored
Normal file
50
node_modules/@octokit/auth-oauth-user/dist-src/get-authentication.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import { createOAuthDeviceAuth } from "@octokit/auth-oauth-device";
|
||||
import { exchangeWebFlowCode } from "@octokit/oauth-methods";
|
||||
async function getAuthentication(state) {
|
||||
if ("code" in state.strategyOptions) {
|
||||
const { authentication } = await exchangeWebFlowCode({
|
||||
clientId: state.clientId,
|
||||
clientSecret: state.clientSecret,
|
||||
clientType: state.clientType,
|
||||
onTokenCreated: state.onTokenCreated,
|
||||
...state.strategyOptions,
|
||||
request: state.request
|
||||
});
|
||||
return {
|
||||
type: "token",
|
||||
tokenType: "oauth",
|
||||
...authentication
|
||||
};
|
||||
}
|
||||
if ("onVerification" in state.strategyOptions) {
|
||||
const deviceAuth = createOAuthDeviceAuth({
|
||||
clientType: state.clientType,
|
||||
clientId: state.clientId,
|
||||
onTokenCreated: state.onTokenCreated,
|
||||
...state.strategyOptions,
|
||||
request: state.request
|
||||
});
|
||||
const authentication = await deviceAuth({
|
||||
type: "oauth"
|
||||
});
|
||||
return {
|
||||
clientSecret: state.clientSecret,
|
||||
...authentication
|
||||
};
|
||||
}
|
||||
if ("token" in state.strategyOptions) {
|
||||
return {
|
||||
type: "token",
|
||||
tokenType: "oauth",
|
||||
clientId: state.clientId,
|
||||
clientSecret: state.clientSecret,
|
||||
clientType: state.clientType,
|
||||
onTokenCreated: state.onTokenCreated,
|
||||
...state.strategyOptions
|
||||
};
|
||||
}
|
||||
throw new Error("[@octokit/auth-oauth-user] Invalid strategy options");
|
||||
}
|
||||
export {
|
||||
getAuthentication
|
||||
};
|
||||
22
node_modules/@octokit/auth-oauth-user/dist-src/hook.js
generated
vendored
Normal file
22
node_modules/@octokit/auth-oauth-user/dist-src/hook.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { auth } from "./auth.js";
|
||||
import { requiresBasicAuth } from "./requires-basic-auth.js";
|
||||
async function hook(state, request, route, parameters = {}) {
|
||||
const endpoint = request.endpoint.merge(
|
||||
route,
|
||||
parameters
|
||||
);
|
||||
if (/\/login\/(oauth\/access_token|device\/code)$/.test(endpoint.url)) {
|
||||
return request(endpoint);
|
||||
}
|
||||
if (requiresBasicAuth(endpoint.url)) {
|
||||
const credentials = btoa(`${state.clientId}:${state.clientSecret}`);
|
||||
endpoint.headers.authorization = `basic ${credentials}`;
|
||||
return request(endpoint);
|
||||
}
|
||||
const { token } = state.clientType === "oauth-app" ? await auth({ ...state, request }) : await auth({ ...state, request });
|
||||
endpoint.headers.authorization = "token " + token;
|
||||
return request(endpoint);
|
||||
}
|
||||
export {
|
||||
hook
|
||||
};
|
||||
36
node_modules/@octokit/auth-oauth-user/dist-src/index.js
generated
vendored
Normal file
36
node_modules/@octokit/auth-oauth-user/dist-src/index.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import { getUserAgent } from "universal-user-agent";
|
||||
import { request as octokitRequest } from "@octokit/request";
|
||||
import { VERSION } from "./version.js";
|
||||
import { auth } from "./auth.js";
|
||||
import { hook } from "./hook.js";
|
||||
import { requiresBasicAuth } from "./requires-basic-auth.js";
|
||||
function createOAuthUserAuth({
|
||||
clientId,
|
||||
clientSecret,
|
||||
clientType = "oauth-app",
|
||||
request = octokitRequest.defaults({
|
||||
headers: {
|
||||
"user-agent": `octokit-auth-oauth-app.js/${VERSION} ${getUserAgent()}`
|
||||
}
|
||||
}),
|
||||
onTokenCreated,
|
||||
...strategyOptions
|
||||
}) {
|
||||
const state = Object.assign({
|
||||
clientType,
|
||||
clientId,
|
||||
clientSecret,
|
||||
onTokenCreated,
|
||||
strategyOptions,
|
||||
request
|
||||
});
|
||||
return Object.assign(auth.bind(null, state), {
|
||||
// @ts-expect-error not worth the extra code needed to appease TS
|
||||
hook: hook.bind(null, state)
|
||||
});
|
||||
}
|
||||
createOAuthUserAuth.VERSION = VERSION;
|
||||
export {
|
||||
createOAuthUserAuth,
|
||||
requiresBasicAuth
|
||||
};
|
||||
7
node_modules/@octokit/auth-oauth-user/dist-src/requires-basic-auth.js
generated
vendored
Normal file
7
node_modules/@octokit/auth-oauth-user/dist-src/requires-basic-auth.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
const ROUTES_REQUIRING_BASIC_AUTH = /\/applications\/[^/]+\/(token|grant)s?/;
|
||||
function requiresBasicAuth(url) {
|
||||
return url && ROUTES_REQUIRING_BASIC_AUTH.test(url);
|
||||
}
|
||||
export {
|
||||
requiresBasicAuth
|
||||
};
|
||||
4
node_modules/@octokit/auth-oauth-user/dist-src/version.js
generated
vendored
Normal file
4
node_modules/@octokit/auth-oauth-user/dist-src/version.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
const VERSION = "6.0.2";
|
||||
export {
|
||||
VERSION
|
||||
};
|
||||
Reference in New Issue
Block a user