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