Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port the authentication integration tests #876

Merged
merged 1 commit into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public async Task SignInAsync([NotNull] ClaimsPrincipal user, [CanBeNull] Authen

transaction.Properties[typeof(AuthenticationProperties).FullName] = properties ?? new AuthenticationProperties();

var context = new ProcessSigninContext(transaction)
var context = new ProcessSignInContext(transaction)
{
Principal = user,
Response = new OpenIddictResponse()
Expand Down Expand Up @@ -261,7 +261,7 @@ public async Task SignOutAsync([CanBeNull] AuthenticationProperties properties)
throw new InvalidOperationException("An OpenID Connect response cannot be returned from this endpoint.");
}

var context = new ProcessSignoutContext(transaction)
var context = new ProcessSignOutContext(transaction)
{
Response = new OpenIddictResponse()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ TokenUsages.UserCode when !context.Options.DisableTokenStorage
/// <summary>
/// Contains the logic responsible of generating an access token using Data Protection.
/// </summary>
public class GenerateDataProtectionAccessToken : IOpenIddictServerHandler<ProcessSigninContext>
public class GenerateDataProtectionAccessToken : IOpenIddictServerHandler<ProcessSignInContext>
{
private readonly IOptionsMonitor<OpenIddictServerDataProtectionOptions> _options;

Expand All @@ -166,7 +166,7 @@ public GenerateDataProtectionAccessToken([NotNull] IOptionsMonitor<OpenIddictSer
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSigninContext>()
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.AddFilter<RequireAccessTokenIncluded>()
.AddFilter<RequirePreferDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionAccessToken>()
Expand All @@ -180,7 +180,7 @@ public GenerateDataProtectionAccessToken([NotNull] IOptionsMonitor<OpenIddictSer
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
public ValueTask HandleAsync([NotNull] ProcessSigninContext context)
public ValueTask HandleAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down Expand Up @@ -219,7 +219,7 @@ public ValueTask HandleAsync([NotNull] ProcessSigninContext context)
/// <summary>
/// Contains the logic responsible of generating an authorization code using Data Protection.
/// </summary>
public class GenerateDataProtectionAuthorizationCode : IOpenIddictServerHandler<ProcessSigninContext>
public class GenerateDataProtectionAuthorizationCode : IOpenIddictServerHandler<ProcessSignInContext>
{
private readonly IOptionsMonitor<OpenIddictServerDataProtectionOptions> _options;

Expand All @@ -230,7 +230,7 @@ public GenerateDataProtectionAuthorizationCode([NotNull] IOptionsMonitor<OpenIdd
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSigninContext>()
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.AddFilter<RequireAuthorizationCodeIncluded>()
.AddFilter<RequirePreferDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionAuthorizationCode>()
Expand All @@ -244,7 +244,7 @@ public GenerateDataProtectionAuthorizationCode([NotNull] IOptionsMonitor<OpenIdd
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
public ValueTask HandleAsync([NotNull] ProcessSigninContext context)
public ValueTask HandleAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down Expand Up @@ -283,7 +283,7 @@ public ValueTask HandleAsync([NotNull] ProcessSigninContext context)
/// <summary>
/// Contains the logic responsible of generating a device code using Data Protection.
/// </summary>
public class GenerateDataProtectionDeviceCode : IOpenIddictServerHandler<ProcessSigninContext>
public class GenerateDataProtectionDeviceCode : IOpenIddictServerHandler<ProcessSignInContext>
{
private readonly IOptionsMonitor<OpenIddictServerDataProtectionOptions> _options;

Expand All @@ -294,7 +294,7 @@ public GenerateDataProtectionDeviceCode([NotNull] IOptionsMonitor<OpenIddictServ
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSigninContext>()
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.AddFilter<RequireDeviceCodeIncluded>()
.AddFilter<RequirePreferDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionDeviceCode>()
Expand All @@ -308,7 +308,7 @@ public GenerateDataProtectionDeviceCode([NotNull] IOptionsMonitor<OpenIddictServ
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
public ValueTask HandleAsync([NotNull] ProcessSigninContext context)
public ValueTask HandleAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down Expand Up @@ -347,7 +347,7 @@ public ValueTask HandleAsync([NotNull] ProcessSigninContext context)
/// <summary>
/// Contains the logic responsible of generating a refresh token using Data Protection.
/// </summary>
public class GenerateDataProtectionRefreshToken : IOpenIddictServerHandler<ProcessSigninContext>
public class GenerateDataProtectionRefreshToken : IOpenIddictServerHandler<ProcessSignInContext>
{
private readonly IOptionsMonitor<OpenIddictServerDataProtectionOptions> _options;

Expand All @@ -358,7 +358,7 @@ public GenerateDataProtectionRefreshToken([NotNull] IOptionsMonitor<OpenIddictSe
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSigninContext>()
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.AddFilter<RequireRefreshTokenIncluded>()
.AddFilter<RequirePreferDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionRefreshToken>()
Expand All @@ -372,7 +372,7 @@ public GenerateDataProtectionRefreshToken([NotNull] IOptionsMonitor<OpenIddictSe
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
public ValueTask HandleAsync([NotNull] ProcessSigninContext context)
public ValueTask HandleAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down Expand Up @@ -411,7 +411,7 @@ public ValueTask HandleAsync([NotNull] ProcessSigninContext context)
/// <summary>
/// Contains the logic responsible of generating a user code using Data Protection.
/// </summary>
public class GenerateDataProtectionUserCode : IOpenIddictServerHandler<ProcessSigninContext>
public class GenerateDataProtectionUserCode : IOpenIddictServerHandler<ProcessSignInContext>
{
private readonly IOptionsMonitor<OpenIddictServerDataProtectionOptions> _options;

Expand All @@ -422,7 +422,7 @@ public GenerateDataProtectionUserCode([NotNull] IOptionsMonitor<OpenIddictServer
/// Gets the default descriptor definition assigned to this handler.
/// </summary>
public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSigninContext>()
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessSignInContext>()
.AddFilter<RequireUserCodeIncluded>()
.AddFilter<RequirePreferDataProtectionFormatEnabled>()
.UseSingletonHandler<GenerateDataProtectionUserCode>()
Expand All @@ -436,7 +436,7 @@ public GenerateDataProtectionUserCode([NotNull] IOptionsMonitor<OpenIddictServer
/// <returns>
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous operation.
/// </returns>
public ValueTask HandleAsync([NotNull] ProcessSigninContext context)
public ValueTask HandleAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/OpenIddict.Server.Owin/OpenIddictServerOwinHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
return new AuthenticationTicket(null, properties);
}

return null;
return new AuthenticationTicket((ClaimsIdentity) context.Principal.Identity, new AuthenticationProperties());
}

protected override async Task TeardownCoreAsync()
Expand Down Expand Up @@ -209,7 +209,7 @@ protected override async Task TeardownCoreAsync()

transaction.Properties[typeof(AuthenticationProperties).FullName] = signin.Properties ?? new AuthenticationProperties();

var context = new ProcessSigninContext(transaction)
var context = new ProcessSignInContext(transaction)
{
Principal = signin.Principal,
Response = new OpenIddictResponse()
Expand Down Expand Up @@ -260,7 +260,7 @@ protected override async Task TeardownCoreAsync()

transaction.Properties[typeof(AuthenticationProperties).FullName] = signout.Properties ?? new AuthenticationProperties();

var context = new ProcessSignoutContext(transaction)
var context = new ProcessSignOutContext(transaction)
{
Response = new OpenIddictResponse()
};
Expand Down
6 changes: 3 additions & 3 deletions src/OpenIddict.Server/OpenIddictServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ public void PostConfigure([CanBeNull] string name, [NotNull] OpenIddictServerOpt
}

if (!options.CustomHandlers.Any(
descriptor => descriptor.ContextType == typeof(ProcessSigninContext) &&
descriptor => descriptor.ContextType == typeof(ProcessSignInContext) &&
descriptor.FilterTypes.All(type => !typeof(RequireDegradedModeDisabled).IsAssignableFrom(type))))
{
throw new InvalidOperationException(new StringBuilder()
.Append("No custom verification sign-in handler was found. When enabling the degraded mode, ")
.Append("a custom 'IOpenIddictServerHandler<ProcessSigninContext>' must be implemented ")
.Append("to generate device and user codes (e.g by retrieving them from a database).")
.Append("a custom 'IOpenIddictServerHandler<ProcessSignInContext>' must be implemented ")
.Append("to generate device and user codes and storing them in a database, if applicable.")
.ToString());
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/OpenIddict.Server/OpenIddictServerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@ public ProcessChallengeContext([NotNull] OpenIddictServerTransaction transaction
/// <summary>
/// Represents an event called when processing a sign-in response.
/// </summary>
public class ProcessSigninContext : BaseValidatingTicketContext
public class ProcessSignInContext : BaseValidatingTicketContext
{
/// <summary>
/// Creates a new instance of the <see cref="ProcessSigninContext"/> class.
/// Creates a new instance of the <see cref="ProcessSignInContext"/> class.
/// </summary>
public ProcessSigninContext([NotNull] OpenIddictServerTransaction transaction)
public ProcessSignInContext([NotNull] OpenIddictServerTransaction transaction)
: base(transaction)
{
}
Expand Down Expand Up @@ -432,12 +432,12 @@ public ProcessSigninContext([NotNull] OpenIddictServerTransaction transaction)
/// <summary>
/// Represents an event called when processing a sign-out response.
/// </summary>
public class ProcessSignoutContext : BaseValidatingContext
public class ProcessSignOutContext : BaseValidatingContext
{
/// <summary>
/// Creates a new instance of the <see cref="ProcessSignoutContext"/> class.
/// Creates a new instance of the <see cref="ProcessSignOutContext"/> class.
/// </summary>
public ProcessSignoutContext([NotNull] OpenIddictServerTransaction transaction)
public ProcessSignOutContext([NotNull] OpenIddictServerTransaction transaction)
: base(transaction)
{
}
Expand Down
24 changes: 12 additions & 12 deletions src/OpenIddict.Server/OpenIddictServerHandlerFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public static class OpenIddictServerHandlerFilters
/// <summary>
/// Represents a filter that excludes the associated handlers if no access token is returned.
/// </summary>
public class RequireAccessTokenIncluded : IOpenIddictServerHandlerFilter<ProcessSigninContext>
public class RequireAccessTokenIncluded : IOpenIddictServerHandlerFilter<ProcessSignInContext>
{
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSigninContext context)
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand All @@ -34,9 +34,9 @@ public ValueTask<bool> IsActiveAsync([NotNull] ProcessSigninContext context)
/// <summary>
/// Represents a filter that excludes the associated handlers if no authorization code is returned.
/// </summary>
public class RequireAuthorizationCodeIncluded : IOpenIddictServerHandlerFilter<ProcessSigninContext>
public class RequireAuthorizationCodeIncluded : IOpenIddictServerHandlerFilter<ProcessSignInContext>
{
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSigninContext context)
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down Expand Up @@ -98,9 +98,9 @@ public ValueTask<bool> IsActiveAsync([NotNull] BaseContext context)
/// <summary>
/// Represents a filter that excludes the associated handlers if no device code is returned.
/// </summary>
public class RequireDeviceCodeIncluded : IOpenIddictServerHandlerFilter<ProcessSigninContext>
public class RequireDeviceCodeIncluded : IOpenIddictServerHandlerFilter<ProcessSignInContext>
{
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSigninContext context)
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down Expand Up @@ -146,9 +146,9 @@ public ValueTask<bool> IsActiveAsync([NotNull] BaseContext context)
/// <summary>
/// Represents a filter that excludes the associated handlers if no identity token is returned.
/// </summary>
public class RequireIdentityTokenIncluded : IOpenIddictServerHandlerFilter<ProcessSigninContext>
public class RequireIdentityTokenIncluded : IOpenIddictServerHandlerFilter<ProcessSignInContext>
{
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSigninContext context)
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down Expand Up @@ -194,9 +194,9 @@ public ValueTask<bool> IsActiveAsync([NotNull] BaseContext context)
/// <summary>
/// Represents a filter that excludes the associated handlers if no refresh token is returned.
/// </summary>
public class RequireRefreshTokenIncluded : IOpenIddictServerHandlerFilter<ProcessSigninContext>
public class RequireRefreshTokenIncluded : IOpenIddictServerHandlerFilter<ProcessSignInContext>
{
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSigninContext context)
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down Expand Up @@ -306,9 +306,9 @@ public ValueTask<bool> IsActiveAsync([NotNull] BaseContext context)
/// <summary>
/// Represents a filter that excludes the associated handlers if no user code is returned.
/// </summary>
public class RequireUserCodeIncluded : IOpenIddictServerHandlerFilter<ProcessSigninContext>
public class RequireUserCodeIncluded : IOpenIddictServerHandlerFilter<ProcessSignInContext>
{
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSigninContext context)
public ValueTask<bool> IsActiveAsync([NotNull] ProcessSignInContext context)
{
if (context == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static class Authentication
ApplyAuthorizationResponse<ProcessChallengeContext>.Descriptor,
ApplyAuthorizationResponse<ProcessErrorContext>.Descriptor,
ApplyAuthorizationResponse<ProcessRequestContext>.Descriptor,
ApplyAuthorizationResponse<ProcessSigninContext>.Descriptor,
ApplyAuthorizationResponse<ProcessSignInContext>.Descriptor,

/*
* Authorization request validation:
Expand Down Expand Up @@ -80,7 +80,7 @@ public ExtractAuthorizationRequest([NotNull] IOpenIddictServerProvider provider)
public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<ProcessRequestContext>()
.UseScopedHandler<ExtractAuthorizationRequest>()
.SetOrder(int.MinValue + 100_000)
.SetOrder(100_000)
.Build();

/// <summary>
Expand Down Expand Up @@ -278,7 +278,7 @@ public async ValueTask HandleAsync([NotNull] ProcessRequestContext context)

if (notification.Principal != null)
{
var @event = new ProcessSigninContext(context.Transaction)
var @event = new ProcessSignInContext(context.Transaction)
{
Principal = notification.Principal,
Response = new OpenIddictResponse()
Expand Down
Loading