/* * 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 device authorization endpoint to give the /// user code a chance to manually extract the device request from the ambient HTTP context. /// public sealed class ExtractDeviceAuthorizationRequestContext : BaseValidatingContext { /// /// Creates a new instance of the class. /// public ExtractDeviceAuthorizationRequestContext(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 device authorization endpoint /// to determine if the request is valid and should continue to be processed. /// public sealed class ValidateDeviceAuthorizationRequestContext : BaseValidatingClientContext { /// /// Creates a new instance of the class. /// public ValidateDeviceAuthorizationRequestContext(OpenIddictServerTransaction transaction) : base(transaction) { } /// /// Gets or sets the request. /// public OpenIddictRequest Request { get => Transaction.Request!; set => Transaction.Request = value; } } /// /// Represents an event called for each validated device authorization request /// to allow the user code to decide how the request should be handled. /// public sealed class HandleDeviceAuthorizationRequestContext : BaseValidatingTicketContext { /// /// Creates a new instance of the class. /// public HandleDeviceAuthorizationRequestContext(OpenIddictServerTransaction transaction) : base(transaction) { } /// /// Gets or sets the request. /// public OpenIddictRequest Request { get => Transaction.Request!; set => Transaction.Request = value; } /// /// 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 device authorization response is returned to the caller. /// public sealed class ApplyDeviceAuthorizationResponseContext : BaseRequestContext { /// /// Creates a new instance of the class. /// public ApplyDeviceAuthorizationResponseContext(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; } /// /// Represents an event called for each request to the end-user verification endpoint to give the user code /// a chance to manually extract the end-user verification request from the ambient HTTP context. /// public sealed class ExtractEndUserVerificationRequestContext : BaseValidatingContext { /// /// Creates a new instance of the class. /// public ExtractEndUserVerificationRequestContext(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 end-user verification endpoint /// to determine if the request is valid and should continue to be processed. /// public sealed class ValidateEndUserVerificationRequestContext : BaseValidatingClientContext { /// /// Creates a new instance of the class. /// public ValidateEndUserVerificationRequestContext(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 user code, if applicable. /// public ClaimsPrincipal? UserCodePrincipal { get; set; } } /// /// Represents an event called for each validated end-user verification request /// to allow the user code to decide how the request should be handled. /// public sealed class HandleEndUserVerificationRequestContext : BaseValidatingTicketContext { /// /// Creates a new instance of the class. /// public HandleEndUserVerificationRequestContext(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 user code, if applicable. /// public ClaimsPrincipal? UserCodePrincipal { get; set; } /// /// Gets the additional parameters returned to the caller. /// /// /// Note: by default, this property is not used as empty responses are typically /// returned for end-user verification requests. To return a different response, a /// custom event handler must be registered to handle end-user verification responses. /// 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 end-user verification response is returned to the caller. /// public sealed class ApplyEndUserVerificationResponseContext : BaseRequestContext { /// /// Creates a new instance of the class. /// public ApplyEndUserVerificationResponseContext(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; } }