【问题标题】:Angular - unable to read www-authenticate header in catchErrorAngular - 无法读取 catchError 中的 www-authenticate 标头
【发布时间】:2021-03-09 05:08:45
【问题描述】:

我正在尝试读取 401 响应的 www-authenticate 标头,以便我可以触发令牌刷新并将请求再次发送到 API。但是,我似乎无法从错误响应中读取标题。下面是角度代码。尝试刷新访问令牌的其他人也遇到了这个问题?

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);
    })
);

任何帮助都会很有用。谢谢。

【问题讨论】:

    标签: angular oauth-2.0 api-authorization


    【解决方案1】:

    在互联网上进一步搜索后发现此链接in Microsoft Website。显然,虽然默认情况下会传递某些标头,但我必须在我的 API 中显式启用某些响应标头。在我的 API 中启用 WWW-Authenticate 标头,并且能够以角度代码读取它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-02
      • 2018-10-19
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 2021-06-07
      • 2015-11-19
      相关资源
      最近更新 更多