|
|
@ -5,7 +5,6 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Immutable; |
|
|
|
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Security.Claims; |
|
|
using System.Security.Claims; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
@ -426,6 +425,236 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
Assert.Equal("Bob le Magnifique", (string) response[Claims.Subject]); |
|
|
Assert.Equal("Bob le Magnifique", (string) response[Claims.Subject]); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task ProcessChallenge_UnknownEndpointCausesAnException() |
|
|
|
|
|
{ |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var client = CreateClient(options => options.EnableDegradedMode()); |
|
|
|
|
|
|
|
|
|
|
|
// Act and assert
|
|
|
|
|
|
var exception = await Assert.ThrowsAsync<InvalidOperationException>(delegate |
|
|
|
|
|
{ |
|
|
|
|
|
return client.PostAsync("/challenge", new OpenIddictRequest()); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal("An OpenID Connect response cannot be returned from this endpoint.", exception.Message); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task ProcessChallenge_InvalidEndpointCausesAnException() |
|
|
|
|
|
{ |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var client = CreateClient(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
options.SetConfigurationEndpointUris("/challenge"); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleConfigurationRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.SkipRequest(); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Act and assert
|
|
|
|
|
|
var exception = await Assert.ThrowsAsync<InvalidOperationException>(delegate |
|
|
|
|
|
{ |
|
|
|
|
|
return client.GetAsync("/challenge"); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal("An OpenID Connect response cannot be returned from this endpoint.", exception.Message); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task ProcessChallenge_ReturnsDefaultErrorForAuthorizationRequestsWhenNoneIsSpecified() |
|
|
|
|
|
{ |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var client = CreateClient(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
options.SetAuthorizationEndpointUris("/challenge"); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleAuthorizationRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.SkipRequest(); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
var response = await client.PostAsync("/challenge", new OpenIddictRequest |
|
|
|
|
|
{ |
|
|
|
|
|
ClientId = "Fabrikam", |
|
|
|
|
|
Nonce = "n-0S6_WzA2Mj", |
|
|
|
|
|
RedirectUri = "http://www.fabrikam.com/path", |
|
|
|
|
|
ResponseType = ResponseTypes.Code, |
|
|
|
|
|
Scope = Scopes.OpenId |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Equal(Errors.AccessDenied, response.Error); |
|
|
|
|
|
Assert.Equal("The authorization was denied by the resource owner.", response.ErrorDescription); |
|
|
|
|
|
Assert.Null(response.ErrorUri); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task ProcessChallenge_ReturnsDefaultErrorForTokenRequestsWhenNoneIsSpecified() |
|
|
|
|
|
{ |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var client = CreateClient(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
options.SetTokenEndpointUris("/challenge"); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.SkipRequest(); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
var response = await client.PostAsync("/challenge", new OpenIddictRequest |
|
|
|
|
|
{ |
|
|
|
|
|
GrantType = GrantTypes.Password, |
|
|
|
|
|
Username = "johndoe", |
|
|
|
|
|
Password = "A3ddj3w" |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Equal(Errors.InvalidGrant, response.Error); |
|
|
|
|
|
Assert.Equal("The token request was rejected by the authorization server.", response.ErrorDescription); |
|
|
|
|
|
Assert.Null(response.ErrorUri); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task ProcessChallenge_ReturnsErrorFromAuthenticationProperties() |
|
|
|
|
|
{ |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var client = CreateClient(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
options.SetTokenEndpointUris("/challenge/custom"); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.SkipRequest(); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
var response = await client.PostAsync("/challenge/custom", new OpenIddictRequest |
|
|
|
|
|
{ |
|
|
|
|
|
GrantType = GrantTypes.Password, |
|
|
|
|
|
Username = "johndoe", |
|
|
|
|
|
Password = "A3ddj3w" |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Equal("custom_error", response.Error); |
|
|
|
|
|
Assert.Equal("custom_error_description", response.ErrorDescription); |
|
|
|
|
|
Assert.Equal("custom_error_uri", response.ErrorUri); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
|
|
[InlineData("custom_error", null, null)] |
|
|
|
|
|
[InlineData("custom_error", "custom_description", null)] |
|
|
|
|
|
[InlineData("custom_error", "custom_description", "custom_uri")] |
|
|
|
|
|
[InlineData(null, "custom_description", null)] |
|
|
|
|
|
[InlineData(null, "custom_description", "custom_uri")] |
|
|
|
|
|
[InlineData(null, null, "custom_uri")] |
|
|
|
|
|
[InlineData(null, null, null)] |
|
|
|
|
|
public async Task ProcessChallenge_AllowsRejectingRequest(string error, string description, string uri) |
|
|
|
|
|
{ |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var client = CreateClient(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
options.SetTokenEndpointUris("/challenge"); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.SkipRequest(); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessChallengeContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Reject(error, description, uri); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
var response = await client.PostAsync("/challenge", new OpenIddictRequest |
|
|
|
|
|
{ |
|
|
|
|
|
GrantType = GrantTypes.Password, |
|
|
|
|
|
Username = "johndoe", |
|
|
|
|
|
Password = "A3ddj3w" |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Equal(error ?? Errors.InvalidRequest, response.Error); |
|
|
|
|
|
Assert.Equal(description, response.ErrorDescription); |
|
|
|
|
|
Assert.Equal(uri, response.ErrorUri); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task ProcessChallenge_AllowsHandlingResponse() |
|
|
|
|
|
{ |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var client = CreateClient(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
options.SetTokenEndpointUris("/challenge"); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.SkipRequest(); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessChallengeContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Transaction.SetProperty("custom_response", new |
|
|
|
|
|
{ |
|
|
|
|
|
name = "Bob le Bricoleur" |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
context.HandleRequest(); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
var response = await client.PostAsync("/challenge", new OpenIddictRequest |
|
|
|
|
|
{ |
|
|
|
|
|
GrantType = GrantTypes.Password, |
|
|
|
|
|
Username = "johndoe", |
|
|
|
|
|
Password = "A3ddj3w" |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Equal("Bob le Bricoleur", (string) response["name"]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task ProcessSignIn_UnknownEndpointCausesAnException() |
|
|
public async Task ProcessSignIn_UnknownEndpointCausesAnException() |
|
|
{ |
|
|
{ |
|
|
@ -576,6 +805,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
{ |
|
|
{ |
|
|
@ -606,21 +844,21 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
{ |
|
|
{ |
|
|
Assert.Equal(new[] { "http://www.fabrikam.com/" }, context.Principal.GetResources()); |
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetAudiences("http://www.fabrikam.com/") |
|
|
|
|
|
.SetScopes(Scopes.OfflineAccess) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
return default; |
|
|
return default; |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
{ |
|
|
{ |
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
Assert.Equal(new[] { "http://www.fabrikam.com/" }, context.Principal.GetResources()); |
|
|
.SetAudiences("http://www.fabrikam.com/") |
|
|
|
|
|
.SetScopes(Scopes.OfflineAccess) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
return default; |
|
|
})); |
|
|
})); |
|
|
@ -647,6 +885,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -690,6 +937,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleAuthorizationRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -813,6 +1069,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleAuthorizationRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -946,6 +1211,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -979,6 +1253,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -1013,6 +1296,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
options.AllowCustomFlow("urn:ietf:params:oauth:grant-type:custom_grant"); |
|
|
options.AllowCustomFlow("urn:ietf:params:oauth:grant-type:custom_grant"); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -1040,7 +1332,19 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
public async Task ProcessSignIn_ExpiresInIsReturnedWhenExpirationDateIsKnown() |
|
|
public async Task ProcessSignIn_ExpiresInIsReturnedWhenExpirationDateIsKnown() |
|
|
{ |
|
|
{ |
|
|
// Arrange
|
|
|
// Arrange
|
|
|
var client = CreateClient(options => options.EnableDegradedMode()); |
|
|
var client = CreateClient(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
// Act
|
|
|
// Act
|
|
|
var response = await client.PostAsync("/connect/token", new OpenIddictRequest |
|
|
var response = await client.PostAsync("/connect/token", new OpenIddictRequest |
|
|
@ -1062,6 +1366,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -1373,6 +1686,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -1410,6 +1732,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleAuthorizationRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -1556,6 +1887,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
|
|
|
|
|
|
builder.SetOrder(EvaluateReturnedTokens.Descriptor.Order + 500); |
|
|
builder.SetOrder(EvaluateReturnedTokens.Descriptor.Order + 500); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// Act
|
|
|
// Act
|
|
|
@ -1579,6 +1919,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -1614,6 +1963,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
options.AllowCustomFlow("urn:ietf:params:oauth:grant-type:custom_grant"); |
|
|
options.AllowCustomFlow("urn:ietf:params:oauth:grant-type:custom_grant"); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -1653,6 +2011,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleAuthorizationRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
{ |
|
|
{ |
|
|
@ -1685,6 +2052,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
{ |
|
|
{ |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
{ |
|
|
{ |
|
|
@ -1720,15 +2096,6 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
options.EnableDegradedMode(); |
|
|
options.EnableDegradedMode(); |
|
|
options.UseRollingTokens(); |
|
|
options.UseRollingTokens(); |
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
Assert.Equal(new[] { Scopes.OpenId, Scopes.OfflineAccess }, context.Principal.GetScopes()); |
|
|
|
|
|
Assert.Equal("value", context.Principal.GetClaim(Claims.Prefixes.Private + "_private_claim")); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessAuthenticationContext>(builder => |
|
|
options.AddEventHandler<ProcessAuthenticationContext>(builder => |
|
|
{ |
|
|
{ |
|
|
builder.UseInlineHandler(context => |
|
|
builder.UseInlineHandler(context => |
|
|
@ -1746,6 +2113,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
|
|
|
|
|
|
builder.SetOrder(ValidateIdentityModelToken.Descriptor.Order - 500); |
|
|
builder.SetOrder(ValidateIdentityModelToken.Descriptor.Order - 500); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<ProcessSignInContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
Assert.Equal(new[] { Scopes.OpenId, Scopes.OfflineAccess }, context.Principal.GetScopes()); |
|
|
|
|
|
Assert.Equal("value", context.Principal.GetClaim(Claims.Prefixes.Private + "_private_claim")); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// Act
|
|
|
// Act
|
|
|
@ -2716,6 +3092,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
options.Services.AddSingleton(manager); |
|
|
options.Services.AddSingleton(manager); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleAuthorizationRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// Act
|
|
|
// Act
|
|
|
@ -2780,6 +3165,15 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
options.Services.AddSingleton(manager); |
|
|
options.Services.AddSingleton(manager); |
|
|
|
|
|
|
|
|
options.DisableAuthorizationStorage(); |
|
|
options.DisableAuthorizationStorage(); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleAuthorizationRequestContext>(builder => |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal = new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
})); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
// Act
|
|
|
// Act
|
|
|
@ -2796,6 +3190,21 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
Mock.Get(manager).Verify(manager => manager.CreateAsync(It.IsAny<OpenIddictAuthorizationDescriptor>(), It.IsAny<CancellationToken>()), Times.Never()); |
|
|
Mock.Get(manager).Verify(manager => manager.CreateAsync(It.IsAny<OpenIddictAuthorizationDescriptor>(), It.IsAny<CancellationToken>()), Times.Never()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
|
|
public async Task ProcessSignOut_UnknownEndpointCausesAnException() |
|
|
|
|
|
{ |
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var client = CreateClient(options => options.EnableDegradedMode()); |
|
|
|
|
|
|
|
|
|
|
|
// Act and assert
|
|
|
|
|
|
var exception = await Assert.ThrowsAsync<InvalidOperationException>(delegate |
|
|
|
|
|
{ |
|
|
|
|
|
return client.PostAsync("/signout", new OpenIddictRequest()); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal("An OpenID Connect response cannot be returned from this endpoint.", exception.Message); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Fact] |
|
|
[Fact] |
|
|
public async Task ProcessSignOut_InvalidEndpointCausesAnException() |
|
|
public async Task ProcessSignOut_InvalidEndpointCausesAnException() |
|
|
{ |
|
|
{ |
|
|
@ -2951,32 +3360,6 @@ namespace OpenIddict.Server.FunctionalTests |
|
|
|
|
|
|
|
|
options.AddEventHandler<ValidateTokenRequestContext>(builder => |
|
|
options.AddEventHandler<ValidateTokenRequestContext>(builder => |
|
|
builder.UseInlineHandler(context => default)); |
|
|
builder.UseInlineHandler(context => default)); |
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleAuthorizationRequestContext>(builder => |
|
|
|
|
|
{ |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal ??= new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
builder.SetOrder(int.MaxValue); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
options.AddEventHandler<HandleTokenRequestContext>(builder => |
|
|
|
|
|
{ |
|
|
|
|
|
builder.UseInlineHandler(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.Principal ??= new ClaimsPrincipal(new ClaimsIdentity("Bearer")) |
|
|
|
|
|
.SetClaim(Claims.Subject, "Bob le Magnifique"); |
|
|
|
|
|
|
|
|
|
|
|
return default; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
builder.SetOrder(int.MaxValue); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|