Why does the EasyAuth not accept my request for my function app with a OIDC identity provider?

Martin Rosin 5 Reputation points
2024-05-14T11:35:39.01+00:00

I have an API that exposes a few endpoints, from which some user details and data can be fetched. The API is a function app with authentication enabled and restrict access set to "Require authentication". My app uses azure B2C for a subset of users and has been configured as a Microsoft identity provider and works fine. But my other subset of users uses Keycloak as a identity provider. I have configured Keycloak as an identity provider and can see it in my list. When I use postman and get my access token and try to call my function app API the EasyAuth does not let the request through (HTTP 401). When troubleshooting (from the authentication tab) the auth settings JSON does not show my keycloak identity provider. Also there are a lot of JWT validation errors from Easy Auth (e.g. Issuer validation failure etc.). It seems that EasyAuth is trying to validate my request against the Microsoft/B2C identity provider and not my Keycloak. Does EasyAuth support multiple identity providers?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,416 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Martin Rosin 5 Reputation points
    2024-05-17T06:39:00.7133333+00:00

    By default Keycloak does not strictly enforce the clientId as the audience (aud) claim in tokens. There are reasons for this, which is outside the scope of this problem. In this case though, when there is federation and EasyAuth is used, one must make sure to map the clientId to the audience claim or else the token will be deemed invalid.

    There are multiple ways to resolve audience in keycloak: https://www.keycloak.org/docs/latest/server_admin/#audience-support

    1 person found this answer helpful.