REST / JAVA + ANGULAR2 authentication

0

I have a api rest in java and need to perform an authentication (login / password). I'm building on this java code that uses Jwt: link

My question is: how to treat this token in the angle and authenticate the user? Every source of study is welcome. Thanks in advance.

    
asked by anonymous 11.02.2018 / 15:41

1 answer

0

I usually trigger a service on my backend that gets a username and password. This service validates and returns a JWT token.

At angular, I use the $ localStorage provider to store it. For each request that will be made to my API, I look for the token stored in the login and include it in the request HEADERS to validate it in the backend.

If you want to use the non-angular token for any purpose, you can use angular-jwt to decode it with the jwtHelper.decodeToken (token) function; and / or validate through the jwtHelper.isTokenExpired (token) function

Oh, to use this angle-jwt you need to add it in the module of your app ('angular-jwt').

    
19.04.2018 / 22:51