asp api 7 jwt not recognizing "Staff" role but recognizes "Customer" role, verified user has staff
Stack Overflow
ASP.NET Core 7 : JWT bearer was challenged due to role
Decoded token from front-end displayed to debug:
{
sub: "[email protected]",
jti: "fd4779c8-2637-4c75-a901-447697274dce",
email: "[email protected]",
...
14 Replies
I believe the problem could be because of the way you are adding your roles to the list of claims in the jwt. Also be careful with sensitivity,
UserManager
might return "staff"
and the token "Staff"
. This could also be a problem.thank you for your response. i attempted to authorize "staff" but still the error "Bearer was challenged" persists when using Staff routes. I will try a foreach and manually add them.
Here is an example of how I generate my tokens
ive been seeing the addrange on stack. ill give that a shot. im just perplexed because im using the same code from the Customer token creator and that works. idk what Staff doesnt work
Here is what I get back when decoding the token:
thats from your tok
You don't really need multiple token generators. One should be enough.
ok
Yes
The token generation method that I sent you. Will get all your tokens from
UserManager
and store them correctly under Claim.Role
.ok tyvm.
Hope you find a solution. It's a bit hard to find the issue, without debugging the code.
unfortunately that didn't do anything. which is weird
um i even cleared cookies and cache according to microsoft, jwt roles are stored in a cookie from the api
if cached
hey you took time to respond earlier so i wanted to update you.
Issue Fixed So this was my error. I was using a standard html form with an angular web application because I didn't have enough time to debug a file upload with formdata using reactive forms. My school project was due. The form was being submitted successfully to the api and was not being intercepted by the angular interceptor to send the jwt. It was working exactly how i programmed it to work... unfortunately 🤪
@candyroll93 Good to hear, that you found a solution mate. It's always html's fault 🤣
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.