Reputation: 319
I'm trying to get Facebook to redirect back to my Unity application (running on android) after a call to https://facebook.com/v2.8/dialog/oauth. I've created a custom URL scheme in my android app like myApp://. However, when I attempt to send the OAuth request through to facebook, it tells me that the redirect_uri is not supported. I've tried to add my custom URL to my Facebook app's OAuth settings, but it says it is not a valid URL (which makes sense, as it's technically not).
The request:
var url = string.Format("https://facebook.com/v2.8/dialog/oauth?client_id={0}&response_type=token&redirect_uri={1}", "MYAPPID", "redfish%3A%2F%2Ffacebooklogin");
My app's AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:icon="@drawable/app_icon" android:label="@string/app_name">
<activity android:name=".MainActivity" android:label="@string/app_name" android:launchMode="singleTask" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="sensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<data android:scheme="redfish" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
</manifest>
Code for catching the redirect in unity:
public class OnAcessToken : MonoBehaviour {
void OnAccessToken(string accessToken)
{
Debug.Log("Received access token: " + accessToken);
SceneManager.LoadScene("FileSelect");
}
}
The class OnAccessToken
is hit using a custom library generated by the instructions at http://oferei.com/2013/06/serverless-instagram-authentication/.
What I'm asking is how to I get Facebook to allow my custom URL scheme as a valid redirect_uri? Or am I going about this the wrong way.
Upvotes: 0
Views: 476
Reputation: 319
Ended up answering my own question with some additional research. Using a custom URL schema for android isn't necessary, and according to Google, the practice of using something like myApp://
is being deprecated.
Instead, my schema is now http://myApp.auth
, and the corresponding intent filter looks like this:
<intent-filter>
<data android:scheme="http"
android:host="redfish.auth/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Now, in Facebook's settings, I can set http://redfish.auth
as an acceptable OAuth URL, and it won't complain since it has the http
schema. This overrides the host rather than the schema, so it works in Chromium browsers (previously did not because of the aforementioned Chrome standards).
So, when I make a call to http://redfish.auth/facebooklogin
, it redirects back to my app!
References: https://developer.android.com/guide/components/intents-filters.html
Upvotes: 1