I have a .Net test client project that is trying to call a .Net API server. The client uses the FusionAuth API to login a user and get a JWT token back:
public static async Task<string> AuthenticateTestUser()
{
if (!string.IsNullOrEmpty(JwtToken))
{
return JwtToken;
}
var testApiKey =
"DWCSwbQ-ZGVedjTw78Lvjwk9lx-Mr-6vYdzqS_RTYT8O-RNVr0_hBJfV"; // todo: use a more restricted API key
var client = new FusionAuthClient(testApiKey, "http://localhost:9011");
var accruedBenefitsAppId = Guid.Parse("bbfb892e-2a37-491e-8a4a-d87a12231c55");
var response = await client.LoginAsync(new LoginRequest()
{
password = "**********",
applicationId = accruedBenefitsAppId,
loginId = "automated-test-user@site.com"
});
JwtToken = response.successResponse.token;
return JwtToken;
}
I then use that JwtToken to make an API request with HttpClient and add the authorization like this:
httpReq.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JwtToken);
I've configured the API application in startup to use authentication like this:
services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.RequireHttpsMetadata = false; //todo: don't deploy this!
options.Authority = configuration.GetValue<string>("AuthenticationSettings:Authority");
options.Audience = configuration.GetValue<string>("AuthenticationSettings:ClientId");
options.IncludeErrorDetails = true;
});
The authority value is simply the URL of my local FusionAuth instance (http://localhost:9011/
) and the Audience is the ID of the API application I made (some GUID).
Yet when I make the API request, I get a 401 response back and the value of the WWW-Authenticate header is: error="invalid_token", error_description="The signature key was not found"
for Scheme Bearer
.
I have verified that the user exists and that they have a registration for the app that I am trying to validate for. The JWT token comes back fine and I can read it in JWT.io.
When I look at the various logs in FusionAuth, I see that there is a login for that user.
Obviously I am missing some important step, but I'm not sure what. Does the API project need to prove its identity in some way before it can validate the JWT token? I don't see any examples or mention of that.