replaceAuthGrant method
Replaces the router HTTP-auth grant used for subsequent MCP requests.
The grant must contain a valid Bearer access token issued by an auth
endpoint that shares this client's HTTP origin. Streamable HTTP session,
resume, protocol, request, and connection state remain unchanged.
Requests already in flight keep their captured credential, and a delayed
401 or failed initialize for that credential cannot clear the replacement
authorization state's active session. Refresh timing and request retries
stay caller-controlled.
Implementation
void replaceAuthGrant(ConnectanumHttpAuthGrant grant) {
final authorizationHeader = _authorizationHeaderFrom(
_headersWithAuthGrant(
endpoint,
const <String, String>{},
grant,
),
);
final authorizationExpiresAt = grant.accessTokenExpiresAt?.toUtc();
_authorizationHeader = authorizationHeader;
_authorizationExpiresAt = authorizationExpiresAt;
_authorizationStateToken = Object();
}