Marty Wallace
Marty Wallace

Reputation: 35734

Instagram app authentication without redirect

I have created an Instagram app. Users can authenticate and then list their uploaded images.

Unfortunately the authentication process requires a redirect and I would like to do this without the redirect.

Is it possible?

Upvotes: 1

Views: 5305

Answers (3)

Matt Pinkston
Matt Pinkston

Reputation: 1630

You do not necessarily have to redirect (in the traditional sense)!

After issuing your initial request, e.g. https://api.instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=code

Instagram does indeed respond with a 302 redirect to the URL specified in the redirect_uri and that URI will have appended on to it either a code or access_token parameter depending on the type of flow you are using (specified by your original response_type parameter)

If your web client is capable of intercepting the redirect request before it fires, you can collect the 'code' or 'access_token' parameter from the redirect url and continue as desired.

For example: with iOS, there's a UIWebView delegate method "shouldStartLoadWithRequest" that you can use to examine the redirect URI and cancel the actual request before it loads. Since the redirect URI has what you're after, you can basically delegate any further processing to a background thread (or whatever) and continue as you please.

Upvotes: 1

Arthur Antunes
Arthur Antunes

Reputation: 9

The Instagram API uses the OAuth 2.0, keep in mind that all requests to the API must be made over SSL (https://).

The redirect uri specifies where we redirect users after they have chosen whether or not to authenticate your application. This uri is needed to capture the API response.

You have two ways for authenticate:

1.Server-side:

  1. Direct your user to authorization URL.

    Once a user authorizes your application, Instagram redirect to your redirect uri with a code parameter to use for obtain the user token.

  2. Request the user access token:

    Now you need to exchange the code you have received in the previous step for an access token. You have to POST this code, along with some app identification parameters.

    If successful, this call will return a OAuth Token.

2.Client-Side

  1. Direct your user to authorization URL.

  2. Receive the access token via the URL:

    Once the user has authenticated and then authorized your application, Instagram redirect to your redirect uri with the access token in the url fragment.


Instagram info: https://www.instagram.com/developer/authentication/

Upvotes: 0

krisrak
krisrak

Reputation: 12952

No, its not possible, you have to use Oauth to login and get access_token, this is only one time, you can store access_token and use it to make API calls, if it fails with invalid access_token, then you have ask user to login again and get updated access_token

Upvotes: 0

Related Questions