Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Get Spring Roles from JWT

I have two roles in my REST back-end (built with Spring):

ROLE_USER, ROLE_ADMIN

When I log in, the REST API returns a valid token. Then I set it in the local storage like this:

localStorage.setItem('currentUser', JSON.stringify({username: username, token: token}));

And when I need it I get it like this:

localStorage.getItem('currentUser');

So far so good. When I get my token how do I get the payload and the claims in it?

I want to show admin panel if you are an admin.

like image 758
Teodor Dimitrov Avatar asked May 31 '26 14:05

Teodor Dimitrov


1 Answers

jwtHelper.decodeToken($scope.jwt)

See https://github.com/auth0/angular-jwt and https://github.com/auth0/angular2-jwt

an example https://github.com/auth0-blog/angularjs-jwt-authentication-tutorial/blob/8841ad5d7cb034506d2e3e6840db6202e6969b7a/frontend/home/home.js#L16

like image 135
StanislavL Avatar answered Jun 02 '26 03:06

StanislavL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!