( authCode: AuthCode, authOptions: LoginOAuthWebOptions, )
| 171 | * @throws If `clientSecret` is absent. |
| 172 | */ |
| 173 | export async function exchangeAuthCodeForAccessToken( |
| 174 | authCode: AuthCode, |
| 175 | authOptions: LoginOAuthWebOptions, |
| 176 | ): Promise<Token> { |
| 177 | if (!authOptions.clientSecret) { |
| 178 | throw new Error('clientSecret is required to exchange an auth code'); |
| 179 | } |
| 180 | |
| 181 | const { authentication } = await exchangeWebFlowCode({ |
| 182 | clientType: 'oauth-app', |
| 183 | clientId: authOptions.clientId, |
| 184 | clientSecret: authOptions.clientSecret, |
| 185 | code: authCode, |
| 186 | request: request.defaults({ |
| 187 | baseUrl: getGitHubAuthBaseUrl(authOptions.hostname) |
| 188 | .toString() |
| 189 | .replace(/\/$/, ''), |
| 190 | }), |
| 191 | }); |
| 192 | |
| 193 | return authentication.token as Token; |
| 194 | } |
no test coverage detected