namespace ModelContextProtocol.Authentication; /// /// Represents an error that occurred during a Cross-Application Access authorization operation /// (token exchange per RFC 8693, and JWT bearer grant per RFC 7523). /// public sealed class IdentityAssertionGrantException : Exception { /// /// Gets the OAuth error code, if available (e.g., "invalid_request", "invalid_grant"). /// public string? ErrorCode { get; } /// /// Gets the human-readable error description from the OAuth error response. /// public string? ErrorDescription { get; } /// /// Gets the URI identifying a human-readable web page with error information. /// public string? ErrorUri { get; } /// /// Initializes a new instance of the class. /// /// The error message. /// The OAuth error code. /// The human-readable error description. /// The error URI. public IdentityAssertionGrantException(string message, string? errorCode = null, string? errorDescription = null, string? errorUri = null) : base(FormatMessage(message, errorCode, errorDescription)) { ErrorCode = errorCode; ErrorDescription = errorDescription; ErrorUri = errorUri; } private static string FormatMessage(string message, string? errorCode, string? errorDescription) { if (!string.IsNullOrEmpty(errorCode)) { message = $"{message} Error: {errorCode}"; if (!string.IsNullOrEmpty(errorDescription)) { message = $"{message} ({errorDescription})"; } } return message; } }