Daniel Rearden
Daniel Rearden

Reputation: 84687

Instagram redirect URI only handled as Android intent when using custom scheme

I'm trying to authenticate with Instagram in my Android app. As others have noticed, when I assign a redirect URI in the Instagram dashboard, I can only use http or https as the scheme. When the redirect is sent, though, my app doesn't recognize it and my browser attempts to resolve the URI as normal.

Here's the interesting bit: when I use my webpage as the redirect URI, and in the page's code force a redirect to a URI with a custom scheme (like "myapp" instead of "http"), the app recognizes it just fine. Of course, I lose all the authentication details in the process, so this is largely useless, but it does point to the scheme as the culprit (and naturally that's the one thing I can't change).

Here's my intent-filter:

<intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:scheme="https"/>
            <data android:host="oauth2redirect.aggro"/>
        </intent-filter>

I've played around with different combinations of data elements, like adding pathPrefix, with no result. The only way I can get the app to receive the intent is to change the scheme to something other than http or https.

Short of figuring out some script to run on the page to forward the necessary headers and payload with the redirect, is there a workaround for this?

EDIT: Still looking for a workaround. However, it does look like this is the intended behavior for links in Chrome for Android.

Upvotes: 0

Views: 618

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84687

Well, for anyone in the same boat, here's what I ended up doing: I set up my intent filter using my custom scheme and URI (i.e. myapp://oauth2redirect or whatever unique URI you want). Then for the redirect URI, I set it to my personal webpage. In the body of the page, I included the following script:

<script type="text/javascript">
    var target = "myapp://oauth2redirect/?" + window.location.search.substring(1);
    window.location.href = target;
</script>

This solved the problem, although it means maintaining whatever page you're using for this purpose. Unless Instagram makes it possible to enter custom schemes, I don't see another option.

Upvotes: 1

Related Questions