chaonextdoor
chaonextdoor

Reputation: 5129

How to retrieve the authorization token from the response header of an ajax call in angularjs?

Basically the title has described everything. I send an api call, get a response, with Authorization in the header, and I want to retrieve this authorization token from the header because it is needed for subsuquent api calls. How should I get this info?

Upvotes: 2

Views: 2305

Answers (2)

alberto-bottarini
alberto-bottarini

Reputation: 1231

You should take a look here: https://docs.angularjs.org/api/ng/service/$http

$http.get('yourUrl').
  success(function(data, status, headers, config) {
    console.log(headers);
  })

Upvotes: 1

Reactgular
Reactgular

Reputation: 54741

$http passes headers to the success/error callbacks. The headers parameter is a function that takes a single argument that is an array. It returns all those header values as an array result.

$http.get('/someUrl')
     .success(function(data, status, headers) {
         console.log(headers(['Authorization']));
     });

Upvotes: 0

Related Questions