manuzhang
manuzhang

Reputation: 3025

How to intercept a redirection in a popup window?

I'm writing a Chrome App which needs user's authorization. Say, a user wants to share a tweet to a website and click on a button. I'll firstly search for the user's access token to that website in the Chrome storage. If not available, I' ll open a window with

window.open(url);

where the url is an authorization API provided by the website. Then the user will put in login info (username / password) and be redirected to a callback concatenated by a code required for the access token.

I don't want the user to be redirected and I need that code. How could I intercept that redirection, fetch the code and close the window after a user has finished authorization?

Upvotes: 3

Views: 1677

Answers (2)

JohnP
JohnP

Reputation: 50019

OAuth flows (as well as other redirection control flows) are controlled using match patterns in chrome. Match patterns allow you to hook into the flow by listening to certain urls being triggered by the browser.

More about it here - http://developer.chrome.com/extensions/match_patterns.html

Upvotes: 1

Collin Grady
Collin Grady

Reputation: 2243

If the callback URL is under your control, could you try using some javascript with window.opener to pass the code back, then window.close() the popup?

Upvotes: 1

Related Questions