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

41 lines
990 B
JavaScript

import { createOAuthUserAuth } from "@octokit/auth-oauth-user";
async function auth(state, authOptions) {
if (authOptions.type === "oauth-app") {
return {
type: "oauth-app",
clientId: state.clientId,
clientSecret: state.clientSecret,
clientType: state.clientType,
headers: {
authorization: `basic ${btoa(
`${state.clientId}:${state.clientSecret}`
)}`
}
};
}
if ("factory" in authOptions) {
const { type, ...options } = {
...authOptions,
...state
};
return authOptions.factory(options);
}
const common = {
clientId: state.clientId,
clientSecret: state.clientSecret,
request: state.request,
...authOptions
};
const userAuth = state.clientType === "oauth-app" ? await createOAuthUserAuth({
...common,
clientType: state.clientType
}) : await createOAuthUserAuth({
...common,
clientType: state.clientType
});
return userAuth();
}
export {
auth
};