从 Angular 应用程序调用 OKTA url 给出 404,但在浏览器中有效

calling OKTA url from Angular app gives 404 but works in browser

我有一个场景,我必须在 angular 应用程序中调用 OKTA url“{}/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 时,我得到了正确的响应。

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

有什么想法吗?

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

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

我匹配了 index.html 的 header 和 header 发送的 angular。 index.html 正在发送 angular 没有发送的 cookie。所以通过设置 { withCredentials: true }) Angular 做同样的事情 .

 .get<SessionInfo>(`https://tenet.oktapreview.com/api/v1/sessions/me`, { withCredentials: true })