我有一个 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_hint
和domain_hint
。我传递了这两个参数,但没有任何反应。请注意,在下面的代码段中,我放置了日志。只有componentWillMount
,before
和after
被记录在控制台中。
不确定这里缺少什么。
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);
}
}