|
|
|
@ -16,6 +16,7 @@ using Owin; |
|
|
|
using Xunit; |
|
|
|
using Xunit.Abstractions; |
|
|
|
using static OpenIddict.Server.OpenIddictServerEvents; |
|
|
|
using static OpenIddict.Server.OpenIddictServerHandlers; |
|
|
|
using static OpenIddict.Server.OpenIddictServerHandlers.Protection; |
|
|
|
|
|
|
|
namespace OpenIddict.Server.Owin.IntegrationTests; |
|
|
|
@ -128,6 +129,54 @@ public partial class OpenIddictServerOwinIntegrationTests : OpenIddictServerInte |
|
|
|
Assert.Equal(new DateTimeOffset(2120, 01, 01, 00, 00, 00, TimeSpan.Zero), properties.ExpiresUtc); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessAuthentication_CustomPropertiesAreAddedForErroredAuthenticationResults() |
|
|
|
{ |
|
|
|
// Arrange
|
|
|
|
await using var server = await CreateServerAsync(options => |
|
|
|
{ |
|
|
|
options.EnableDegradedMode(); |
|
|
|
options.SetAuthorizationEndpointUris("/authenticate/properties"); |
|
|
|
|
|
|
|
options.UseOwin() |
|
|
|
.EnableErrorPassthrough() |
|
|
|
.EnableAuthorizationEndpointPassthrough(); |
|
|
|
|
|
|
|
options.AddEventHandler<ProcessAuthenticationContext>(builder => |
|
|
|
{ |
|
|
|
builder.UseInlineHandler(context => |
|
|
|
{ |
|
|
|
context.RejectIdentityToken = true; |
|
|
|
|
|
|
|
context.Properties["custom_property"] = "value"; |
|
|
|
|
|
|
|
return default; |
|
|
|
}); |
|
|
|
|
|
|
|
builder.SetOrder(EvaluateValidatedTokens.Descriptor.Order + 1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
await using var client = await server.CreateClientAsync(); |
|
|
|
|
|
|
|
// Act
|
|
|
|
var response = await client.PostAsync("/authenticate/properties", new OpenIddictRequest |
|
|
|
{ |
|
|
|
ClientId = "Fabrikam", |
|
|
|
IdTokenHint = "id_token_hint", |
|
|
|
Nonce = "n-0S6_WzA2Mj", |
|
|
|
RedirectUri = "http://www.fabrikam.com/path", |
|
|
|
ResponseType = "id_token", |
|
|
|
Scope = Scopes.OpenId |
|
|
|
}); |
|
|
|
|
|
|
|
// Assert
|
|
|
|
var properties = new AuthenticationProperties(response.GetParameters() |
|
|
|
.ToDictionary(parameter => parameter.Key, parameter => (string?) parameter.Value)); |
|
|
|
|
|
|
|
Assert.Equal("value", properties.Dictionary["custom_property"]); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task ProcessChallenge_ImportsAuthenticationProperties() |
|
|
|
{ |
|
|
|
@ -642,7 +691,7 @@ public partial class OpenIddictServerOwinIntegrationTests : OpenIddictServerInte |
|
|
|
else if (context.Request.Path == new PathString("/authenticate")) |
|
|
|
{ |
|
|
|
var result = await context.Authentication.AuthenticateAsync(OpenIddictServerOwinDefaults.AuthenticationType); |
|
|
|
if (result?.Identity is null) |
|
|
|
if (result?.Identity is not { IsAuthenticated: true }) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
|