alexziskind1 / nativescript-oauth2

Other
86 stars 93 forks source link

Facebook "Not now" Button Causes Successful Redirect #72

Open ScottAtRedHawk opened 5 years ago

ScottAtRedHawk commented 5 years ago

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

On iOS and Android using Facebook login, when a user taps the "Not now" button below the blue "Log in" button, the WebView redirects to the URL defined in the redirectUri property when initializing the Facebook provider. This is reproducible with the demos for this plugin as well. Is there a way to stop the app from redirecting if the user taps "Not now" and just navigating back to whatever page in the app the user was on before?

Screenshot

Is there any code involved?

No.

PS - @alexziskind1 Great YouTube channel! I watch all your new videos. Keep up the great work!

ScottAtRedHawk commented 5 years ago

I'm seeing these two lines in the console when I click the "Not now" button:

WebView loadStarted https://www.facebook.com/connect/login_success.html?error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied&state=abcd&locale2=en_US&refid=9#_=_
WebView loadFinished https://www.facebook.com/connect/login_success.html?error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied&state=abcd&locale2=en_US&refid=9#_=_

Is there a way to intercept that URL and return or throw an error and close the web view?

odedBartov commented 4 years ago

a little late, but i managed to workaround this problem (i faced it too). go to node_modules -> nativescript-oauth2 -> tns-oauth-login-webview-controller. on function "pageLoadStarted" (line 74) you should add a check if the user cancelled the request. i did it as follow: before:

pageLoadStarted(args) {
        console.log("WebView loadStarted " + args.url);
        if (args.url.startsWith(this.loginController.client.provider.options.redirectUri)) {
            if (global.isAndroid && args.object && args.object["stopLoading"]) {
                args.object["stopLoading"]();
            }
            this.resumeWithUrl(args.url);
        }
    }

after:

pageLoadStarted(args) {
        console.log("WebView loadStarted " + args.url);
        if (args.url.startsWith("https://www.facebook.com/connect/login_success.html?error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied")) {
            this.loginController.frame.goBack();
        }
        if (args.url.startsWith(this.loginController.client.provider.options.redirectUri)) {
            if (global.isAndroid && args.object && args.object["stopLoading"]) {
                args.object["stopLoading"]();
            }
            this.resumeWithUrl(args.url);
        }
    }

this way when the user clicks "not now" an error will be thrown and you will catch it in your component