callback to parent window oAuth

1,472 views
Skip to first unread message

deb123

unread,
Mar 15, 2010, 9:50:03 AM3/15/10
to Twitter Development Talk
I am trying to open the "Accept/Deny" window in a new window. I want
the callback to come back to the parent window. If I use window.open,
I get the pop up but the callback comes back to the child window. I
want the child window to close when the use hits the Accept or Deny
and the callback to come to the parent window.
How do I make this happen?
Thanks,
D

Taylor Singletary

unread,
Mar 15, 2010, 9:58:02 AM3/15/10
to twitter-development-talk
You can't accomplish it exactly the way you want to, but you can do this:

1) Set the OAuth callback to a URL that's still on your domain,
something specific that's purpose is only to collect the callback
details and quickly return a 200 status.
2) In your parent window, occasionally poll the status of the child
window -- when it's on Twitter.com you won't have access to its
window.location.
3) When the window.location is on your callback URL and the same
domain as the parent window, you'll be able to close the pop-up window
and then change the state of the originating window in turn.

Taylor Singletary
Developer Advocate, Twitter
http://twitter.com/episod

Michael Steuer

unread,
Mar 15, 2010, 2:35:47 PM3/15/10
to twitter-deve...@googlegroups.com
There's better ways of doing this actually, that doesn't require polling of
any kind...

In your pop up, when Twitter redirects to your callback URL:

- process the Oauth tokens etc so that your user's session is authenticated
- set the parents window location to whereever it needs to go (logged in
view of your app), using window.opener.location.href = "whatever"
- close the popup (window.close)

On 3/15/10 5:58 AM, "Taylor Singletary" <taylorsi...@twitter.com>
wrote:

deb123

unread,
Mar 15, 2010, 3:41:55 PM3/15/10
to Twitter Development Talk
Thanks for the reply. My callback URL is a servlet. I can get all the
session info there.
How do I then call a javascript to close the child window and forward
the parent window?
I am not sure how do I go to client side from the servlet.


On Mar 15, 1:35 pm, Michael Steuer <mste...@gmail.com> wrote:
> There's better ways of doing this actually, that doesn't require polling of
> any kind...
>
> In your pop up, when Twitter redirects to your callback URL:
>
> - process the Oauth tokens etc so that your user's session is authenticated
> - set the parents window location to whereever it needs to go (logged in
> view of your app), using window.opener.location.href = "whatever"
> - close the popup (window.close)
>

> On 3/15/10 5:58 AM, "Taylor Singletary" <taylorsinglet...@twitter.com>


> wrote:
>
> > You can't accomplish it exactly the way you want to, but you can do this:
>
> > 1) Set the OAuth callback to a URL that's still on your domain,
> > something specific that's purpose is only to collect the callback
> > details and quickly return a 200 status.
> > 2) In your parent window, occasionally poll the status of the child
> > window -- when it's on Twitter.com you won't have access to its
> > window.location.
> > 3) When the window.location is on your callback URL and the same
> > domain as the parent window, you'll be able to close the pop-up window
> > and then change the state of the originating window in turn.
>
> > Taylor Singletary
> > Developer Advocate, Twitter
> >http://twitter.com/episod
>

Michael Steuer

unread,
Mar 15, 2010, 5:34:09 PM3/15/10
to twitter-deve...@googlegroups.com
First off, you should first refresh the parent window and THEN close the
child window (once you close the child window execution of your javascript
will stop).

I would presume you can simply output javascript to the client, and it will
get executed. So in your mark up that your servlet renders, simply add a
<script type="text/javascript"> element containing the javascript that
refreshes the location of the window.opener window and subsequently closes
the child window..

Reply all
Reply to author
Forward
0 new messages