handleChallenge method

Future<bool> handleChallenge({
  1. required String serverUrl,
  2. required int status,
  3. String? wwwAuthenticate,
})

Answer a 401 or 403 from serverUrl: authorize (or step up) through McpOAuthOptions.authorize. True when there is a new token to retry with; false when this client cannot (no authorize, or step-ups spent).

Implementation

Future<bool> handleChallenge({
  required String serverUrl,
  required int status,
  String? wwwAuthenticate,
}) {
  final resource = canonicalResourceUri(serverUrl);
  // The callback must not return the removed future: whenComplete would
  // then wait on the very future it completes.
  return _running[resource] ??= _handle(serverUrl, status, wwwAuthenticate).whenComplete(() {
    _running.remove(resource);
  });
}