/* * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) * See https://github.com/openiddict/openiddict-core for more information concerning * the license and the contributors participating to this project. */ using System.Security.Claims; namespace OpenIddict.Server; public static partial class OpenIddictServerEvents { /// /// Represents an event called for each request to the token endpoint to give the user code /// a chance to manually extract the token request from the ambient HTTP context. /// public sealed class ExtractTokenRequestContext : BaseValidatingContext { /// /// Creates a new instance of the class. /// public ExtractTokenRequestContext(OpenIddictServerTransaction transaction) : base(transaction) { } /// /// Gets or sets the request, or if it wasn't extracted yet. /// public OpenIddictRequest? Request { get => Transaction.Request; set => Transaction.Request = value; } } /// /// Represents an event called for each request to the token endpoint /// to determine if the request is valid and should continue to be processed. /// public sealed class ValidateTokenRequestContext : BaseValidatingClientContext { /// /// Creates a new instance of the class. /// public ValidateTokenRequestContext(OpenIddictServerTransaction transaction) : base(transaction) { } /// /// Gets or sets the request. /// public OpenIddictRequest Request { get => Transaction.Request!; set => Transaction.Request = value; } /// /// Gets or sets the security principal extracted from the actor token, if applicable. /// public ClaimsPrincipal? ActorTokenPrincipal { get; set; } /// /// Gets or sets the security principal extracted from the authorization code, if applicable. /// public ClaimsPrincipal? AuthorizationCodePrincipal { get; set; } /// /// Gets or sets the security principal extracted from the device code, if applicable. /// public ClaimsPrincipal? DeviceCodePrincipal { get; set; } /// /// Gets or sets the security principal extracted from the refresh token, if applicable. /// public ClaimsPrincipal? RefreshTokenPrincipal { get; set; } /// /// Gets or sets the security principal extracted from the subject token, if applicable. /// public ClaimsPrincipal? SubjectTokenPrincipal { get; set; } } /// /// Represents an event called for each validated token request /// to allow the user code to decide how the request should be handled. /// public sealed class HandleTokenRequestContext : BaseValidatingTicketContext { /// /// Creates a new instance of the class. /// public HandleTokenRequestContext(OpenIddictServerTransaction transaction) : base(transaction) { } /// /// Gets or sets the request. /// public OpenIddictRequest Request { get => Transaction.Request!; set => Transaction.Request = value; } /// /// Gets or sets the security principal extracted from the actor token, if applicable. /// public ClaimsPrincipal? ActorTokenPrincipal { get; set; } /// /// Gets or sets the security principal extracted from the authorization code, if applicable. /// public ClaimsPrincipal? AuthorizationCodePrincipal { get; set; } /// /// Gets or sets the security principal extracted from the device code, if applicable. /// public ClaimsPrincipal? DeviceCodePrincipal { get; set; } /// /// Gets or sets the security principal extracted from the refresh token, if applicable. /// public ClaimsPrincipal? RefreshTokenPrincipal { get; set; } /// /// Gets or sets the security principal extracted from the subject token, if applicable. /// public ClaimsPrincipal? SubjectTokenPrincipal { get; set; } /// /// Gets the additional parameters returned to the client application. /// public Dictionary Parameters { get; private set; } = new(StringComparer.Ordinal); /// /// Allows OpenIddict to return a sign-in response using the specified principal. /// /// The claims principal. public void SignIn(ClaimsPrincipal principal) => Principal = principal; /// /// Allows OpenIddict to return a sign-in response using the specified principal. /// /// The claims principal. /// The additional parameters returned to the client application. public void SignIn(ClaimsPrincipal principal, IDictionary parameters) { Principal = principal; Parameters = new(parameters, StringComparer.Ordinal); } } /// /// Represents an event called before the token response is returned to the caller. /// public sealed class ApplyTokenResponseContext : BaseRequestContext { /// /// Creates a new instance of the class. /// public ApplyTokenResponseContext(OpenIddictServerTransaction transaction) : base(transaction) { } /// /// Gets or sets the request, or if it couldn't be extracted. /// public OpenIddictRequest? Request { get => Transaction.Request; set => Transaction.Request = value; } /// /// Gets or sets the response. /// public OpenIddictResponse Response { get => Transaction.Response!; set => Transaction.Response = value; } /// /// Gets the error code returned to the client application. /// When the response indicates a successful response, /// this property returns . /// public string? Error => Response.Error; } }