1

I am trying to get the authentication token from the login response but the value is null and I think that only Content-Type attribute is not null...

Login method

login(credentials: any): Observable<any> {
    return this.http.post(AUTH_API + '/login', {
      username: credentials.username, 
      password: credentials.password
    }, {observe: 'response'});
  }
this.authService.login(this.loginForm.value)
      .subscribe((res:Response) => {
        console.log(res.headers.get('Authorization'));
    },
    err => {
      this.isLoginError = true;
      this.loginErrorMessage = err.error;
    });

Response headers

EDIT:

I added Access-Control-Expose-Headers to my backend response and it works.

response.setHeader("Access-Control-Expose-Headers", "Authorization");
            response.addHeader("Authorization", jwtTokenProvider.generateToken(auth));

1 Answer 1

1

Seems that you have to add "Access-Control-Expose-Headers" to the response headers in your backend side.

Response from Angular 5 HTTP Client has "Authorization" missing from the Response header

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.