Hassan Tareq Hassan Tareq - 25 days ago 9
Android Question

Why is custom scheme for redirect_uri for facebook login not working?

Answer to the question: facebook redirect_uri set to ios URL Scheme did not solve my problem.

Trying to implement Facebook login in Android WebView (using Facebook SDK is working, but want to implement it in WebView for some reason):

private void launchFacebookOauth() {

// intent
Intent intent = new Intent(Intent.ACTION_VIEW, getAuthorizationUri());
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
finish();

}

public Uri getAuthorizationUri() {

final String CLIENT_ID = "client_id";
final String RESPONSE_TYPE = "response_type";
final String REDIRECT_URI = "redirect_uri";
final String CODE = "code";


Map<String, String> params = new HashMap<>();
params.put(CLIENT_ID, clientId);
params.put(RESPONSE_TYPE, CODE);
params.put(REDIRECT_URI, redirectUri);


Request request = new Request.Builder().url(AUTHORIZATION_ENDPOINT_URL).build();
HttpUrl.Builder builder = request.url().newBuilder();
for (Map.Entry<String, String> param : params.entrySet()) {
builder.addQueryParameter(param.getKey(), param.getValue());
}
HttpUrl httpUrl = builder.build();

return Uri.parse(httpUrl.toString());
}


When using scheme:
http://
or
https://
for redirect_uri, Android shows dialog to choose from MyTestApp & browser (don't want this behaviour). So, trying to use custom scheme:
fb12345678
& host
hovermind.com


<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="fb12345678" android:host="hovermind.com"/>
</intent-filter> .



redirect_uri: fb12345678://hovermind.com


Getting error in the WebView:


Can't Load URL: The domain of this URL isn't included in the app's
domain. To be load this URL, add all domains and subdomains of your
app to the App Domains field in your app settings .


FYI,
hovermind.com
is added in 'App Domains' section and 'Valid OAuth redirect URIs' section (developers dashboard) . When trying to add
fb12345678://hovermind.com
in Valid OAuth redirect URIs section, Facebook shows error dialog.

How to laucnh my App using custom redirect_uri scheme from WebView (Facebook login) ?


Don't want to use
App Links
either ( min. SDK >= 23 and server config issue )

Answer Source

I could not find any solution or StackOverflow answer & therefore came to the conclusion that use Facebook Login for Android instead of WebView