重定向后关闭 OAuth 2.0 弹出窗口 [英] Closing OAuth 2.0 popup window after redirect

查看:116
本文介绍了重定向后关闭 OAuth 2.0 弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在弹出窗口中将用户重定向到 OAuth 2.0 授权端点.在 OAuth 2.0 授权服务器使用授权码重定向用户后,关闭此弹出窗口并刷新主窗口的最佳方法是什么?

I redirect user to the OAuth 2.0 authorization endpoint in popup window. What is best way to close this popup and refresh main window after OAuth 2.0 authorization server redirects user back with an authorization code?

在此先感谢您的帮助.

推荐答案

我觉得弹窗可以关闭

parent.close();

为了刷新主窗口,我使用了这个技巧:

And to refresh main window I used this trick:

$(function() {
    var win;
    var checkConnect;
    var $connect = $("#some_button");
    var oAuthURL = "http://example.com/account/_oauth?redirect_url=" + redirect_url;
    $connect.click(function() {
        win = window.open(oAuthURL, 'SomeAuthentication', 'width=972,height=660,modal=yes,alwaysRaised=yes');
    });

    checkConnect = setInterval(function() {
        if (!win || !win.closed) return;
        clearInterval(checkConnect);
        window.location.reload();
    }, 100);
});

Opener(主窗口)每次只检查弹出窗口是否仍然存在,并且 win.closed 返回 true - 主窗口重新加载

Opener ( main window ) just checks every time if the popup still live and if win.closed returns true - the main window reloads

希望对大家有所帮助

这篇关于重定向后关闭 OAuth 2.0 弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆