9

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 :-)

Igy
  • 43,710
  • 8
  • 89
  • 115
Sabrina Leggett
  • 9,079
  • 7
  • 47
  • 50
  • Correct me if I'm wrong, but the FB Javascript SDK auth does do a page refresh *after* a successful authentication. The auth happens in a page popup, then a page refresh is called if the login was successful. – Shane Stillwell Sep 13 '12 at 00:20
  • 3
    check out this link: http://www.9lessons.info/2012/05/login-with-instagram-php.html and you can integrate that into an .ajax() call – tcd Sep 13 '12 at 01:12
  • 2
    See [this question](http://stackoverflow.com/q/9276086/1467115) for how to get data returned from a popup. – Jan Gerlinger Sep 13 '12 at 07:42

1 Answers1

10

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.

Sabrina Leggett
  • 9,079
  • 7
  • 47
  • 50