exchangeAuthorizationCode method

Future<McpOAuthTokenGrant> exchangeAuthorizationCode(
  1. McpAuthorizationCode authorizationCode, {
  2. required McpOAuthClientAuthentication clientAuthentication,
  3. Map<String, String> headers = const <String, String>{},
  4. Duration timeout = const Duration(seconds: 30),
  5. int maxResponseBytes = 64 * 1024,
})

Exchanges an OAuth authorization code for an access-token grant.

Implementation

Future<McpOAuthTokenGrant> exchangeAuthorizationCode(
  McpAuthorizationCode authorizationCode, {
  required McpOAuthClientAuthentication clientAuthentication,
  Map<String, String> headers = const <String, String>{},
  Duration timeout = const Duration(seconds: 30),
  int maxResponseBytes = 64 * 1024,
}) {
  _throwIfClosed();
  if (!_sameMcpOAuthResource(authorizationCode.request.resource, endpoint)) {
    throw McpOAuthTokenException(
      'Authorization code is not valid for this MCP resource.',
      endpoint: endpoint,
    );
  }
  return _runTrackedOAuthHttpOperation(
    (onRequestOpened) => exchangeMcpAuthorizationCode(
      authorizationCode,
      clientAuthentication: clientAuthentication,
      httpClient: _httpClient,
      headers: headers,
      timeout: timeout,
      maxResponseBytes: maxResponseBytes,
      onRequestOpened: onRequestOpened,
    ),
  );
}