简体   繁体   English

无法在 MS Teams 桌面应用程序上运行选项卡

[英]Unable to run tab on MS Teams Desktop App

I have build Tabs for MS Teams and showing me this error on the desktop app only as seen below我已经为 MS Teams 构建了 Tabs,并且仅在桌面应用程序上向我显示此错误,如下所示

Also, this is working fine on every other platform (Browser, Mobile app)此外,这在所有其他平台(浏览器、移动应用程序)上都运行良好

InteractionRequiredAuthError: AADSTS50058: A silent sign-in request was sent but no user is signed in. The cookies used to represent the user's session were not sent in the request to Azure AD. InteractionRequiredAuthError: AADSTS50058: 发送了静默登录请求,但没有用户登录。用于表示用户 session 的 cookies 未在发送到 Azure AD 的请求中发送。 This can happen if the user is using Inte.net Explorer or Edge, and the web app sending the silent sign-in request is in a different IE security zone than the Azure AD endpoint (login.microsoftonline.com).如果用户使用的是 Inte.net Explorer 或 Edge,并且发送静默登录请求的 web 应用与 Azure AD 终结点 (login.microsoftonline.com) 位于不同的 IE 安全区域中,则可能会发生这种情况。 Trace ID: f6450045-e435-4fa7-8dcb-b1e7da7f2300 Correlation ID: b88afb3e-7b95-48fc-a68e-5875238dd1d3 Timestamp: 2021-01-28 08:56:59Z跟踪 ID:f6450045-e435-4fa7-8dcb-b1e7da7f2300 关联 ID:b88afb3e-7b95-48fc-a68e-5875238dd1d3 时间戳:2021-01-28 08:56:59Z

在此处输入图像描述


Here we are using MSAL, silent authentication.这里我们使用 MSAL,静默身份验证。

const tokenRequestObj = {
  scopes: ["user.read"],
  loginHint: loginHint,
};
this.msalService.acquireTokenSilent(tokenRequestObj) //get silent token using context.
  .then(async authTokenResult => {
    console.log(authTokenResult); //Got access token.
  }).catch((error) => {
    if (error.name === 'InteractionRequiredAuthError') {
      this.msalService.acquireTokenRedirect(tokenRequestObj)
    }
  });
this.msalService.handleRedirectCallback(this.authCallback);

It's not a bug, it's a feature.这不是一个错误,这是一个功能。

=========== You can scroll down to the solution section ================ ===========你可以向下滚动到解决方案部分================

This is a boring section...这是一个无聊的部分......

So let me try to explain what is happening on the background.因此,让我尝试解释一下背景中发生的事情。

First you call msalService.acquireTokenSilent which does some magic on the backgroung, something similar to this:首先,您调用msalService.acquireTokenSilent ,它在背景上做了一些魔术,类似于此:

  1. Checks localStorage for a token you can obtain.在 localStorage 中检查您可以获得的令牌。 (Web App level). (网络应用程序级别)。
  2. Invokes MSTeams App Api and trying to get token from there.调用 MSTeams 应用程序 Api 并尝试从那里获取令牌。 (Teams App level). (团队应用级别)。
  3. Reqests token from Graph (Network level).从 Graph 请求令牌(网络级别)。

If the background magic doesn't work it means you have to sign user in and obtain token from the OAuth. That's why you see this error:如果后台魔术不起作用,则意味着您必须让用户登录并从 OAuth 获取令牌。这就是您看到此错误的原因:

InteractionRequiredAuthError: AADSTS50058: A silent sign-in request was sent but no user is signed in. The cookies used to represent the user's session were not sent in the request to Azure AD. InteractionRequiredAuthError: AADSTS50058: 发送了静默登录请求,但没有用户登录。用于表示用户 session 的 cookies 未在发送到 Azure AD 的请求中发送。 This can happen if the user is using Inte.net Explorer or Edge, and the web app sending the silent sign-in request is in a different IE security zone than the Azure AD endpoint (login.microsoftonline.com).如果用户使用的是 Inte.net Explorer 或 Edge,并且发送静默登录请求的 web 应用与 Azure AD 终结点 (login.microsoftonline.com) 位于不同的 IE 安全区域中,则可能会发生这种情况。 Trace ID: f6450045-e435-4fa7-8dcb-b1e7da7f2300 Correlation ID: b88afb3e-7b95-48fc-a68e-5875238dd1d3 Timestamp: 2021-01-28 08:56:59Z跟踪 ID:f6450045-e435-4fa7-8dcb-b1e7da7f2300 关联 ID:b88afb3e-7b95-48fc-a68e-5875238dd1d3 时间戳:2021-01-28 08:56:59Z

Next you call msalService.acquireTokenRedirect which redirects user to login.microsoftonline.com and here's where the things go wrong!接下来调用msalService.acquireTokenRedirect ,它将用户重定向到login.microsoftonline.com ,这就是 go 错误的地方!

一个不简单

You see, Teams App works in a different way on different platforms.您会看到,Teams App 在不同平台上的工作方式不同。 There are 4 platforms: IOS, Android, Web, Desktop.有4个平台:IOS、Android、Web、Desktop。

IOS - opens Tab/Task in webview, has no redirect limitations. IOS - 在 webview 中打开选项卡/任务,没有重定向限制。

Android - opens Tab/Task in webview, has no redirect limitations. Android - 在 webview 中打开选项卡/任务,没有重定向限制。

Web - opens Tab/Task in iframe, has redirect limitations (X-Frame-Options). Web - 在 iframe 中打开选项卡/任务,具有重定向限制(X-Frame-Options)。

Desktop - opens Tab/Task in iframe, has redirect limitations (X-Frame-Options).桌面- 在 iframe 中打开选项卡/任务,具有重定向限制(X-Frame-Options)。 Well basically Desktop is the Electron app which hosts Web app.基本上桌面是 Electron 应用程序,它托管 Web 应用程序。 But it has popup limitation which i'll desctibe below.但它有弹出限制,我将在下面描述。

The issue you are facing with is related to the Desktop platforms.您遇到的问题与桌面平台有关。

======================= The solution section =========================== =======================解决方案部分======================== ===

So here's what you should do to fix this:所以这是你应该做的来解决这个问题:

  1. Implement redirects for mobile platforms only.仅为移动平台实施重定向。
  2. Avoid redirects on Web/Desktop platforms and use msalService.acquireTokenPopup instead.避免在 Web/桌面平台上重定向并改用msalService.acquireTokenPopup
  3. Desktop App doesn't open popup window (Why Microsoft, just why?) instead it deligates it to a default OS browser (that's the limitation i wrote above).桌面应用程序不会打开弹出窗口 window (为什么是 Microsoft,为什么?)而是将其委托给默认操作系统浏览器(这是我在上面写的限制)。 So you have to handle it on your own.所以你必须自己处理。

Here's an example how to handle Desktop popup issue:以下是如何处理桌面弹出窗口问题的示例:

  1. Make a session on the backend.在后端制作一个 session。
  2. Connect to the backend's session from Desktop App via websocket.从桌面应用程序通过 websocket 连接到后端的 session。
  3. Wait for a data from websocket.等待来自 websocket 的数据。
  4. Send data to the websocket from the redirectUri page (in the OS web browser) when user is successfuly signed in and redirected.当用户成功登录并重定向时,从redirectUri页面(在操作系统 web 浏览器中)向 websocket 发送数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM