Skip to content

Commit 43eb6ff

Browse files
committed
Add record support for unauthorized result
1 parent aad7ad5 commit 43eb6ff

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

samples/ProtectedMCPClient/BasicOAuthAuthorizationProvider.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ public BasicOAuthAuthorizationProvider(
7878
}
7979

8080
/// <inheritdoc />
81-
public async Task<(bool Success, string? RecommendedScheme)> HandleUnauthorizedResponseAsync(
81+
public async Task<McpUnauthorizedResponseResult> HandleUnauthorizedResponseAsync(
8282
HttpResponseMessage response,
8383
string scheme,
8484
CancellationToken cancellationToken = default)
8585
{
8686
// This provider only supports Bearer scheme
8787
if (scheme != "Bearer")
8888
{
89-
return (false, null);
89+
return new McpUnauthorizedResponseResult(false, null);
9090
}
9191

9292
try
@@ -111,17 +111,17 @@ public BasicOAuthAuthorizationProvider(
111111
if (token != null)
112112
{
113113
_token = token;
114-
return (true, "Bearer");
114+
return new McpUnauthorizedResponseResult(true, "Bearer");
115115
}
116116
}
117117
}
118118

119-
return (false, null);
119+
return new McpUnauthorizedResponseResult(false, null);
120120
}
121121
catch (Exception ex)
122122
{
123123
Console.WriteLine($"Error handling auth challenge: {ex.Message}");
124-
return (false, null);
124+
return new McpUnauthorizedResponseResult(false, null);
125125
}
126126
}
127127

src/ModelContextProtocol/Authentication/ITokenProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public interface ITokenProvider
3838
/// <param name="scheme">The authentication scheme that was used when the unauthorized response was received.</param>
3939
/// <param name="cancellationToken">A token to cancel the operation.</param>
4040
/// <returns>
41-
/// A tuple containing a boolean indicating if the provider was able to handle the unauthorized response,
42-
/// and the authentication scheme that should be used for the next attempt.
41+
/// A result object indicating if the provider was able to handle the unauthorized response,
42+
/// and the authentication scheme that should be used for the next attempt, if any.
4343
/// </returns>
44-
Task<(bool Success, string? RecommendedScheme)> HandleUnauthorizedResponseAsync(
44+
Task<McpUnauthorizedResponseResult> HandleUnauthorizedResponseAsync(
4545
HttpResponseMessage response,
4646
string scheme,
4747
CancellationToken cancellationToken = default);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace ModelContextProtocol.Authentication;
2+
3+
/// <summary>
4+
/// Represents the result of handling an unauthorized response from a resource.
5+
/// </summary>
6+
/// <param name="Success">Indicates if the provider was able to handle the unauthorized response.</param>
7+
/// <param name="RecommendedScheme">The authentication scheme that should be used for the next attempt, if any.</param>
8+
public record McpUnauthorizedResponseResult(bool Success, string? RecommendedScheme);

0 commit comments

Comments
 (0)