Skip to content

Commit 50db5c4

Browse files
authored
Merge pull request apache#263 from SailingSteve/CB-14013-InAppBrowser-AllowCustomSchemes
CB-14013: (android) Change the InAppBrowser to allow custom schemes for oAuth
2 parents 013a861 + 42df297 commit 50db5c4

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/android/InAppBrowser.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public class InAppBrowser extends CordovaPlugin {
133133
private boolean hideUrlBar = false;
134134
private boolean showFooter = false;
135135
private String footerColor = "";
136+
private String[] allowedSchemes;
136137

137138
/**
138139
* Executes the request and returns PluginResult.
@@ -1110,6 +1111,29 @@ else if (url.startsWith("sms:")) {
11101111
LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
11111112
}
11121113
}
1114+
// Test for whitelisted custom scheme names like mycoolapp:// or twitteroauthresponse:// (Twitter Oauth Response)
1115+
else if (!url.startsWith("http:") && !url.startsWith("https:") && url.matches("^[a-z]*://.*?$")) {
1116+
if (allowedSchemes == null) {
1117+
String allowed = preferences.getString("AllowedSchemes", "");
1118+
allowedSchemes = allowed.split(",");
1119+
}
1120+
if (allowedSchemes != null) {
1121+
for (String scheme : allowedSchemes) {
1122+
if (url.startsWith(scheme)) {
1123+
try {
1124+
JSONObject obj = new JSONObject();
1125+
obj.put("type", "customscheme");
1126+
obj.put("url", url);
1127+
sendUpdate(obj, true);
1128+
return true;
1129+
} catch (JSONException ex) {
1130+
LOG.e(LOG_TAG, "Custom Scheme URI passed in has caused a JSON error.");
1131+
}
1132+
}
1133+
}
1134+
}
1135+
}
1136+
11131137
return false;
11141138
}
11151139

@@ -1232,4 +1256,4 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, Str
12321256
super.onReceivedHttpAuthRequest(view, handler, host, realm);
12331257
}
12341258
}
1235-
}
1259+
}

www/inappbrowser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
'loadstart': channel.create('loadstart'),
3737
'loadstop': channel.create('loadstop'),
3838
'loaderror': channel.create('loaderror'),
39-
'exit': channel.create('exit')
39+
'exit': channel.create('exit'),
40+
'customscheme': channel.create('customscheme')
4041
};
4142
}
4243

0 commit comments

Comments
 (0)