[V3] How to have different token type requirements per route? #375
Unanswered
richk-h2ecommerce
asked this question in
BFF
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Using the following Nugets:
Duende.BFF.Yarp 3.0
Duende.BFF 3.0
Duende.AccessTokenManagement 3.2.0
Duende.AccessTokenManagement.OpenIdConnect 3.2.0
I have a simple app with just program.cs and a yarp.json config file.
I have 3 routes setup via yarp.json. 2 have AuthorizationPolicy; 1 requiring an authed user and one requiring the user has a specific role. These both work fine. These 2 routes are using the MetaData "Duende.Bff.Yarp.TokenType": "User".
Json config example for one below:
I need a 3rd route which allows non-authenticated users to talk to the back-end also, but naturally I still want the BFF to auth with the backend API. I have tried to facilitate this by using the TokenType "client" and specifying the ClientName to the name of a client specifically created for this purpose (different to the main clientName specified in the .AddOpenIdConnect() method.
Below is the part of the json file with the anonymous route:
And here is the setup for the ClientCredentialsClient:
I have verified via a debug endpoint and Postman that this cp-bff-service client
a) exists
b) gets a valid token from the IDP
However, when I call the endpoint bff/GetProductListNoAuth, I can see in the IdP (separate app) logs that the request is made as the cp-bff client and not the cp-bff-service client and is therefore rejected as the cp-bff client is configured for authorization_code grantType and uses PKCE. The cp-bff client is configured for client_credentials grantType and not PKCE.
I have also tried using the UserOrClient TokenType for the anon route and get the same result.
Why is this? Is it possible to configure things like I am trying to or is this not intended functionality?
Beta Was this translation helpful? Give feedback.
All reactions