exchangeAuthorizationCode method
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,
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,
),
);
}