Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instagram API: force prompt during authentication

Is there a way for the instagram auth(login) to always ask for authentication? This is skipped when the user is logged in and has already authorized the app.

It would be something like twitter's use_authorize=true or google's approval_prompt=force.

like image 455
index Avatar asked Jul 03 '14 09:07

index


2 Answers

I believe that the most simple way is to use next url:

https://instagram.com/accounts/logoutin/?force_classic_login=&next=URLENCODED_INSTAGRAM_OAUTH_URI_PATH_WITH_YOUR_DATA

For example:

window.location.assign('https://instagram.com/accounts/logoutin/?force_classic_login=&next=' + encodeURIComponent('/oauth/authorize/?response_type=code&scope=public_content+follower_list+comments&client_id='+ YOUR_IG_CLIENT_ID + '&redirect_uri='+encodeURIComponent(YOUR_REDIRECT_URI)));

Please take a note that your redirect uri should be encoded twice

like image 191
listar Avatar answered Nov 17 '22 05:11

listar


I managed to get it working:

I try loading an image with the url of the instagram logout page before opening the authorize popup.
Something like this (coffeescript):

windowOpen = ->
    window.open("/instagram/authorize?...")

if forceLogin
    tryLogout().always ->
        windowOpen()

And the tryLogout function (setTimeout 10seconds as a fallback)

tryLogout: ->
    deferred = $.Deferred()
    logOutImg = new Image()

    logOutImg.onerror = ->
        deferred.resolve()
    logOutImg.onload = ->
        deferred.resolve()

    logOutImg.src = 'https://instagram.com/accounts/logout/'

    setTimeout(->
        deferred.reject()
    , 10000)

    return deferred.promise()
like image 36
nicolast Avatar answered Nov 17 '22 07:11

nicolast