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

Error: Unable to process request due to missing initial state. #33

Open
braincomb opened this issue Nov 5, 2021 · 13 comments
Open

Error: Unable to process request due to missing initial state. #33

braincomb opened this issue Nov 5, 2021 · 13 comments
Assignees
Labels
help wanted Extra attention is needed package: authentication platform: android Android platform

Comments

@braincomb
Copy link

braincomb commented Nov 5, 2021

Is your feature request related to a problem? Please describe:

There's currently an issue with the authentication flow where in some cases upon calling the Callback URL (default myapp.firebaseapp.com/__/auth/handler provided by Firebase) the external browser will show this error:
"Unable to process request due to missing initial state. This may happen if browser sessionStorage is inaccessible or accidentally cleared."

There's a GitHub issue open for this: firebase/firebase-js-sdk#4256

From my own testing and troubleshooting I've concluded that in my experience this only happens with mobile Firefox. However, if we go to Firefox advanced settings and toggle "Open Links in App" to on, then the authentication proceeds as normal by redirecting back to the Capacitor app. Other browsers tested such as Chrome, Brave and Samsung Internet all work normally.

This leads me to believe that if force the authentication to open in a WebView, then we normalize the experience for all users, regardless of what their default web browser is set to.

Describe the solution you'd like:

If possible, force (or as configurable option) the authentication flow to go through @capacitor/browser instead of an external browser.

Additional context:

I'm unsure if the solution belongs to this plugin, but I thought this was a good place to start. Any advice appreciated!

@robingenz
Copy link
Member

Hi @braincomb,
interesting thought. I need to do some research.
On which platform does the problem occur? Native Android, Native iOS or Web?

@robingenz robingenz self-assigned this Nov 5, 2021
@braincomb
Copy link
Author

Hi @robingenz ,

This was tested on a physical Android device running your plugin with native auth. Firefox was the only browser that showed the error and did not redirect back to the app.

For iOS I was only able to test with XCode emulator, no issues there.

EDIT: I'd like to add that this only happens with Twitter provider. My guess is that any provider that uses a Callback URL will open an external browser for the redirect. Google provider works fine which opens a popup on the phone.

@robingenz robingenz added the platform: android Android platform label Nov 6, 2021
@robingenz
Copy link
Member

Thank you for the information.
I was able to reproduce the issue with Twitter and GitHub Sign In on Android.
I have created a Firebase App Check plugin for Capacitor (see here), since that was a suggested solution in the thread you linked. It is still a development version. Unfortunately it did not help in my case.
It works in my Firefox only if I manually enable the Open links in apps option in the settings (see mozilla support).

Regarding your suggestion: Unfortunately I could not find a way to tell the Firebase SDK which browser to open.
I will leave this issue open and mark it as help wanted. Maybe we will find a solution in the future. Unfortunately, at the moment I have no other ideas how this problem could be solved by the plugin.

@robingenz robingenz added the help wanted Extra attention is needed label Nov 6, 2021
@robingenz robingenz changed the title feat: open authentication flow in in-app Capacitor browser. Error: Unable to process request due to missing initial state. Nov 6, 2021
@braincomb
Copy link
Author

@robingenz Thank you for looking into this.

Interestingly enough, step 3 under Handle the sign-in flow with the Firebase SDK from the Authenticate Using Twitter on Android actually states:

Note that unlike other FirebaseAuth operations, this will take control of your UI by popping up a Custom Chrome Tab.

Which from our testing showed it doesn't.

I have also looked at how Facebook authentication behaves since it also uses a callback URL, and noticed that it opens a Custom Tab. Granted some extra configuration needed to be done in XML files.

Would something similar be possible to achieve here for Twitter auth to use a custom tab?

@robingenz
Copy link
Member

@braincomb I am very busy this week. I will have a look at it this weekend/next week.

@robingenz
Copy link
Member

I have also looked at how Facebook authentication behaves since it also uses a callback URL, and noticed that it opens a Custom Tab.

What do you mean exactly? Does a Google Chrome Custom Tab appear even though you have Firefox as your default browser? Or how did you notice that?

Granted some extra configuration needed to be done in XML files.

Which changes were made exactly? Do you have references?

@braincomb
Copy link
Author

What do you mean exactly? Does a Google Chrome Custom Tab appear even though you have Firefox as your default browser? Or how did you notice that?

Yes, exactly, Chrome Custom Tab always opens regardless of what the default browser is.

Which changes were made exactly? Do you have references?

This is from your Facebook Setup documentation: there's an activity for CustomTabActivity which I'm assuming is what makes it use the Custom Tab. But I'm now thinking that this configuration is controlled by either Facebook SDK or Firebase SDK.

Either way, it looks like Firebase documentation claims that a Custom Tab should open for Twitter auth, but that is not the case. I'll see if I can open a bug issue with them.

@hnnweb
Copy link

hnnweb commented Feb 6, 2022

@braincomb You don't have Google Container plugin active? The login won't work with containers.

@robingenz robingenz transferred this issue from robingenz/capacitor-firebase-authentication Mar 23, 2022
@lincolnthree
Copy link

Hi, was a solution ever found to this? We are getting an issue where Facebook Compliance is unable to successfully test our Login integration because they are getting this error -- we can't seem to reproduce it on any other devices. But it's this exact same error.

The login pop-up window just shows them a white screen.

Is there any way to get CapacitorFirebase to use redirect instead of PopUp?

@robingenz
Copy link
Member

Hi, was a solution ever found to this? We are getting an issue where Facebook Compliance is unable to successfully test our Login integration because they are getting this error -- we can't seem to reproduce it on any other devices. But it's this exact same error.

The login pop-up window just shows them a white screen.

Is there any way to get CapacitorFirebase to use redirect instead of PopUp?

Unfortunately there is no solution so far.

Is there any way to get CapacitorFirebase to use redirect instead of PopUp?

  • Android/iOS: not possible
  • Web: not implemented

@lincolnthree
Copy link

lincolnthree commented Oct 21, 2022

  • Android/iOS: not possible

Right.

  • Web: not implemented

Yes, this is the platform I was wondering about. I suppose we could call the Firebase API manually. Any plans for supporting this? Thanks.

@robingenz
Copy link
Member

I suppose we could call the Firebase API manually.

Yes

Any plans for supporting this? Thanks.

Not yet, but feel free to create a feature request and I'll put it on the raodmap.

@lincolnthree
Copy link

Done, thanks: #224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed package: authentication platform: android Android platform
Projects
None yet
Development

No branches or pull requests

4 participants