如何检查AuthenticationContext是否与Azure AD连接?

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

我目前正在尝试连接到我的广告,以接收我的Team App内自己的Vue.js App的缓存的用户/令牌或新的令牌。

到目前为止,我已经创建了一个Teams应用程序来获取用户的上下文,创建了要连接到的Azure应用程序,并使用了Vue.js应用程序来测试microsoftTeams SDK和Adal.js程序包。

这是我当前的方法:

import * as microsoftTeams from '@microsoft/teams-js';
import * as AuthenticationContext from 'adal-angular/lib/adal';

// some other code that is not relevant to this...

async loginWithTeamsCredentials() {

  await microsoftTeams.initialize();

  microsoftTeams.getContext(async (context) => {
    const { loginHint } = context;

    const config = {
      clientId: 'some ClientID that I replaced with nonsense for this stackoverflow post',
      redirectUri: 'https://login.microsoftonline.com/common/oauth2/nativeclient',
      cacheLocation: 'localStorage',
      navigateToLoginRequestUrl: false,
    };

    if (loginHint) {
      config.extraQueryParameter = `scope=openid+profile&login_hint=${encodeURIComponent(
        loginHint,
      )}`;
    } else {
      config.extraQueryParameter = 'scope=openid+profile';
    }

    const authContext = new AuthenticationContext(config);

    const user = await authContext.getCachedUser();

    console.log(user);
  });
},

问题是,即使用户存在于我的浏览器的localStorage中,该用户也始终为null。因此,我不确定要通过AuthenticationContext对象开始是否与我的AD建立连接。我的代码中的配置包含必要的信息,并且也应该正确。我还可以通过此代码获得microsoftTeams SDK上下文的loginHint,所以这也不是问题。

我在这里做错了什么?

adal microsoft-teams adal.js
1个回答
1
投票

我的问题是使用adal.js而不是msal.js,这对于Azure AD V2是必需的。使用msal.js和相应的方法可以建立连接。

编辑2019-12-16:另一件事是,您不能在MicrosoftTeams中使用msal进行静默身份验证。因此,我目前正在尝试找出如何仅从microsoftTeams SDK中获取我的信息。

© www.soinside.com 2019 - 2024. All rights reserved.