我正在尝试在我的应用程序中包含某些第三方应用程序的oauth。基本上在按钮上单击“我从后端请求身份验证的URL”。然后,我使用window.open(url)
打开一个新窗口。用户完成此过程后,我的弹出窗口将重定向到回调URL。
现在,我想在重定向到弹出网址后立即关闭弹出窗口。我该怎么办?
function connectToApp() {
loginRequest()
.then(function openNewWindow(res) {
var url = res.data,width = 700,height = 500,left = (screen.width/2) - (width / 2),top = (screen.height/2) - (height / 2),params = 'modal=yes,alwaysRaised=yes,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height;
if(newWindow === null || newWindow.closed) {
newWindow= window.open(url,'newWindow',params);
newWindow.focus();
} else {
newWindow.focus();
}
})
};
完成身份验证后,我将重定向到回调URL到新窗口。我尝试使用window.postMessage
,但不知道如何实现。
- 我要关闭新窗口。
- 我的应用程序如何知道用户已完成身份验证?
- 我不需要重定向到回调URL,因为我只想在身份验证完成后将应用程序中的视图从注销切换为登录。