#How to get Authorization token from response headers?

8 messages · Page 1 of 1 (latest)

jolly creek
#

I'm trying to get auth token from response headers this is my code in auth.service.ts

login(email: string, password: string): Observable<any> {
  const url = `${this.apiUrl}/auth/login`;
  const body = {
    Email: email,
    Password: password,
  };

  return this.http.post(url, body, { observe: 'response' }).pipe(
    map((response) => {
      console.log(response.headers.keys());
      const bearerToken = response.headers.get('Authorization');
      console.log(bearerToken);
      return response;
    })
  );
}

but actually I didn't find it the only 2 headers I found in the console are ['content-length', 'content-type']
What is the problem here??

#

and the header exists in the network

crimson axle
#

Does this header belong to POST only, not to the response?

jolly creek
crimson axle
#

In communication between client and server, usually, the authorization header is used to pass info from client to server. Not in the other direction. That is why it is not visible in the response.

jolly creek
crimson axle
#

yeah, I see, I was not paying attention to the screenshot. It is there indeed.