exchangeCodeForToken method

Future<String> exchangeCodeForToken(
  1. Session session, {
  2. required String code,
  3. required String codeVerifier,
  4. required String redirectUri,
})

Exchanges an authorization code for an access token.

This method exchanges the authorization code received from GitHub's OAuth flow for an access token using PKCE. The code is the authorization code from the callback, and codeVerifier is the PKCE code verifier that was used to generate the code challenge.

The redirectUri must match the redirect URI used in the authorization request.

This method delegates to the generic OAuth2PkceUtil for token exchange, using GitHub-specific configuration.

Throws GitHubAccessTokenVerificationException if the token exchange fails.

Implementation

Future<String> exchangeCodeForToken(
  final Session session, {
  required final String code,
  required final String codeVerifier,
  required final String redirectUri,
}) async {
  try {
    final tokenResponse = await _oauth2Util.exchangeCodeForToken(
      code: code,
      codeVerifier: codeVerifier,
      redirectUri: redirectUri,
    );
    return tokenResponse.accessToken;
  } on OAuth2Exception catch (e) {
    session.log(e.toString(), level: LogLevel.debug);
    throw GitHubAccessTokenVerificationException();
  }
}