Files
codeql-action/node_modules/@octokit/auth-oauth-app/dist-src/hook.js
2025-02-19 11:13:12 -08:00

28 lines
1.0 KiB
JavaScript

import { requiresBasicAuth } from "@octokit/auth-oauth-user";
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);
}
if (state.clientType === "github-app" && !requiresBasicAuth(endpoint.url)) {
throw new Error(
`[@octokit/auth-oauth-app] GitHub Apps cannot use their client ID/secret for basic authentication for endpoints other than "/applications/{client_id}/**". "${endpoint.method} ${endpoint.url}" is not supported.`
);
}
const credentials = btoa(`${state.clientId}:${state.clientSecret}`);
endpoint.headers.authorization = `basic ${credentials}`;
try {
return await request(endpoint);
} catch (error) {
if (error.status !== 401) throw error;
error.message = `[@octokit/auth-oauth-app] "${endpoint.method} ${endpoint.url}" does not support clientId/clientSecret basic authentication.`;
throw error;
}
}
export {
hook
};