HTTP Headers + Form Data from incoming POST request in Angular

Viewed 443

I am dealing with an authorization system that works the following way:

  1. User is sent to a third party login page
  2. User enters credentials
  3. Website redirects user back to my site, with a POST request containing auth token.

Is there any way for me to obtain the headers of the POST requests in Angular?

If not are there any alternative methods to handle this situation? I'm using Ngingx web server if that's of any help.

1 Answers

This is how you can obtain it

  1. You need a server-side application - choose your favorite tool, but probably Node.js if you are familiar with Angular

  2. Configure the auth gateway to POST to your server-side application

  3. The server-side application accepts the POST and then redirects back a special Angular "login success" route

Depending on the circumstances, or how the auth token is being used, you have some options here

4.1) The server-side application sets a cookie and Angular can read this cookie, know it has been properly logged in

4.2) If there is any token, like JWT, the server-side application can validate it and pass it to Angular in the redirect and then the application will store it in local storage

As a security issue, if the data is sensitive, make sure the auth token is not logged anywhere during the redirect.

Related