Skip to content

Invalid Audience error for JWT Bearer token #21

@dawidboloz

Description

@dawidboloz

Hi,

For more than 2 weeks I have been experiencing an issue with Authorisation on Azure Function App (.net 6.0, in-process, v4) on my TEST environment.
The function was working correctly for a long time before and there was no change done lately. Suddenly the issue starts to appear successively in all our other environments (QA, PROD) with 7 days and 2 days of delay.

The weird this is that my startup configuration, specifically, is not validating the tokens audience, see the configuration.

.AddJwtBearer(options =>
{
    options.Authority = //taken from appsettings
    options.TokenValidationParameters.ValidateAudience = false;
    options.RequireHttpsMetadata = true;
    options.Events = jwtBearerEvents;
})

The most problematic thing is that the issue is not reproducible locally on the VisualStudio, and started from nothing.

The error I have:

Bearer error="invalid_token", error_description="The audience 'api1 api2 api3 api4' is invalid

the 'api1 api2 api3 api4' is the whole audience present in the token

I contacted Azure Support and they advised me to use "Custom Bearer" because apparently

"Bearer" schema is used by Azure Functions with their handler

They also suggested more or less the same as here in the "Accepted answer": microsoft learn

I would like to ask if anyone is experiencing the same issue? And if this package is prepared for, apparently, not supporting "Bearer" schema anymore?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions