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

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
};