Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-14013: (android) Change the InAppBrowser to allow custom schemes for oAuth #263

Merged
26 changes: 25 additions & 1 deletion src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public class InAppBrowser extends CordovaPlugin {
private boolean hideUrlBar = false;
private boolean showFooter = false;
private String footerColor = "";
private String[] allowedSchemes;

/**
* Executes the request and returns PluginResult.
Expand Down Expand Up @@ -1110,6 +1111,29 @@ else if (url.startsWith("sms:")) {
LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
}
}
// Test for whitelisted custom scheme names like mycoolapp:// or twitteroauthresponse:// (Twitter Oauth Response)
else if (!url.startsWith("http:") && !url.startsWith("https:") && url.matches("^[a-z]*://.*?$")) {
if (allowedSchemes == null) {
String allowed = preferences.getString("AllowedSchemes", "");
allowedSchemes = allowed.split(",");
}
if (allowedSchemes != null) {
for (String scheme : allowedSchemes) {
if (url.startsWith(scheme)) {
try {
JSONObject obj = new JSONObject();
obj.put("type", "customscheme");
obj.put("url", url);
sendUpdate(obj, true);
return true;
} catch (JSONException ex) {
LOG.e(LOG_TAG, "Custom Scheme URI passed in has caused a JSON error.");
}
}
}
}
}

return false;
}

Expand Down Expand Up @@ -1232,4 +1256,4 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, Str
super.onReceivedHttpAuthRequest(view, handler, host, realm);
}
}
}
}
3 changes: 2 additions & 1 deletion www/inappbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
'loadstart': channel.create('loadstart'),
'loadstop': channel.create('loadstop'),
'loaderror': channel.create('loaderror'),
'exit': channel.create('exit')
'exit': channel.create('exit'),
'customscheme': channel.create('customscheme')
};
}

Expand Down