Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 512
Lukasz Moren Avatar asked Nov 29 '11 10:11

Lukasz Moren


People also ask

What does redirect URI do in OAuth2?

A redirect URI, or reply URL, is the location where the authorization server sends the user once the app has been successfully authorized and granted an authorization code or access token.

How does OAuth redirect work?

If the request is valid and the user grants the authorization request, the authorization server generates an authorization code and redirects the user back to the application, adding the authorization code and the application's “state” value to the redirect URL.

What is redirect URI in OAuth2 Google?

The redirect URIs are the endpoints to which the OAuth 2.0 server can send responses. These endpoints must adhere to Google's validation rules. For testing, you can specify URIs that refer to the local machine, such as http://localhost:8080 .

Can OAuth be hacked?

Perhaps the most infamous OAuth-based vulnerability is when the configuration of the OAuth service itself enables attackers to steal authorization codes or access tokens associated with other users' accounts. By stealing a valid code or token, the attacker may be able to access the victim's data.


1 Answers

I think popup you can close by

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 ( main window ) just checks every time if the popup still live and if win.closed returns true - the main window reloads

Hope it will help somebody

like image 107
Maksym Avatar answered Oct 04 '22 04:10

Maksym