44namespace 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
0 commit comments