从 Microsoft Teams 获取 SSO 身份验证令牌的问题

Wet_Pantz

我想从 Microsoft 团队获取访问令牌,当在邮递员中使用相同的数据执行它时,它可以完美地工作,在 react 应用程序中发出发布请求时,它不起作用。

这是我的代码:

  useEffect(() => {
    debugger;
    if (inTeams === true) {
      microsoftTeams.authentication.getAuthToken({
        successCallback: (result) => {
          console.log(result);
          const serviceRequest: any = {
            client_id: "[client_id]",
            client_secret: "[client_secret]",
            requested_token_use: "on_behalf_of",
            grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
            scope:
              "[scope]",
            assertion: result,
          };


          httpClient.GetAuthenticationToken(serviceRequest).then((res) => {
            console.log(res);

          });
          var querystring = require("querystring");
          //...
          var asd = querystring.stringify(serviceRequest);

          console.log(asd);

          axios
            .post(
              "https://login.microsoftonline.com/common/oauth2/v2.0/token",
              asd,
              {
                headers: {
                  "Content-Type": "application/x-www-form-urlencoded",
                },
              }
            )
            .then(function (response) {
              console.log(response);
            });

          microsoftTeams.appInitialization.notifySuccess();
        },
        failureCallback: function (error) {
          console.log(error);
        },
      });
    } else {
      setEntityId("Not in Microsoft Teams");
    }
  }, [inTeams]);

这是我发送的(在网络中找到,'[]' 中的字段被我替换,因为隐私)

client_id=[client_id]&client_secret=[client_secret]&requested_token_use=on_behalf_of&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&scope=[scope]&assertion=[assertion]

这是我得到的错误:

在此处输入图像描述

这是在网络中的预览:在此处输入图像描述 AADSTS9002326: Cross-origin token redemption is permitted only for the 'Single-Page Application' client-type.\r\nTrace ID: ef9c5d80-13d0-4001-898b-7206f4663b00\r\nCorrelation ID: 2c0d0ece-3ce5-4ee6-9cdf-8966f66cee2f\r\nTimestamp: 2022-04-01 10:06:19Z

-------------------------------------------

更新:感谢答案:)

我创建了一个获取 SSO 令牌并将其交换为 OBO 令牌的后端方法。这是代码:

   public static async Task<string> ExchangeForOBOToken(ExchangeOBORequest request)
    {
        var contentData = new Dictionary<string, string>();
        contentData.Add("client_id", request.client_id);
        contentData.Add("client_secret", request.client_secret);
        contentData.Add("requested_token_use", request.requested_token_use);
        contentData.Add("grant_type", request.grant_type);
        contentData.Add("scope", request.scope);
        contentData.Add("assertion", request.assertion);
        
        using (var httpClient = new HttpClient())
        {
            using (var content = new FormUrlEncodedContent(contentData))
            {
                content.Headers.Clear();
                content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

                HttpResponseMessage response = await httpClient.PostAsync("https://login.microsoftonline.com/common/oauth2/v2.0/token", content);

                var res=  await response.Content.ReadAsStringAsync();
                return res;
            }
        }
        
    }

我只是用所有数据从前端调用它并返回 OBO 令牌 :)

吉塞诺希尔顿酒店

所以上面有一堆点:

  1. 您实际上并没有说明您需要令牌的用途。据推测,您希望 SSO 令牌能够调用 Graph,这就是为什么您要将其兑换为“代表”(OBO)令牌的原因 - 请确认尽管

  2. 您不想在您的客户端代码中进行 OBO 令牌交换 - 这仅意味着在 SERVER 端发生,因此这些宝贵的令牌不会泄露给攻击者。在此视频此博客文章中查看更多信息

  3. 一旦你的 OBO 部分被移到你的后端,你的代码会看起来更简单,如下所示:

  useEffect(() => {
    debugger;
    if (inTeams === true) {
      microsoftTeams.authentication.getAuthToken({
        successCallback: (result) => {
         // make your call here to your backend, which will in turn: (A) get the OBO token and (B) use it to call whatever you want on Graph.
        },
        failureCallback: function (error) {
          console.log(error);
        },
      });
    } else {
      setEntityId("Not in Microsoft Teams");
    }
  }, [inTeams]);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Microsoft Teams SSO 身份验证方法 getAuthToken() 返回“resourceDisabled”

在Microsoft Teams Bot中进行身份验证后如何获取用户访问令牌?

Microsoft Teams身份验证:无法在Teams Bot(V4 SDK)中检索令牌

门户在获取Microsoft_Azure_Storage的身份验证令牌时遇到问题

Microsoft Teams Bot身份验证黑屏

使用 AAD 身份验证的 Microsoft Teams 传出 Webhook

如何使用 Microsoft Share To Teams 按钮对用户进行身份验证?

从asp.net核心身份验证Web应用程序获取Microsoft Graph的访问令牌

如何从Auth0-Lock SSO身份验证获取Facebook用户ID

aws eks 和 aws sso RBAC 身份验证问题

如何通过EWS获取Microsoft Teams聊天消息?

如何获取Microsoft Teams用户的当前状态

在 Microsoft Teams 中从空频道获取消息导致 403

如何获取 Microsoft Teams 上下文属性 hostClientType

如何使用 django-microsoft-auth 获取当前登录用户进行 Microsoft 身份验证?

Microsoft 身份验证请求使用访问令牌的附加范围

sp启动saml sso身份验证

Owin身份验证-如何获取请求身份验证令牌的客户端的IP地址

使用 Blazor 服务器和 Azure AD 身份验证获取身份验证令牌

Spring Security OAuth2-@ EnableOauth2Sso,但也接受令牌作为身份验证

SSO基于基于令牌的身份验证的安全性如何?

使用Python社交身份验证仅获取令牌

如何从Tableau Server可信身份验证获取令牌?

在 Blazor 中获取访问令牌的 Google 身份验证错误

从Authorization HTTP标头中获取身份验证令牌的值

从Azure Easy API获取Facebook身份验证令牌

Firebase通过REST获取身份验证令牌?

Golang和gcloud API:如何获取身份验证令牌

获取没有gcloud的服务帐户身份验证令牌?