Skip to content

Commit 6bcdb9b

Browse files
authored
Merge pull request #120 from shohey1226/add_twitter_cancelation_handling
added handling for cancelation
2 parents 40b71a3 + 0a4dfe4 commit 6bcdb9b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

android/src/main/java/io/fullstack/oauth/OAuthManagerDialogFragment.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
import im.delight.android.webview.AdvancedWebView;
3737

38+
import java.util.regex.Matcher;
39+
import java.util.regex.Pattern;
40+
3841
public class OAuthManagerDialogFragment extends DialogFragment implements AdvancedWebView.Listener {
3942

4043
private static final int WEBVIEW_TAG = 100001;
@@ -195,6 +198,15 @@ public void onReceivedError(WebView view, int code, String desc, String failingU
195198

196199
private boolean interceptUrl(WebView view, String url, boolean loadUrl) {
197200
Log.i(TAG, "interceptUrl called with url: " + url);
201+
202+
// url would be http://localhost/twitter?denied=xxx when it's canceled
203+
Pattern p = Pattern.compile("\\S*denied\\S*");
204+
Matcher m = p.matcher(url);
205+
if(m.matches()){
206+
Log.i(TAG, "authentication is canceled");
207+
return false;
208+
}
209+
198210
if (isCallbackUri(url, mController.getCallbackUrl())) {
199211
mController.getAccessToken(mWebView, url);
200212
return true;
@@ -326,4 +338,4 @@ public static int convertDpToPixel(float dp, Context context){
326338
float px = dp * ((float)metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT);
327339
return (int)px;
328340
}
329-
}
341+
}

0 commit comments

Comments
 (0)