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

问题描述 投票:0回答:1

我遇到了一个情况,我必须在有角度的应用程序中调用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时,会得到正确的响应。

enter image description here

在我遇到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

enter image description hereenter image description here

angular okta okta-api
1个回答
0
投票

我将index.html的标头与angular发送的标头进行了匹配。 index.html正在发送Cookie,而该cookie尚未发送。因此,通过设置{withCredentials:true})Angular可以做到这一点。

 .get<SessionInfo>(`https://tenet.oktapreview.com/api/v1/sessions/me`, { withCredentials: true })
© www.soinside.com 2019 - 2024. All rights reserved.