public async Task ReplacedTicketAndHandleResponseFromValidateTokenCauseSuccessfulAuthentication() {
// Arrange
var server = CreateResourceServer(options => {
options.Events.OnValidateToken = context => {
var identity = new ClaimsIdentity(context.Options.AuthenticationScheme);
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "Contoso"));
context.Ticket = new AuthenticationTicket(
new ClaimsPrincipal(identity),
new AuthenticationProperties(),
context.Options.AuthenticationScheme);
context.HandleResponse();
return Task.FromResult(0);
};
});
var client = server.CreateClient();
var request = new HttpRequestMessage(HttpMethod.Get, "/");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "valid-token");
// Act
var response = await client.SendAsync(request);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Contoso", await response.Content.ReadAsStringAsync());
}