szerhusenBC/jwt-spring-security-demo

User Roles at front end

Closed this issue · 5 comments

Hi, Did not find on how to get corresponding user roles in front end.
Pls help to give some direction . I am able to get the token in my angular front end . So the authentication is fine. How about the roles to read ? If the token also has the role information then which api or helper can help to read the roles from token in the angular app.

Pls help .

Hi!

At first you have to add the roles information as a claim attribute in the token at the server side. You can do that in the method org.zerhusen.security.JwtTokenUtil.generateToken().

Then you can decode the token and get the claim information (which then contains your roles information) in your Angular client. I'm using the library "jwt_decode" to do that. You can find the neccessary packages under

Does that help you?

Thank You so much for your quick response . I will be following your suggestions and will let you know the outcomes .

Thanks .

I am closing this Ticket now. If you still have problems please let me know.

Hi Stephan ,
I have followed your suggestion . I am able to fetch the roles .
Thank you so much for your guidance.
Sorry for this late reply. Please mark my question as resolved .

You're welcome ;)