Skip to content

Commit f2557ee

Browse files
committed
Update GenericOAuthProvider.cs
1 parent 6601b79 commit f2557ee

1 file changed

Lines changed: 14 additions & 24 deletions

File tree

src/ModelContextProtocol.Core/Authentication/GenericOAuthProvider.cs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ public GenericOAuthProvider(
111111
AuthorizationUrlHandler? authorizationUrlHandler)
112112
: this(serverUrl, httpClient, authorizationHelpers, clientId, clientSecret, redirectUri, scopes, logger, null, authorizationUrlHandler)
113113
{
114-
} /// <summary>
114+
}
115+
116+
/// <summary>
115117
/// Initializes a new instance of the <see cref="GenericOAuthProvider"/> class with explicit authorization server selection.
116118
/// </summary>
117119
/// <param name="serverUrl">The MCP server URL.</param>
@@ -154,11 +156,13 @@ public GenericOAuthProvider(
154156

155157
// Set up authorization URL handler (use default if not provided)
156158
_authorizationUrlHandler = authorizationUrlHandler ?? DefaultAuthorizationUrlHandler;
157-
} /// <summary>
159+
}
160+
161+
/// <summary>
158162
/// Default authorization server selection strategy that selects the first available server.
159163
/// </summary>
160164
/// <param name="availableServers">List of available authorization servers.</param>
161-
/// <returns>The selected authorization server, or null if none are available.</returns>
165+
/// <returns>The selected authorization server, or null if none are available.</returns>
162166
private static Uri? DefaultAuthServerSelector(IReadOnlyList<Uri> availableServers)
163167
{
164168
return availableServers.FirstOrDefault();
@@ -194,7 +198,9 @@ public GenericOAuthProvider(
194198
}
195199

196200
return GetBearerTokenAsync(cancellationToken);
197-
} /// <inheritdoc />
201+
}
202+
203+
/// <inheritdoc />
198204
public async Task<McpUnauthorizedResponseResult> HandleUnauthorizedResponseAsync(
199205
HttpResponseMessage response,
200206
string scheme,
@@ -274,7 +280,9 @@ private async Task<McpUnauthorizedResponseResult> PerformOAuthAuthorizationAsync
274280

275281
_logger.LogError("OAuth authorization flow failed");
276282
return new McpUnauthorizedResponseResult(false, null);
277-
} /// <summary>
283+
}
284+
285+
/// <summary>
278286
/// Selects an authorization server from the available options using the configured selection strategy.
279287
/// </summary>
280288
/// <param name="availableServers">List of available authorization servers.</param>
@@ -446,7 +454,7 @@ private Uri BuildAuthorizationUrl(AuthorizationServerMetadata authServerMetadata
446454
};
447455
return uriBuilder.Uri;
448456
}
449-
private async Task<string?> GetAuthorizationCodeAsync(Uri authorizationUrl, CancellationToken cancellationToken)
457+
private async Task<string?> GetAuthorizationCodeAsync(Uri authorizationUrl, CancellationToken cancellationToken)
450458
{
451459
return await _authorizationUrlHandler(authorizationUrl, _redirectUri, cancellationToken);
452460
}
@@ -506,24 +514,6 @@ private Uri BuildAuthorizationUrl(AuthorizationServerMetadata authServerMetadata
506514
return null;
507515
}
508516

509-
private void OpenBrowser(Uri url)
510-
{
511-
try
512-
{
513-
var psi = new System.Diagnostics.ProcessStartInfo
514-
{
515-
FileName = url.ToString(),
516-
UseShellExecute = true
517-
};
518-
System.Diagnostics.Process.Start(psi);
519-
}
520-
catch (Exception ex)
521-
{
522-
_logger.LogError(ex, "Error opening browser");
523-
_logger.LogInformation("Please manually navigate to: {Url}", url);
524-
}
525-
}
526-
527517
private string GenerateCodeVerifier()
528518
{
529519
var bytes = new byte[32];

0 commit comments

Comments
 (0)