Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OAuth (Instagram) without refresh

I have a single page javascript application, and I'm wondering if I can authenticate the user on Instagram without refreshing the page. I'd like to try to do something similar to the Facebook connect using javascript, where a Facebook dialog opens in a popup then calls a callback script after.

Here's what I'm thinking it would do...

  1. On click, opens a dialog (popup) window where the user logs in to Instagram and the app is granted permission.
  2. In the popup window, the user is redirected back to my website where my website curls to Instagram to get the access_token, then sets the access token in the user's session or as a cookie.
  3. Somehow...the main application needs to recognize when the access token has been set. This is the point I'm really not sure about. Would I use a timer to keep making calls back to the server to check for it? Does anyone have any better ideas for detecting it? Would it work better to set it in a cookie?

I thought I'd ask here first before I start coding incase anyone had any ideas as to if this would/wouldn't work, or other suggestions! Maybe this already exists and I'm missing something?

Thanks in advance :-)

like image 380
Sabrina Leggett Avatar asked Sep 12 '12 23:09

Sabrina Leggett


1 Answers

It ended up being super easy to do this with a popup using the comments from tdun and Jan. Thanks guys! Used the Instgram class from 9lessons, and used window.opener.processAuthData(authData) to call back to the original window. And I did have to do a refresh, but it was in the popup window, not in the main app window, which was what I was going for.

like image 53
Sabrina Leggett Avatar answered Oct 20 '22 09:10

Sabrina Leggett