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

Cant make firebase auth works on cordova. Error: 403 disallowed_useragent #507

Closed
calebeaires opened this issue Feb 13, 2018 · 16 comments
Closed
Assignees

Comments

@calebeaires
Copy link

Environment

  • Operating System version: OSx / Android / Cordova
  • Firebase SDK version: 4.9.2
  • Firebase Product: auth

Problem

Firebase auth on cordova does not works event if with all setup asked on firebases documention.

I have deeply follow the instructions to implement Auth on cordova apps as this tutorial: https://firebase.google.com/docs/auth/web/cordova?handle_the_sign-in_flow_with_the_firebase_sdk

Steps to reproduce:

  1. Create dynamic links
  2. Install all plugins
  3. Update config.xml with the correct code/links/firebase app
  4. Using cordova 8 and last ionic
  5. Put firebase on index.html
  6. Setup its configuration with appkey, auth urls and everthing firebase consoles ask to do.

Relevant Code:


        firebase.auth().signInWithRedirect(provider).then(function () {
            console.log(3333)
            firebase.auth().getRedirectResult().then(function(result) {
              // This gives you a Google Access Token.
              // You can use it to access the Google API.
              var token = result.credential.accessToken;
              // The signed-in user info.
              var user = result.user;
              // ...
              console.log(user)
            }).catch(function(error) {
              // Handle Errors here.
              console.log(error)
              var errorCode = error.code;
              var errorMessage = error.message;
            });
        })

Screenshot

screen shot 2018-02-13 at 06 51 28

@google-oss-bot
Copy link
Contributor

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@calebeaires
Copy link
Author

What I have missed. I tried to give all information I could. May you tell me what I am missing 👍

@bojeil-google
Copy link
Contributor

This OAuth redirect must be getting processed in a webview. It should normally go through a chrome custom tab. You must not have installed the correct plugin: cordova-plugin-browsertab

We have noticed that the latest version of ionic in iOS renders the page in a http://localhost locally hosted page which then triggers the regular web flow causing this to break. This is a known issue. Are you noticing the same pattern in your case?

@DanielGibbsNZ
Copy link

DanielGibbsNZ commented Jun 2, 2018

I am having a similar issue on iOS. I have followed all the instructions in the documentation and once I grant access (using Google sign-in) in Safari, it redirects to the URL http://localhost:8080/var/containers/Bundle/Application/APP_UUID/MyApp.app/www/index.html, which doesn't load anything.

I managed to solve the issue by adding the following line to my config.xml:

<preference name="CordovaWebViewEngine" value="CDVUIWebViewEngine" />

@superbigsoft
Copy link

image

As commented by @bojeil-google this is a known issue for ionic wkwebview which is using http instead of file protocol.

I tried to work around by changing the 'file' into 'http' in this file "packages/auth/src/utils.js" > function "isAndroidOrIosFileEnvironment" and it's working but not sure if it would cause any other issue.

@hectorggp
Copy link

hectorggp commented Sep 17, 2018

This OAuth redirect must be getting processed in a webview. It should normally go through a chrome custom tab. You must not have installed the correct plugin: cordova-plugin-browsertab

We have noticed that the latest version of ionic in iOS renders the page in a http://localhost locally hosted page which then triggers the regular web flow causing this to break. This is a known issue. Are you noticing the same pattern in your case?

@bojeil-google Can you indicate the solution of this issue, please?

@eladcandroid
Copy link

I tried to use an other user agent and the page opened but then I need to login into google accounts manually.. any solution for that?

@corysmc
Copy link

corysmc commented Nov 5, 2018

As commented by @bojeil-google this is a known issue for ionic wkwebview which is using http instead of file protocol.

@superbigsoft / @bojeil-google do you have a link to the known issue?

Also did you get it working inside wkwebview by only changing those lines? I changed file: to http: which made it so that the authentication opens in it's own tab (rather than pushing out to safari) but it hangs up after I log in with Google. I can't get it to close the view and return to my app.

Digging further, without wkwebview cordova makes a call to a URL that is formatted like this:
mybundleid://google/link?deep_link_id=https%3A%2F%2Fmy-app.firebaseapp.com....

Whereas with @superbigsoft's hack of removing 'file' and replacing 'http' (with wkwebview: I'm using capacitor with cordova plugins) I get this URL:
my-app.firebaseapp.com/__/auth/handler?...etc

Which leads me to believe that more changes need to be made for firebase to detect if it is in a hybrid/native environment. Right now firebase is trying to detect its environment. It sure would be nice if I could just tell firebase what environment it's in.

@nadhir-falta
Copy link

@corysmc I have the same issue using firebase and angular 7.
were you able to find any work around? can you please share what you have ?
Thank you!

@corysmc
Copy link

corysmc commented Feb 8, 2019

@nadhir-falta we ended up using firebase native authentication for ios and android, and used capacitor to make the call from the webview.

@scriptPilot
Copy link

@corysmc - Do you want to share your solution with us?

@corysmc
Copy link

corysmc commented Jul 8, 2019

It's a pretty big hack @scriptPilot.
Basically if I detect I'm on a native device, I hide the social logins from firebase UI, and add my own buttons for native login.

@scriptPilot
Copy link

@corysmc - Means your own buttons with native language or own auth flow in web view?

@corysmc
Copy link

corysmc commented Jul 10, 2019

our html buttons call a capacitor plugin that uses the native sdks to authenticate

@PsiOps
Copy link

PsiOps commented Sep 27, 2019

Please have a look at this StackOverflow answer: It could solve this issue (or work around it).

@MeghaB MeghaB self-assigned this May 4, 2020
@MeghaB
Copy link
Contributor

MeghaB commented May 14, 2020

Closing this, since there's been no activity since the StackOverflow answer was submitted. Please feel free to re-open if this is still an issue.

@MeghaB MeghaB closed this as completed May 14, 2020
@firebase firebase locked and limited conversation to collaborators Jun 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests