Skip to content

Commit dc12435

Browse files
committed
refactor: split public types into separate files, remove SEP-990 refs from XML docs
1 parent e8b87db commit dc12435

File tree

6 files changed

+200
-200
lines changed

6 files changed

+200
-200
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
namespace ModelContextProtocol.Authentication;
2+
3+
/// <summary>
4+
/// Options for discovering an IDP's token endpoint and requesting a JWT Authorization Grant.
5+
/// Extends <see cref="RequestJwtAuthGrantOptions"/> semantics but replaces <c>TokenEndpoint</c>
6+
/// with <c>IdpUrl</c>/<c>IdpTokenEndpoint</c> for automatic discovery.
7+
/// </summary>
8+
public sealed class DiscoverAndRequestJwtAuthGrantOptions
9+
{
10+
/// <summary>
11+
/// Gets or sets the Identity Provider's base URL for OAuth/OIDC discovery.
12+
/// Used when <see cref="IdpTokenEndpoint"/> is not specified.
13+
/// </summary>
14+
public string? IdpUrl { get; set; }
15+
16+
/// <summary>
17+
/// Gets or sets the IDP token endpoint URL. When provided, skips IDP metadata discovery.
18+
/// </summary>
19+
public string? IdpTokenEndpoint { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the MCP authorization server URL (used as the <c>audience</c> parameter).
23+
/// </summary>
24+
public required string Audience { get; set; }
25+
26+
/// <summary>
27+
/// Gets or sets the MCP resource server URL (used as the <c>resource</c> parameter).
28+
/// </summary>
29+
public required string Resource { get; set; }
30+
31+
/// <summary>
32+
/// Gets or sets the OIDC ID token to exchange.
33+
/// </summary>
34+
public required string IdToken { get; set; }
35+
36+
/// <summary>
37+
/// Gets or sets the client ID for authentication with the IDP.
38+
/// </summary>
39+
public required string ClientId { get; set; }
40+
41+
/// <summary>
42+
/// Gets or sets the client secret for authentication with the IDP. Optional.
43+
/// </summary>
44+
public string? ClientSecret { get; set; }
45+
46+
/// <summary>
47+
/// Gets or sets the scopes to request (space-separated). Optional.
48+
/// </summary>
49+
public string? Scope { get; set; }
50+
51+
/// <summary>
52+
/// Gets or sets the HTTP client for making requests.
53+
/// </summary>
54+
public HttpClient? HttpClient { get; set; }
55+
}

src/ModelContextProtocol.Core/Authentication/EnterpriseAuth.cs

Lines changed: 8 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
namespace ModelContextProtocol.Authentication;
55

66
/// <summary>
7-
/// Provides Enterprise Managed Authorization utilities for the Identity Assertion Authorization Grant flow (SEP-990).
7+
/// Provides Enterprise Managed Authorization utilities for the Identity Assertion Authorization Grant flow.
88
/// </summary>
99
/// <remarks>
1010
/// <para>
11+
/// Implements the Enterprise Managed Authorization flow as specified at
12+
/// <see href="https://github.com/modelcontextprotocol/ext-auth/blob/main/specification/draft/enterprise-managed-authorization.mdx"/>.
13+
/// </para>
14+
/// <para>
1115
/// This class provides standalone functions for:
1216
/// </para>
1317
/// <list type="bullet">
@@ -384,146 +388,6 @@ public static void IfNullOrEmpty(string? value, string message)
384388
#endregion
385389
}
386390

387-
#region Options Types
388-
389-
/// <summary>
390-
/// Options for requesting a JWT Authorization Grant from an Identity Provider via RFC 8693 Token Exchange.
391-
/// </summary>
392-
public sealed class RequestJwtAuthGrantOptions
393-
{
394-
/// <summary>
395-
/// Gets or sets the IDP's token endpoint URL.
396-
/// </summary>
397-
public required string TokenEndpoint { get; set; }
398-
399-
/// <summary>
400-
/// Gets or sets the MCP authorization server URL (used as the <c>audience</c> parameter).
401-
/// </summary>
402-
public required string Audience { get; set; }
403-
404-
/// <summary>
405-
/// Gets or sets the MCP resource server URL (used as the <c>resource</c> parameter).
406-
/// </summary>
407-
public required string Resource { get; set; }
408-
409-
/// <summary>
410-
/// Gets or sets the OIDC ID token to exchange.
411-
/// </summary>
412-
public required string IdToken { get; set; }
413-
414-
/// <summary>
415-
/// Gets or sets the client ID for authentication with the IDP.
416-
/// </summary>
417-
public required string ClientId { get; set; }
418-
419-
/// <summary>
420-
/// Gets or sets the client secret for authentication with the IDP. Optional.
421-
/// </summary>
422-
public string? ClientSecret { get; set; }
423-
424-
/// <summary>
425-
/// Gets or sets the scopes to request (space-separated). Optional.
426-
/// </summary>
427-
public string? Scope { get; set; }
428-
429-
/// <summary>
430-
/// Gets or sets the HTTP client for making requests. If not provided, a default HttpClient will be used.
431-
/// </summary>
432-
public HttpClient? HttpClient { get; set; }
433-
}
434-
435-
/// <summary>
436-
/// Options for discovering an IDP's token endpoint and requesting a JWT Authorization Grant.
437-
/// Extends <see cref="RequestJwtAuthGrantOptions"/> semantics but replaces <c>TokenEndpoint</c>
438-
/// with <c>IdpUrl</c>/<c>IdpTokenEndpoint</c> for automatic discovery.
439-
/// </summary>
440-
public sealed class DiscoverAndRequestJwtAuthGrantOptions
441-
{
442-
/// <summary>
443-
/// Gets or sets the Identity Provider's base URL for OAuth/OIDC discovery.
444-
/// Used when <see cref="IdpTokenEndpoint"/> is not specified.
445-
/// </summary>
446-
public string? IdpUrl { get; set; }
447-
448-
/// <summary>
449-
/// Gets or sets the IDP token endpoint URL. When provided, skips IDP metadata discovery.
450-
/// </summary>
451-
public string? IdpTokenEndpoint { get; set; }
452-
453-
/// <summary>
454-
/// Gets or sets the MCP authorization server URL (used as the <c>audience</c> parameter).
455-
/// </summary>
456-
public required string Audience { get; set; }
457-
458-
/// <summary>
459-
/// Gets or sets the MCP resource server URL (used as the <c>resource</c> parameter).
460-
/// </summary>
461-
public required string Resource { get; set; }
462-
463-
/// <summary>
464-
/// Gets or sets the OIDC ID token to exchange.
465-
/// </summary>
466-
public required string IdToken { get; set; }
467-
468-
/// <summary>
469-
/// Gets or sets the client ID for authentication with the IDP.
470-
/// </summary>
471-
public required string ClientId { get; set; }
472-
473-
/// <summary>
474-
/// Gets or sets the client secret for authentication with the IDP. Optional.
475-
/// </summary>
476-
public string? ClientSecret { get; set; }
477-
478-
/// <summary>
479-
/// Gets or sets the scopes to request (space-separated). Optional.
480-
/// </summary>
481-
public string? Scope { get; set; }
482-
483-
/// <summary>
484-
/// Gets or sets the HTTP client for making requests.
485-
/// </summary>
486-
public HttpClient? HttpClient { get; set; }
487-
}
488-
489-
/// <summary>
490-
/// Options for exchanging a JWT Authorization Grant for an access token via RFC 7523.
491-
/// </summary>
492-
public sealed class ExchangeJwtBearerGrantOptions
493-
{
494-
/// <summary>
495-
/// Gets or sets the MCP Server's authorization server token endpoint URL.
496-
/// </summary>
497-
public required string TokenEndpoint { get; set; }
498-
499-
/// <summary>
500-
/// Gets or sets the JWT Authorization Grant (JAG) assertion obtained from token exchange.
501-
/// </summary>
502-
public required string Assertion { get; set; }
503-
504-
/// <summary>
505-
/// Gets or sets the client ID for authentication with the MCP authorization server.
506-
/// </summary>
507-
public required string ClientId { get; set; }
508-
509-
/// <summary>
510-
/// Gets or sets the client secret for authentication with the MCP authorization server. Optional.
511-
/// </summary>
512-
public string? ClientSecret { get; set; }
513-
514-
/// <summary>
515-
/// Gets or sets the scopes to request (space-separated). Optional.
516-
/// </summary>
517-
public string? Scope { get; set; }
518-
519-
/// <summary>
520-
/// Gets or sets the HTTP client for making requests.
521-
/// </summary>
522-
public HttpClient? HttpClient { get; set; }
523-
}
524-
525-
#endregion
526-
527391
#region Response Types
528392

529393
/// <summary>
@@ -534,20 +398,20 @@ internal sealed class JagTokenExchangeResponse
534398
{
535399
/// <summary>
536400
/// Gets or sets the issued JAG. Despite the name "access_token" (required by RFC 8693),
537-
/// for SEP-990 this contains a JAG JWT, not an OAuth access token.
401+
/// this contains a JAG JWT, not an OAuth access token.
538402
/// </summary>
539403
[System.Text.Json.Serialization.JsonPropertyName("access_token")]
540404
public string AccessToken { get; set; } = null!;
541405

542406
/// <summary>
543407
/// Gets or sets the type of the security token issued.
544-
/// For SEP-990, this MUST be <see cref="EnterpriseAuth.TokenTypeIdJag"/>.
408+
/// This MUST be <see cref="EnterpriseAuth.TokenTypeIdJag"/>.
545409
/// </summary>
546410
[System.Text.Json.Serialization.JsonPropertyName("issued_token_type")]
547411
public string IssuedTokenType { get; set; } = null!;
548412

549413
/// <summary>
550-
/// Gets or sets the token type. For SEP-990, this MUST be "N_A" per RFC 8693 §2.2.1.
414+
/// Gets or sets the token type. This MUST be "N_A" per RFC 8693 §2.2.1.
551415
/// </summary>
552416
[System.Text.Json.Serialization.JsonPropertyName("token_type")]
553417
public string TokenType { get; set; } = null!;
@@ -627,57 +491,3 @@ internal sealed class OAuthErrorResponse
627491
}
628492

629493
#endregion
630-
631-
#region Exception Type
632-
633-
/// <summary>
634-
/// Represents an error that occurred during Enterprise Managed Authorization (SEP-990) operations,
635-
/// including token exchange (RFC 8693) and JWT bearer grant (RFC 7523) failures.
636-
/// </summary>
637-
public sealed class EnterpriseAuthException : Exception
638-
{
639-
/// <summary>
640-
/// Gets the OAuth error code, if available (e.g., "invalid_request", "invalid_grant").
641-
/// </summary>
642-
public string? ErrorCode { get; }
643-
644-
/// <summary>
645-
/// Gets the human-readable error description from the OAuth error response.
646-
/// </summary>
647-
public string? ErrorDescription { get; }
648-
649-
/// <summary>
650-
/// Gets the URI identifying a human-readable web page with error information.
651-
/// </summary>
652-
public string? ErrorUri { get; }
653-
654-
/// <summary>
655-
/// Initializes a new instance of the <see cref="EnterpriseAuthException"/> class.
656-
/// </summary>
657-
/// <param name="message">The error message.</param>
658-
/// <param name="errorCode">The OAuth error code.</param>
659-
/// <param name="errorDescription">The human-readable error description.</param>
660-
/// <param name="errorUri">The error URI.</param>
661-
public EnterpriseAuthException(string message, string? errorCode = null, string? errorDescription = null, string? errorUri = null)
662-
: base(FormatMessage(message, errorCode, errorDescription))
663-
{
664-
ErrorCode = errorCode;
665-
ErrorDescription = errorDescription;
666-
ErrorUri = errorUri;
667-
}
668-
669-
private static string FormatMessage(string message, string? errorCode, string? errorDescription)
670-
{
671-
if (!string.IsNullOrEmpty(errorCode))
672-
{
673-
message = $"{message} Error: {errorCode}";
674-
if (!string.IsNullOrEmpty(errorDescription))
675-
{
676-
message = $"{message} ({errorDescription})";
677-
}
678-
}
679-
return message;
680-
}
681-
}
682-
683-
#endregion
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace ModelContextProtocol.Authentication;
2+
3+
/// <summary>
4+
/// Represents an error that occurred during Enterprise Managed Authorization operations
5+
/// (token exchange per RFC 8693, and JWT bearer grant per RFC 7523).
6+
/// </summary>
7+
public sealed class EnterpriseAuthException : Exception
8+
{
9+
/// <summary>
10+
/// Gets the OAuth error code, if available (e.g., "invalid_request", "invalid_grant").
11+
/// </summary>
12+
public string? ErrorCode { get; }
13+
14+
/// <summary>
15+
/// Gets the human-readable error description from the OAuth error response.
16+
/// </summary>
17+
public string? ErrorDescription { get; }
18+
19+
/// <summary>
20+
/// Gets the URI identifying a human-readable web page with error information.
21+
/// </summary>
22+
public string? ErrorUri { get; }
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="EnterpriseAuthException"/> class.
26+
/// </summary>
27+
/// <param name="message">The error message.</param>
28+
/// <param name="errorCode">The OAuth error code.</param>
29+
/// <param name="errorDescription">The human-readable error description.</param>
30+
/// <param name="errorUri">The error URI.</param>
31+
public EnterpriseAuthException(string message, string? errorCode = null, string? errorDescription = null, string? errorUri = null)
32+
: base(FormatMessage(message, errorCode, errorDescription))
33+
{
34+
ErrorCode = errorCode;
35+
ErrorDescription = errorDescription;
36+
ErrorUri = errorUri;
37+
}
38+
39+
private static string FormatMessage(string message, string? errorCode, string? errorDescription)
40+
{
41+
if (!string.IsNullOrEmpty(errorCode))
42+
{
43+
message = $"{message} Error: {errorCode}";
44+
if (!string.IsNullOrEmpty(errorDescription))
45+
{
46+
message = $"{message} ({errorDescription})";
47+
}
48+
}
49+
return message;
50+
}
51+
}

src/ModelContextProtocol.Core/Authentication/EnterpriseAuthProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace ModelContextProtocol.Authentication;
55

66
/// <summary>
7-
/// Context provided to the assertion callback for Enterprise Managed Authorization (SEP-990).
7+
/// Context provided to the assertion callback for Enterprise Managed Authorization.
88
/// Contains the URLs discovered during the OAuth flow that are needed for the token exchange step.
99
/// </summary>
1010
public sealed class EnterpriseAuthAssertionContext
@@ -23,7 +23,7 @@ public sealed class EnterpriseAuthAssertionContext
2323
}
2424

2525
/// <summary>
26-
/// Provides Enterprise Managed Authorization (SEP-990) as a standalone, non-interactive provider
26+
/// Provides Enterprise Managed Authorization as a standalone, non-interactive provider
2727
/// that can be used alongside the MCP client's OAuth infrastructure.
2828
/// </summary>
2929
/// <remarks>

0 commit comments

Comments
 (0)