简体   繁体   English

为什么 app.initailzation() 在我的 Teams 加载项 OAuth 流中不起作用?

[英]Why Isn't app.initailzation() working in my Teams Add-in OAuth flow?

I am trying to get simple auth in my Teams app working with Adobe ID (a third party Oauth provider that I use on my site).我正在尝试在我的 Teams 应用程序中使用 Adobe ID(我在我的网站上使用的第三方 Oauth 提供商)获得简单的身份验证。

I am following the sample here .我在这里关注示例。 Everything is working to authorize with the Adobe ID, but when it gets to my end authentication page like this , I get an exception thrown with the message "SDK initialization timed out."一切都在使用 Adobe ID 进行授权,但是当它像这样到达我的最终身份验证页面时,我收到一个异常抛出消息“SDK 初始化超时”。 when I call await app.initialize();当我调用await app.initialize(); . . The sample shown does not have the await term before app.initialize() .显示的示例在app.initialize()之前没有await项。 Is that incorrect?那不对吗? If I remove the await , my code later on to notify authentication of success, fails with the exception "The library has not yet been initialized".如果我删除await ,我的代码稍后会通知身份验证成功,失败并出现异常“库尚未初始化”。 authentication.notifySuccess("Yippee");

  1. What do I need to do to allow app.initialize() to work?我需要做什么才能让 app.initialize() 工作?
  2. How can the sample work if there is no await before it?如果样本之前没有等待,样本如何工作?

Here is the TypeScript code for my OAuth End page that is loaded after the Adobe Authentication succeeds.这是我的 OAuth 结束页面的 TypeScript 代码,在 Adobe 身份验证成功后加载。

import $ from "jquery";
import {app, authentication} from "@microsoft/teams-js";

startup();

async function startup(){
    try{
        $("#status").text("Initializing");
    
        await app.initialize();

        $("#status").text("Initialized");
        console.log("notifying of success");

        authentication.notifySuccess("Yippee");
    }
    catch(error){
        handleError(error, "initializing");
    }
}

function handleError(error:Error, context: string){
    console.error(`💥 Error ${context}: ${error.message}`);

    $("#status").text(error.message);
}

What version of the js library are you using?你用的是什么版本的js库? There have been some changes to how app.initialize is handled depending on the version of the SDK you are using- see details here根据您使用的 SDK 的版本,app.initialize 的处理方式发生了一些变化 - 请在此处查看详细信息

https://learn.microsoft.com/en-us/microsoftteams/platform/tabs/how-to/using-teams-client-library?tabs=typescript%2Cmanifest-teams-toolkit#callbacks-converted-to-promises https://learn.microsoft.com/en-us/microsoftteams/platform/tabs/how-to/using-teams-client-library?tabs=typescript%2Cmanifest-teams-toolkit#callbacks-converted-to-promises

You should be able to see this in package.json for typescript, although I think there may be other areas where you may need to update this.对于 typescript,您应该能够在 package.json 中看到这个,尽管我认为可能还有其他区域您可能需要更新这个。 Try this with the version referenced in the sample- 2.0.0 does that resolve the issue?使用示例中引用的版本尝试此操作 - 2.0.0 是否可以解决问题?

re: await- that just tells the application to wait until a response is returned (a success or failure) before moving on to the next line. re: await- 只是告诉应用程序等待返回响应(成功或失败),然后再转到下一行。 In your case, you need the await as your next line is dependent on the value of status, but your function is async, so it won't block the execution of other async functions.在您的情况下,您需要等待,因为您的下一行取决于状态的值,但您的 function 是异步的,因此它不会阻止其他异步函数的执行。 You want to use await where you have other requests that must have a response on that call- like getauthtoken.你想在有其他请求必须对该调用有响应的地方使用 await——比如 getauthtoken。

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

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