mirror of
https://github.com/github/codeql-action.git
synced 2025-12-27 01:30:10 +08:00
41 lines
990 B
JavaScript
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
|
|
};
|