'Closing OAuth 2.0 popup window after redirect

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?

Thanks in advance for any help.



Solution 1:[1]

So IDK if this will help anyone, but instead of refreshing the page, you probably want to be checking your server to see if the user connected or not via a re-occurring timeout, and then use .close() after they did. An added benefit here is that you'll now have the data to continue on with the registration process.

Solution 2:[2]

First, on the main window you need to open an new popup window, this will open a centered window:

$('.openwindow').click(function(){
    var uri = 'https://my-oauth-server-url'
    var left = (screen.width/2 - 400)
    var top = (screen.height/2 - 350)
    window.open(uri, 'oauth window','resizable=yes, width=800, height=700, top='+top+', left='+left)
});

Once you have the popup window opened you will need to reload the main window (opener window) with new content and close the popup window.

window.opener.location.replace('/oauthok');
window.close();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Agamemnus
Solution 2 lvicedo