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