Save token that comes in the response of Api

0

I'm trying to save the token that my server sends on every request. Although apparently "Authorization" is present in the response, I can not print the value.

The code is:

Whatisreturnedfromtheserver:

WhatIcanprinttotheconsole:

OntheserverI'musingamiddlewareforcors

How do I get the token that is coming into Header Authorization?

    
asked by anonymous 25.04.2017 / 22:51

1 answer

1

Solved. I inserted some more options into the file that generates the final response on the server and it worked. I followed the suggestion of link

  

it looks like you did not expose the header correctly, the browser   will not forward this header to your code unless you specify it server   side.

     

try adding this to you $ headers object

$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE');
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type, X-Auth-Token, Origin, Authorization');
$response->headers->set('Access-Control-Expose-Headers', 'Authorization');
$response->headers->set('Authorization', 'Bearer ' . $newToken);

return $response;
    
26.04.2017 / 01:30