从Angular应用程序调用OKta URL会给出404,但可以在浏览器中使用

我遇到一种情况,我必须在有角度的应用程序中调用OKTA网址“ {} / api / v1 / sessions / me”。 我不使用任何图书馆只是打个普通电话。 我正在使用这样的代码

const headers = new HttpHeaders().set('Content-Type','application/json; charset=utf-8');
this.http
  .get<SessionInfo[]>(`https://xxx.xxx.com/api/v1/sessions/me`,{ headers })
  .subscribe((data: SessionInfo[]) => {
    alert(data);
  });

SessionInfo看起来像这样

export class SessionInfo {
userId: string;
login: string;
  }

当我在浏览器中运行url时,会得到正确的响应。

从Angular应用程序调用OKta URL会给出404,但可以在浏览器中使用

在此之前,我遇到了CORS问题,但我在okta仪表板中对其进行了修复,并在CORS列表中添加了localhost:8080。之后,我得到404。

有什么想法吗?

更新 https://devforum.okta.com/t/get-current-session-api-not-returning-session/3758 这里的讨论使我相信它与Cookie有关。我的目标是获取当前用户的ID,但看起来我们无法从其他网址读取Cookie。

更新2 我做了一个简单的html页面,并使用简单的nodejs服务器托管了它,但得到了响应。并从角度做同样的事情我得到404

从Angular应用程序调用OKta URL会给出404,但可以在浏览器中使用

从Angular应用程序调用OKta URL会给出404,但可以在浏览器中使用

qq_zjy3 回答:从Angular应用程序调用OKta URL会给出404,但可以在浏览器中使用

我匹配了index.html的标头和angular发送的标头。 index.html正在发送角度未发送的cookie。因此,通过设置{withCredentials:true})Angular可以做到这一点。

 .get<SessionInfo>(`https://tenet.oktapreview.com/api/v1/sessions/me`,{ withCredentials: true })
本文链接:https://www.f2er.com/2360748.html

大家都在问