❔ Is this possible in WEBAPI to add logic between JWT token validation and the authorization?
I read a blog about the AspNetCore WebApi: https://jasonwatmore.com/post/2022/02/18/net-6-role-based-authorization-tutorial-with-example-api
this sample add an User instance in HttpContext.Items after the token validation and bring it to the Authorization filter to use it.
I'm trying implement this with AspNetCore internal functions(middleware, policy and requirements). but I cannot find a way to add User instance in that time.
and also try to created a custom middleware
but this Handler will be invoked after the authorization.
Is there any handler can add some logic between JWT token validation and API authorization?
.NET 6.0 - Role Based Authorization Tutorial with Example API | Jas...
How to build an API with role based authorization / access control in .NET 6.0 & C#. Includes example client apps built with Angular, React and Vue.
36 Replies
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
just this line
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
this is the code from the sample
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
thanks
you mean I add user info in the claims?
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
such as roles
the HttpContext.User>?
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
could the claim store array or list?
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
this interface?
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
so I can put the roles into claims into the token. after the token validation, I can use the HttpContext.User.Roles for authorization
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
i may take time to understand that. I'm new with C#
I'll try to understand that IClaims interface and find a way to query the user role with user id
thanks
now I find the only ways is query the user role with ID in policy requirement
but I need to query the roles in each requirement class.
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
yes, and I don't wanna the roles put inthe claim and return to the user
I'll try this
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
I agree
sorry my English is not well. maybe I miss something you said
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
Thanks , I implemented a custom IAuthorizationService. I made it
thankks alot
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
a minute
here is the program file
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
and there is another way to impl that
the jwtbearerOption has a event that would be invoked when the token validated
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
truly thanks for your comments about IAuthService
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.