尝试在“团队”标签中进行静默身份验证

时间:2019-04-01 12:32:32

标签: microsoft-teams adal.js

我已经设置了“团队”选项卡以及具有正确权限并指定了正确URL的Azure AD应用程序。我一直在尝试关注this guide

我可以在提琴手中看到从我的标签页向我的标签认证页提出了请求。在此之前,来自tab-auth页面的请求将转到以下网址:

https://login.microsoftonline.com/common/oauth2/authorize?response_type=id_token&client_id=xxx&redirect_uri=https%3A%2F%2Fmsteamsapp.domain.se%2Fpublic%2Ftab%2Ftabconfig%2Ftab-auth.aspx&state=xxxx&scope=openid+profile&login_hint=xxxxx&client-request-id=xxxx&x-client-SKU=Js&x-client-Ver=1.0.15&prompt=none&nonce=xxxxx

我在开发控制台中也遇到了一些错误:

  

解析'allow'属性时出错:'*;'是无效的功能名称。

     

未捕获的TypeError:无法读取未定义的属性'displayCall'       在新的AuthenticationContext(adal.min.js:2)       在tab-auth.aspx:26

     

未捕获的DOMException:阻止了具有来源的帧   访问跨域框架的结果为“ https://msteamsapp.domain.se”。       在window.onload(https://msteamsapp.domain.se/public/tab/tabConfig/tab.aspx

     

adal.min.js:2未捕获的TypeError:无法读取属性'displayCall'   未定义       在新的AuthenticationContext(adal.min.js:2)       在tab-auth.aspx:26

tab.aspx 有此代码:

        window.onload = function () {

            if (parent.document.getElementById("extension-tab-frame")) {
                var iframe = parent.document.getElementById("extension-tab-frame");
                iframe.sandbox = 'allow-forms allow-modals allow-popups allow-pointer-lock allow-scripts allow-same-origin allow-top-navigation';
            }
        }
        
        // ADAL.js configuration
        let config = {
            clientId: "xxxxxx",
            // redirectUri must be in the list of redirect URLs for the Azure AD app
            redirectUri: window.location.origin + "/public/tab/tabconfig/tab-auth.aspx",
            cacheLocation: "localStorage",
            navigateToLoginRequestUrl: true,
        };
        loginHint = 'xxxx';
        if (loginHint) {
        config.extraQueryParameter = "scope=openid+profile&login_hint=" + encodeURIComponent(loginHint);
    } else {
        config.extraQueryParameter = "scope=openid+profile";
        }
let authContext = new AuthenticationContext(config); // from the ADAL.js library
// See if there's a cached user and it matches the expected user
let user = authContext.getCachedUser();
if (user) {
    if (user.profile.oid !== userObjectId) {
        // User doesn't match, clear the cache
        authContext.clearCache();
    }
}


let token = authContext.getCachedToken(config.clientId);
if (token) {
    showProfileInformation(token);
} else {
    authContext._renewIdToken(function (err, idToken) {
        if (err) {
            console.log("Renewal failed: " + err);
            // Failed to get the token silently; show the login button
            showLoginButton();

        } else {
            showProfileInformation(idToken);
        }
    });
    }

tab-auth-aspx 具有以下代码:

let authContext = new AuthenticationContext();
                if (authContext.isCallback(window.location.hash)) {
                  authContext.handleWindowCallback(window.location.hash);
                                   if (authContext.getCachedUser()) {
                                       console.log('works');
                                        microsoftTeams.authentication.notifySuccess();
                                   } else {
                                       console.log('failure');
                                       console.log(authContext.getLoginError());
                                       microsoftTeams.authentication.notifyFailure(authContext.getLoginError());
                  }
                }

0 个答案:

没有答案