In Annular, the following Steps are used to building authentication and authorization for RESTful APIs and applications. It might help you -
1. The users send their credentials to the server which is verified by the database credentials. If everything is verified successfully, the JWT is sent back to them.
2. The JWT is saved in the user's browser in local storage or in a cookie and so on.
3. The presence of a JWT saved in the browser is used as an indicator that a user is currently logged in.
4. The expiry time of JWT is continually checked to maintain an authenticated state in the Angular applications.
5. The client side routes are protected and access by authenticated users only.
6. When user sends the XHR requests for APIs, the JWT gets sent an Authorization header using your cookies or Bearer.
7. When XHR requests coming on the server, before send back the responses it’s validated first with configured app's secret keys. If everything is looking good then returns successfully responses other send the back to the bad request.
Stayed Informed - Cross Site Request Forgery (XSRF or CSRF)
There are several open source libraries are available for angular which are helps with JWTs and has the ability to Decode the JWT, Authorization header to XHR requests and so on.
"name": "Anil Singh",
HMACSHA256(base64UrlEncode(header) + "." + base64UrlEncode(payload), secret);