Skip to content

Commit 3cc5c7f

Browse files
committed
Allow scopes_supported to be overridden like TS SDK
1 parent dfa29e1 commit 3cc5c7f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/ModelContextProtocol.Core/Authentication/GenericOAuthProvider.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public sealed class GenericOAuthProvider : IMcpCredentialProvider
2323

2424
private readonly Uri _serverUrl;
2525
private readonly Uri _redirectUri;
26-
private readonly List<string> _additionalScopes;
26+
private readonly IList<string>? _scopes;
2727
private readonly string _clientId;
2828
private readonly string? _clientSecret;
2929
private readonly HttpClient _httpClient;
@@ -43,7 +43,7 @@ public sealed class GenericOAuthProvider : IMcpCredentialProvider
4343
/// <param name="clientSecret">OAuth client secret.</param>
4444
/// <param name="redirectUri">OAuth redirect URI.</param>
4545
/// <param name="authorizationRedirectDelegate">Custom handler for processing the OAuth authorization URL. If null, uses the default HTTP listener approach.</param>
46-
/// <param name="additionalScopes">Additional OAuth scopes to request beyond those specified in the scopes_supported specified in the .well-known/oauth-protected-resource response.</param>
46+
/// <param name="scopes">Additional OAuth scopes to request instead of those specified in the scopes_supported specified in the .well-known/oauth-protected-resource response.</param>
4747
/// <param name="loggerFactory">A logger factory to handle diagnostic messages.</param>
4848
/// <param name="authServerSelector">Function to select which authorization server to use from available servers. If null, uses default selection strategy.</param>
4949
/// <exception cref="ArgumentNullException">Thrown when serverUrl is null.</exception>
@@ -54,7 +54,7 @@ public GenericOAuthProvider(
5454
Uri redirectUri,
5555
AuthorizationRedirectDelegate? authorizationRedirectDelegate = null,
5656
string? clientSecret = null,
57-
IEnumerable<string>? additionalScopes = null,
57+
IList<string>? scopes = null,
5858
Func<IReadOnlyList<Uri>, Uri?>? authServerSelector = null,
5959
ILoggerFactory? loggerFactory = null)
6060
{
@@ -63,7 +63,7 @@ public GenericOAuthProvider(
6363
_logger = (ILogger?)loggerFactory?.CreateLogger<GenericOAuthProvider>() ?? NullLogger.Instance;
6464

6565
_redirectUri = redirectUri;
66-
_additionalScopes = additionalScopes?.ToList() ?? [];
66+
_scopes = scopes;
6767
_clientId = clientId;
6868
_clientSecret = clientSecret;
6969

@@ -301,9 +301,9 @@ private Uri BuildAuthorizationUrl(
301301
queryParams["code_challenge_method"] = "S256";
302302

303303
var scopesSupported = protectedResourceMetadata.ScopesSupported;
304-
if (_additionalScopes.Count > 0 || scopesSupported.Count > 0)
304+
if (_scopes?.Count > 0 || scopesSupported.Count > 0)
305305
{
306-
queryParams["scope"] = string.Join(" ", [.._additionalScopes, ..scopesSupported]);
306+
queryParams["scope"] = string.Join(" ", _scopes ?? scopesSupported);
307307
}
308308

309309
var uriBuilder = new UriBuilder(authServerMetadata.AuthorizationEndpoint)

0 commit comments

Comments
 (0)