/*
* 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 Microsoft.IdentityModel.Tokens;
namespace OpenIddict.Server;
public static partial class OpenIddictServerEvents
{
///
/// Represents an event called for each request to the configuration endpoint to give the user code
/// a chance to manually extract the configuration request from the ambient HTTP context.
///
public sealed class ExtractConfigurationRequestContext : BaseValidatingContext
{
///
/// Creates a new instance of the class.
///
public ExtractConfigurationRequestContext(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 configuration endpoint
/// to determine if the request is valid and should continue to be processed.
///
public sealed class ValidateConfigurationRequestContext : BaseValidatingContext
{
///
/// Creates a new instance of the class.
///
public ValidateConfigurationRequestContext(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 configuration request
/// to allow the user code to decide how the request should be handled.
///
public sealed class HandleConfigurationRequestContext : BaseValidatingContext
{
///
/// Creates a new instance of the class.
///
public HandleConfigurationRequestContext(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 Metadata { get; } = new(StringComparer.Ordinal);
///
/// Gets or sets the issuer URI.
///
public Uri? Issuer { get; set; }
///
/// Gets or sets the authorization endpoint URI.
///
public Uri? AuthorizationEndpoint { get; set; }
///
/// Gets or sets the JSON Web Key Set endpoint URI.
///
public Uri? JsonWebKeySetEndpoint { get; set; }
///
/// Gets or sets the device authorization endpoint URI.
///
public Uri? DeviceAuthorizationEndpoint { get; set; }
///
/// Gets or sets the introspection endpoint URI.
///
public Uri? IntrospectionEndpoint { get; set; }
///
/// Gets or sets the end session endpoint URI.
///
public Uri? LogoutEndpoint { get; set; }
///
/// Gets or sets the revocation endpoint URI.
///
public Uri? RevocationEndpoint { get; set; }
///
/// Gets or sets the token endpoint URI.
///
public Uri? TokenEndpoint { get; set; }
///
/// Gets or sets the userinfo endpoint URI.
///
public Uri? UserInfoEndpoint { get; set; }
///
/// Gets the list of claims supported by the authorization server.
///
public HashSet Claims { get; } = new(StringComparer.Ordinal);
///
/// Gets a list of the code challenge methods
/// supported by the authorization server.
///
public HashSet CodeChallengeMethods { get; } = new(StringComparer.Ordinal);
///
/// Gets a list of client authentication methods supported by
/// the device authorization endpoint provided by the authorization server.
///
public HashSet DeviceAuthorizationEndpointAuthenticationMethods { get; } = new(StringComparer.Ordinal);
///
/// Gets the list of grant types
/// supported by the authorization server.
///
public HashSet GrantTypes { get; } = new(StringComparer.Ordinal);
///
/// Gets a list of signing algorithms supported by the
/// authorization server for signing the identity tokens.
///
public HashSet IdTokenSigningAlgorithms { get; } = new(StringComparer.Ordinal);
///
/// Gets a list of client authentication methods supported by
/// the introspection endpoint provided by the authorization server.
///
public HashSet IntrospectionEndpointAuthenticationMethods { get; } = new(StringComparer.Ordinal);
///
/// Gets the list of response modes
/// supported by the authorization server.
///
public HashSet ResponseModes { get; } = new(StringComparer.Ordinal);
///
/// Gets the list of response types
/// supported by the authorization server.
///
public HashSet ResponseTypes { get; } = new(StringComparer.Ordinal);
///
/// Gets a list of client authentication methods supported by
/// the revocation endpoint provided by the authorization server.
///
public HashSet RevocationEndpointAuthenticationMethods { get; } = new(StringComparer.Ordinal);
///
/// Gets the list of scope values
/// supported by the authorization server.
///
public HashSet Scopes { get; } = new(StringComparer.Ordinal);
///
/// Gets the list of subject types
/// supported by the authorization server.
///
public HashSet SubjectTypes { get; } = new(StringComparer.Ordinal);
///
/// Gets a list of client authentication methods supported by
/// the token endpoint provided by the authorization server.
///
public HashSet TokenEndpointAuthenticationMethods { get; } = new(StringComparer.Ordinal);
}
///
/// Represents an event called before the configuration response is returned to the caller.
///
public sealed class ApplyConfigurationResponseContext : BaseRequestContext
{
///
/// Creates a new instance of the class.
///
public ApplyConfigurationResponseContext(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 JSON Web Key Set endpoint to give the user code
/// a chance to manually extract the JSON Web Key Set request from the ambient HTTP context.
///
public sealed class ExtractJsonWebKeySetRequestContext : BaseValidatingContext
{
///
/// Creates a new instance of the class.
///
public ExtractJsonWebKeySetRequestContext(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;
}
///
/// Gets or sets the response.
///
public OpenIddictResponse Response
{
get => Transaction.Response!;
set => Transaction.Response = value;
}
}
///
/// Represents an event called for each request to the JSON Web Key Set endpoint
/// to determine if the request is valid and should continue to be processed.
///
public sealed class ValidateJsonWebKeySetRequestContext : BaseValidatingContext
{
///
/// Creates a new instance of the class.
///
public ValidateJsonWebKeySetRequestContext(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 JSON Web Key Set request
/// to allow the user code to decide how the request should be handled.
///
public sealed class HandleJsonWebKeySetRequestContext : BaseValidatingContext
{
///
/// Creates a new instance of the class.
///
public HandleJsonWebKeySetRequestContext(OpenIddictServerTransaction transaction)
: base(transaction)
{
}
///
/// Gets or sets the request.
///
public OpenIddictRequest Request
{
get => Transaction.Request!;
set => Transaction.Request = value;
}
///
/// Gets the list of JSON Web Keys exposed by the JSON Web Key Set endpoint.
///
public List Keys { get; } = [];
}
///
/// Represents an event called before the JSON Web Key Set response is returned to the caller.
///
public sealed class ApplyJsonWebKeySetResponseContext : BaseRequestContext
{
///
/// Creates a new instance of the class.
///
public ApplyJsonWebKeySetResponseContext(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;
}
}