Merge branch 'release/2.1' into release/2.2

This commit is contained in:
Chris Ross (ASP.NET) 2018-07-12 14:43:40 -07:00
commit 175d493632
1 changed files with 42 additions and 0 deletions

View File

@ -468,6 +468,43 @@ namespace Microsoft.AspNetCore.Authentication.JwtBearer
Assert.Equal(HttpStatusCode.OK, response.Response.StatusCode);
}
[Fact]
public async Task SaveBearerToken()
{
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(new string('a', 128)));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var claims = new[]
{
new Claim(ClaimTypes.NameIdentifier, "Bob")
};
var token = new JwtSecurityToken(
issuer: "issuer.contoso.com",
audience: "audience.contoso.com",
claims: claims,
expires: DateTime.Now.AddMinutes(30),
signingCredentials: creds);
var tokenText = new JwtSecurityTokenHandler().WriteToken(token);
var server = CreateServer(o =>
{
o.SaveToken = true;
o.TokenValidationParameters = new TokenValidationParameters()
{
ValidIssuer = "issuer.contoso.com",
ValidAudience = "audience.contoso.com",
IssuerSigningKey = key,
};
});
var newBearerToken = "Bearer " + tokenText;
var response = await SendAsync(server, "http://example.com/token", newBearerToken);
Assert.Equal(HttpStatusCode.OK, response.Response.StatusCode);
Assert.Equal(tokenText, await response.Response.Content.ReadAsStringAsync());
}
[Fact]
public async Task SignInThrows()
{
@ -1140,6 +1177,11 @@ namespace Microsoft.AspNetCore.Authentication.JwtBearer
await context.Response.WriteAsync(identifier.Value);
}
else if (context.Request.Path == new PathString("/token"))
{
var token = await context.GetTokenAsync("access_token");
await context.Response.WriteAsync(token);
}
else if (context.Request.Path == new PathString("/unauthorized"))
{
// Simulate Authorization failure