File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed
samples/ProtectedMCPClient
src/ModelContextProtocol/Authentication Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments