I'm trying to read the www-authenticate header for a 401 response so that I can trigger token refresh and send the request again to API. However, I don't seem to be able to read the header from the error response. Below is the angular code. Anyone else trying to refresh the access token faced the issue?
const headers = new HttpHeaders({
'Content-Type': 'application/json',
Authorization: 'bearer ' + this.accessToken
});
const httpCall = this.http.get<T>(getUrl, { headers: headers, observe : 'response'});
return httpCall
.pipe(
map(resp => {
console.log(resp);
return resp.body;
}),
catchError((err: HttpResponse<T>, resp) => {
console.log(err.headers.get('www-authenticate'));
console.error(err);
return of(null);
})
);
Any help would be useful. Thanks.
After further searching on the internet came upon this link in Microsoft Website. Apparently while certain headers are passed by default, I have to explicitly enable certain response headers in my API. Enabled the WWW-Authenticate header in my API and was able to read it in the angular code.