1

我有一个 Reactjs 应用程序(又名单页应用程序),它作为 Web 资源上传到 Dynamics 365 Customer Engagement(以前称为 CRM)。此 Web 资源或应用程序显示在实体表单内的 IFRAME 中,因此此小型应用程序已经可以使用 Xrm 对象直接访问 Dynamics 365 数据。都好。

我试图用这个应用程序完成的是让它通过 Microsoft Graph API 连接到 SharePoint 并上传文件和创建文件夹。

由于用户已经登录到 Dynamics 365 和 Azure AD(我猜),没有必要向用户显示另一个弹出登录屏幕。

在 msal wiki中,有 2 个附加参数可以传递给 ,userAgentApplication以通知 AAD 用户已经登录并且它们是login_hintdomain_hint。我传递了这两个参数,但没有任何反应。请注意,在下面的代码段中,我放置了日志。只有componentWillMount,beforeafter被记录在控制台中。

不确定这里缺少什么。

componentWillMount() {
    console.log('componentWillMount');
    try {
        console.log('before');

        var userAgentApplication = new UserAgentApplication(applicationConfig.clientID, applicationConfig.authority, function (errorDesc, token, error, tokenType) {
            // Called after loginRedirect or acquireTokenPopup
            console.log('callback called');
        }, {cacheLocation: 'localStorage'});

        userAgentApplication.acquireTokenSilent(["user.read"], null, null, "&login_hint=first.last@mydomain.cp,&domain_hint=mydomain.com")
            .then(token => console.log('token', token))
            .catch((err) => console.log('err', err));

        userAgentApplication.acquireTokenSilent(["user.read"], "&login_hint=first.last@mydomain.cp,&domain_hint=mydomain.com")
            .then(token => console.log('token', token))
            .catch((err) => console.log('err', err));

        console.log('after');

    }
    catch (e) {
        console.log('caught error: ', e);
    }
}
4

1 回答 1

1

花了3天后,我会回答我自己的问题。

我发现了2个问题:

  • 我需要调用userAgentApplication.loginPopup并将 user.name@domain.com 传递给login_hintextraParameters然后调用acquireTokenSilent. userAgentApplication 将检查是否存在现有授权。
  • 第二个问题是acquireTokenSilent根本不执行。既没有成功也没有失败,并且在github中有一个未解决的问题。
于 2019-01-22T18:42:51.907 回答