Save token coming in Api Sponse

Asked

Viewed 233 times

0

I am trying to save the token that my server sends in each request. Although "Authorization" appears to be present in Sponse, I cannot print the value.

The code is: código no service

What returns from the server: retorno do servidor

What I can print on the console: console

On the server I am using a middleware for Cors inserir a descrição da imagem aqui

How do I "pick up" the token that is coming in Header Authorization?

1 answer

1

Solved. I inserted a few more options in the file that generates the final replay on the server and it worked. I followed the suggestion of https://stackoverflow.com/questions/43622368/save-token-that-comes-in-response-to-api

it looks that 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.