如何解决Outlook web add in with msal 1.x loginRedirect - 不再使用最新的 iOS
我有一个 office add,它需要用户获取 MS Graph 访问令牌。我当前的代码库适用于所有平台和 iOS14 之前的每个 iOS 版本。我使用 msal.js 和 DialogAPIs (displaydialogasync) 来允许用户登录。但是当用户在使用 iOS14 的设备上单击登录时,而不是被重定向到 login.microsoft,重定向似乎失败(微调器出现在
我会分享一些代码以防万一出现错误。
MainPage.html
var dialog;
Office.context.ui.displayDialogAsync('https://cdnExample.com/Views/LoginDialog.html',{ width: 25,height: 20,displayInIframe: false },function (asyncResult) {
dialog = asyncResult.value;
dialog.addEventHandler(Office.EventType.DialogMessageReceived,ProcessMessage);
});
function ProcessMessage(arg) {
if (arg.message == 'Initialized')
dialog.messageChild(message);
else if (arg.message.indexOf('id_token') > -1) {
dialog.close();
const loginRequest = {
scopes: scopes,loginHint: 'myEmail@test.com'
};
// I have declared this msal var on page load,not included in this sample
msal.acquireTokenSilent(loginRequest).then(function (response) {
accessToken = response.accessToken;
ShowLoadingSpinner('Loading...');
$('#loading').children().show();
$('#welcome').hide();
SetupApp();
res(response);
}).catch(function (res) {
console.log(error);
});
}
}
登录对话框.html
if (window.location.hash.indexOf('id_token=') > -1) {
Office.onReady(function () {
if (Office.context.ui)
Office.context.ui.messageParent(window.location.hash);
});
return;
}
Office.context.ui.addHandlerAsync(
Office.EventType.DialogParentMessageReceived,OnMessageFromParent);
Office.context.ui.messageParent('Initialized');
} catch (e) {
Office.context.ui.messageParent('Error');
}
const config = {
auth: {
clientId: 'xxx-xx-xx-xx',redirectUri: "https://cdnExample.com/Views/LoginDialog.html",//defaults to application start page
//postLogoutRedirectUri: "your_app_logout_redirect_uri"
},cache: { cacheLocation: 'localStorage' }
};
var scopes = ["mail.send","mail.readWrite","user.read"];
const loginRequest = {
scopes: scopes
}
const myMsal = new Msal.UserAgentApplication(config);
function authCallback(error,response) {
console.log('authCallback' + response);
console.log('authCallback' + error);
//handle redirect response
}
myMsal.handleRedirectCallback(authCallback);
myMsal.loginRedirect(loginRequest);
值得注意的是,我使用的是 msal 1.4.6。对此的任何见解都非常感谢,因为这是该应用程序的一个问题,该应用程序已经与客户一起使用。谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。