WhiteAngel
WhiteAngel

Reputation: 2826

How to get headers of the redirect response using AngularJS

I'm trying to implement OAuth2 authentication methods for an internal application. The process looks quite straightforward:

  1. User presses "Login" button
  2. User is being redirected to the page which contains code received from OAuth2 server
  3. Request is being sent to OAuth2 server to obtain access_token
  4. As soon as access_token is received user is being redirected back to initial page and a special header Header["Access-Token"] is being set during this redirection

Authentication works fine in this case, the only prolem I'm having is that I can't read Header["Access-Token"] after the redirection back to initial page.

Using interceptors I'm able to intercept requests which are being sent from the application (e.g. REST API requests) but not the ones during the page load.

Is there any solution using Angular for this problem?

Upvotes: 1

Views: 2025

Answers (1)

user3639680
user3639680

Reputation: 71

I hope it will be helpful.

  • you can redirect user to "originalURL/"+access_token from server as the response will be indirectly sent to endpoint on server
  • Then if you don't want to expose the access_token you can set it's value in cookies/session and just remove it from url.
  • Alert: if that token contains "/" or "#" please replace it with some keyword while redirection from server because Angular use "/" and "#" in routing. So if your url includes such characters it will redirect you to default route.

Upvotes: 1

Related Questions