[ 
https://issues.apache.org/jira/browse/CB-14013?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16436153#comment-16436153
 ] 

ASF GitHub Bot commented on CB-14013:
-------------------------------------

infil00p closed pull request #263: CB-14013: (android) Change the InAppBrowser 
to allow custom schemes for oAuth
URL: https://github.com/apache/cordova-plugin-inappbrowser/pull/263
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index 2b0dbe0fa..9b3388ced 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -133,6 +133,7 @@ Licensed to the Apache Software Foundation (ASF) under one
     private boolean hideUrlBar = false;
     private boolean showFooter = false;
     private String footerColor = "";
+    private String[] allowedSchemes;
 
     /**
      * Executes the request and returns PluginResult.
@@ -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;
         }
 
@@ -1232,4 +1256,4 @@ public void onReceivedHttpAuthRequest(WebView view, 
HttpAuthHandler handler, Str
             super.onReceivedHttpAuthRequest(view, handler, host, realm);
         }
     }
-}
+}
\ No newline at end of file
diff --git a/www/inappbrowser.js b/www/inappbrowser.js
index 7c3e749e8..3619f173f 100644
--- a/www/inappbrowser.js
+++ b/www/inappbrowser.js
@@ -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')
         };
     }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> cordova-plugin-inappbrowser support for custom URL schemes, as needed for 
> oAuth
> -------------------------------------------------------------------------------
>
>                 Key: CB-14013
>                 URL: https://issues.apache.org/jira/browse/CB-14013
>             Project: Apache Cordova
>          Issue Type: New Feature
>          Components: cordova-plugin-inappbrowser
>    Affects Versions: cordova@7.0.0
>            Reporter: Steve Podell
>            Priority: Major
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> A very common usage of the inappbrowser is to open a URL to the apps server, 
> as part of the oAuth flow.  After a secure token is created, the final step 
> in the oAuth flow is to redirect back to the Cordova app, to proceed as 
> authenticated.  At the WeVote open source project we use this to authenticate 
> with Twitter and Facebook, other projects want to authenticate with Google, 
> Whatsapp, Skype, etc. 
> There is a package for React Native react-native-oauth that does this, and I 
> was able to get oAuth working for iOS with 
> cordova-plugin-safariviewcontroller, but there is nothing that is stable, 
> maintained, and working that is equivalent for Android.
> A pull request will follow that uses whitelisted schemes to allow the oAuth 
> redirect to complete through the InAppBrowser.  It is a fairly simple code 
> change, that leads to a simple end user implementation, that should be widely 
> appreciated (based on years of mostly unfulfilled Stack Overflow chatter.)
>  
> This PR builds on  
> [https://github.com/apache/cordova-plugin-inappbrowser/pull/99] and 
> [https://github.com/apache/cordova-plugin-inappbrowser/pull/261] and builds 
> on a good suggestion from *[NGumby|https://github.com/NGumby]* and comments 
> about viability from *[infil00p|https://github.com/infil00p]*
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to