i'm stucked on a problem and i don't know how to solve it.
i want to add two different JWT authorization methods to my API. don't ask me why, reasons.
in my startup.cs i added
services.AddAuthentication()
.AddJwtBearer("firstJwt", options =>
{
options.Audience = "FirstProtectedApi";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("mySecret")),
ValidIssuer = "WebApiTest",
ValidateAudience = true,
ValidateLifetime = true,
ClockSkew = TimeSpan.FromMinutes(1)
};
})
.AddJwtBearer("secondJwt", options =>
{
options.Audience = "SecondProtectedApi";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("mySecret")),
ValidIssuer = "WebApiTest",
ValidateAudience = true,
ValidateLifetime = true,
ClockSkew = TimeSpan.FromMinutes(1)
};
});
services
.AddAuthorization(options =>
{
options.DefaultPolicy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.AddAuthenticationSchemes("FirstProtectedApi", "SecondProtectedApi")
.Build();
});
and this code should work.
my problem now is, in the controller. i have, for testing purpose, two different logins. how do i call the first or the second authentication schemes on login so that i can navigate to protected routes only available to FirstProtectedApi or SecondProtectedApi?
even some documentation would be awesome!
thanks a lot!