committed by
GitHub
25 changed files with 1639 additions and 108 deletions
@ -0,0 +1,97 @@ |
|||||
|
/* |
||||
|
* 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; |
||||
|
using System.Collections.Immutable; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Microsoft.AspNetCore; |
||||
|
using static OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlerFilters; |
||||
|
using static OpenIddict.Server.OpenIddictServerEvents; |
||||
|
|
||||
|
namespace OpenIddict.Server.AspNetCore |
||||
|
{ |
||||
|
public static partial class OpenIddictServerAspNetCoreHandlers |
||||
|
{ |
||||
|
public static class Introspection |
||||
|
{ |
||||
|
public static ImmutableArray<OpenIddictServerHandlerDescriptor> DefaultHandlers { get; } = ImmutableArray.Create( |
||||
|
/* |
||||
|
* Introspection request extraction: |
||||
|
*/ |
||||
|
ExtractGetOrPostRequest<ExtractIntrospectionRequestContext>.Descriptor, |
||||
|
|
||||
|
/* |
||||
|
* Introspection request handling: |
||||
|
*/ |
||||
|
InferIssuerFromHost.Descriptor, |
||||
|
|
||||
|
/* |
||||
|
* Introspection response processing: |
||||
|
*/ |
||||
|
ProcessJsonResponse<ApplyIntrospectionResponseContext>.Descriptor); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Contains the logic responsible of infering the issuer URL from the HTTP request host.
|
||||
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by ASP.NET Core.
|
||||
|
/// </summary>
|
||||
|
public class InferIssuerFromHost : IOpenIddictServerHandler<HandleIntrospectionRequestContext> |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the default descriptor definition assigned to this handler.
|
||||
|
/// </summary>
|
||||
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
||||
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<HandleIntrospectionRequestContext>() |
||||
|
.AddFilter<RequireHttpRequest>() |
||||
|
.UseSingletonHandler<InferIssuerFromHost>() |
||||
|
.SetOrder(OpenIddictServerHandlers.Introspection.AttachMetadataClaims.Descriptor.Order + 1_000) |
||||
|
.Build(); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Processes the event.
|
||||
|
/// </summary>
|
||||
|
/// <param name="context">The context associated with the event to process.</param>
|
||||
|
/// <returns>
|
||||
|
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
|
||||
|
/// </returns>
|
||||
|
public ValueTask HandleAsync([NotNull] HandleIntrospectionRequestContext context) |
||||
|
{ |
||||
|
if (context == null) |
||||
|
{ |
||||
|
throw new ArgumentNullException(nameof(context)); |
||||
|
} |
||||
|
|
||||
|
// This handler only applies to ASP.NET Core requests. If the HTTP context cannot be resolved,
|
||||
|
// this may indicate that the request was incorrectly processed by another server stack.
|
||||
|
var request = context.Transaction.GetHttpRequest(); |
||||
|
if (request == null) |
||||
|
{ |
||||
|
throw new InvalidOperationException("The ASP.NET Core HTTP request cannot be resolved."); |
||||
|
} |
||||
|
|
||||
|
// If the issuer was not populated by another handler (e.g from the server options),
|
||||
|
// try to infer it from the request scheme/host/path base (which requires HTTP/1.1).
|
||||
|
if (context.Issuer == null) |
||||
|
{ |
||||
|
if (!request.Host.HasValue) |
||||
|
{ |
||||
|
throw new InvalidOperationException("No host was attached to the HTTP request."); |
||||
|
} |
||||
|
|
||||
|
if (!Uri.TryCreate(request.Scheme + "://" + request.Host + request.PathBase, UriKind.Absolute, out Uri issuer)) |
||||
|
{ |
||||
|
throw new InvalidOperationException("The issuer address cannot be inferred from the current request."); |
||||
|
} |
||||
|
|
||||
|
context.Issuer = issuer.AbsoluteUri; |
||||
|
} |
||||
|
|
||||
|
return default; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
/* |
||||
|
* 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. |
||||
|
*/ |
||||
|
|
||||
|
namespace OpenIddict.Server.DataProtection |
||||
|
{ |
||||
|
public static class OpenIddictServerDataProtectionConstants |
||||
|
{ |
||||
|
public static class Properties |
||||
|
{ |
||||
|
public const string AccessTokenLifetime = ".access_token_lifetime"; |
||||
|
public const string AuthorizationCodeLifetime = ".authorization_code_lifetime"; |
||||
|
public const string Audiences = ".audiences"; |
||||
|
public const string CodeChallenge = ".code_challenge"; |
||||
|
public const string CodeChallengeMethod = ".code_challenge_method"; |
||||
|
public const string DataProtector = ".data_protector"; |
||||
|
public const string Expires = ".expires"; |
||||
|
public const string IdentityTokenLifetime = ".identity_token_lifetime"; |
||||
|
public const string Issued = ".issued"; |
||||
|
public const string Nonce = ".nonce"; |
||||
|
public const string OriginalRedirectUri = ".original_redirect_uri"; |
||||
|
public const string Presenters = ".presenters"; |
||||
|
public const string RefreshTokenLifetime = ".refresh_token_lifetime"; |
||||
|
public const string Resources = ".resources"; |
||||
|
public const string Scopes = ".scopes"; |
||||
|
public const string TokenId = ".token_id"; |
||||
|
public const string TokenUsage = ".token_usage"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,97 @@ |
|||||
|
/* |
||||
|
* 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; |
||||
|
using System.Collections.Immutable; |
||||
|
using System.Threading.Tasks; |
||||
|
using JetBrains.Annotations; |
||||
|
using Owin; |
||||
|
using static OpenIddict.Server.OpenIddictServerEvents; |
||||
|
using static OpenIddict.Server.Owin.OpenIddictServerOwinHandlerFilters; |
||||
|
|
||||
|
namespace OpenIddict.Server.Owin |
||||
|
{ |
||||
|
public static partial class OpenIddictServerOwinHandlers |
||||
|
{ |
||||
|
public static class Introspection |
||||
|
{ |
||||
|
public static ImmutableArray<OpenIddictServerHandlerDescriptor> DefaultHandlers { get; } = ImmutableArray.Create( |
||||
|
/* |
||||
|
* Introspection request extraction: |
||||
|
*/ |
||||
|
ExtractGetOrPostRequest<ExtractIntrospectionRequestContext>.Descriptor, |
||||
|
|
||||
|
/* |
||||
|
* Introspection request handling: |
||||
|
*/ |
||||
|
InferIssuerFromHost.Descriptor, |
||||
|
|
||||
|
/* |
||||
|
* Introspection response processing: |
||||
|
*/ |
||||
|
ProcessJsonResponse<ApplyIntrospectionResponseContext>.Descriptor); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Contains the logic responsible of infering the issuer URL from the HTTP request host.
|
||||
|
/// Note: this handler is not used when the OpenID Connect request is not initially handled by OWIN.
|
||||
|
/// </summary>
|
||||
|
public class InferIssuerFromHost : IOpenIddictServerHandler<HandleIntrospectionRequestContext> |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Gets the default descriptor definition assigned to this handler.
|
||||
|
/// </summary>
|
||||
|
public static OpenIddictServerHandlerDescriptor Descriptor { get; } |
||||
|
= OpenIddictServerHandlerDescriptor.CreateBuilder<HandleIntrospectionRequestContext>() |
||||
|
.AddFilter<RequireOwinRequest>() |
||||
|
.UseSingletonHandler<InferIssuerFromHost>() |
||||
|
.SetOrder(OpenIddictServerHandlers.Introspection.AttachMetadataClaims.Descriptor.Order + 1_000) |
||||
|
.Build(); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Processes the event.
|
||||
|
/// </summary>
|
||||
|
/// <param name="context">The context associated with the event to process.</param>
|
||||
|
/// <returns>
|
||||
|
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
|
||||
|
/// </returns>
|
||||
|
public ValueTask HandleAsync([NotNull] HandleIntrospectionRequestContext context) |
||||
|
{ |
||||
|
if (context == null) |
||||
|
{ |
||||
|
throw new ArgumentNullException(nameof(context)); |
||||
|
} |
||||
|
|
||||
|
// This handler only applies to OWIN requests. If The OWIN request cannot be resolved,
|
||||
|
// this may indicate that the request was incorrectly processed by another server stack.
|
||||
|
var request = context.Transaction.GetOwinRequest(); |
||||
|
if (request == null) |
||||
|
{ |
||||
|
throw new InvalidOperationException("The OWIN request cannot be resolved."); |
||||
|
} |
||||
|
|
||||
|
// If the issuer was not populated by another handler (e.g from the server options),
|
||||
|
// try to infer it from the request scheme/host/path base (which requires HTTP/1.1).
|
||||
|
if (context.Issuer == null) |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(request.Host.Value)) |
||||
|
{ |
||||
|
throw new InvalidOperationException("No host was attached to the HTTP request."); |
||||
|
} |
||||
|
|
||||
|
if (!Uri.TryCreate(request.Scheme + "://" + request.Host + request.PathBase, UriKind.Absolute, out Uri issuer)) |
||||
|
{ |
||||
|
throw new InvalidOperationException("The issuer address cannot be inferred from the current request."); |
||||
|
} |
||||
|
|
||||
|
context.Issuer = issuer.AbsoluteUri; |
||||
|
} |
||||
|
|
||||
|
return default; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
/* |
||||
|
* 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. |
||||
|
*/ |
||||
|
|
||||
|
namespace OpenIddict.Server |
||||
|
{ |
||||
|
public static class OpenIddictServerConstants |
||||
|
{ |
||||
|
public static class Properties |
||||
|
{ |
||||
|
public const string Principal = ".principal"; |
||||
|
public const string ValidatedPostLogoutRedirectUri = ".validated_post_logout_redirect_uri"; |
||||
|
public const string ValidatedRedirectUri = ".validated_redirect_uri"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
File diff suppressed because it is too large
Loading…
Reference in new issue