C
C#11mo ago
Joan G

❔ Dynamically change Filter to reuse same Controller

Hello! I have an application that has 2 different logins: one for web apps (with a cookie and SAML with certificates flow), another one for apps (with an apptoapp with JWT flow). The thing is that in order to not break the flow of the web app, I need the controller to have the [Authorize] tag + some Filters, and to use it with the App I need to check for a token with another completely different filter. Assuming I am not able to remove the [Authorize] tag (to not break the web flow), is there a dynamic way to add or remove tags to controller depending on the incoming request? For example: If I check in a middleware and it contains a token in the header, add the filters 2, else 1. I don't know if the question is clear enough. Anyway, thanks for your help!
3 Replies
Pobiega
Pobiega11mo ago
Attributes are compile-time metadata, so no, you can't vary the existence of them dynamically. What you CAN do is write your own middleware with your own attributes and use those, and in that middleware you could look at the request and decide what to do.
Joan G
Joan G11mo ago
That's what I thought... The thing is that I tried to add middlewares but somehow they 'break' the flow and some of the automatic redirections stop working. But thanks for your answer! I appreciate it!
Accord
Accord11mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.