Firebase-js-sdk: BUG; Auth raise error (A network error...) on iOS WKwebview

Created on 21 Mar 2018  路  19Comments  路  Source: firebase/firebase-js-sdk

[REQUIRED] Describe your environment

  • Operating System version: iOS 11.2 WKWebview
  • Firebase SDK version: 4.12
  • Firebase Product: auth

[REQUIRED] Describe the problem

loginwithemailand password fail with error -> A network error (such as timeout, interrupted connection or unreachable host) has occurred.

Steps to reproduce:

just embed a html page on iOS WKWebview with a login button

Relevant Code:

Please help with any suggestion or work around...

auth

Most helpful comment

I am still seeing auth errors logged on our Sentry instance for iOS.

All 19 comments

Network errors are incredibly hard to debug as they are usually related to the environment or local conditions. I speculate this is related to navigator.onLine bug (previously reported) which is some cases returns false when the network connection is available.

@bojeil-google
i have a confirmation from firebase support the exist of this bug on WKWebview...

the navigator.onLine return true but login fail with mentioned error.
and on the other hand, firestore run successfully with all functionality on the same environment. and never return error related to connection..

Any help, work around.. ?

Again, I cannot debug this. I have no idea what firestore uses. We don't share the same mechanism for processing http requests.
There is no bug with WKWebview (you probably misunderstood or miscommunicated the issue with support), otherwise we would hear a lot of issues with WKWebView in general.
There are currently 2 issues close to yours:

  1. navigator.onLine incorrectly returning false
  2. bug with ionic latest version which uses WKWebView instead of UIWebView which cause OAuth sign in to fail (only that flow).

None of these match your report.

To clarify the ionic iOS issue is not specific to WKWebView. It is due to them using a locally hosted server (http://localhost) to serve the files instead of (file://) as they used to.

@bojeil-google
this shared minimal test case
https://drive.google.com/drive/folders/10zv-OaHduIuP2q347TCIVxKe8kCbAj0z?usp=sharing
please have look
you need just to set the config of firebase project at line 38 from file firebaseTest.js

firebase support confirm the replicate of my case exactly...

In general you should go through support for similar requests. GitHub is not really the channel for similar support questions. I will see if I have time to look into this in the coming weeks. Thanks.

@bojeil-google
i am not using ionic.. i just load html with firebase auth and firestore javascript on WKWebview..

NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"folder/index" ofType:@"html"];

NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSString * basePath = [urlAddress substringToIndex:[urlAddress length] - 11]; //   (/index.html) length 11
NSURL *baseurl = [NSURL fileURLWithPath:basePath];
[self.webView loadFileURL:url allowingReadAccessToURL:  baseurl];

i hope that you look at that case
Thanks for your time

@bojeil-google
Hello,
I found the source of the error...

we are using allowFileAccessFromFileURLs on WKWebview, this to enable access to local files in WKWebview environment... if we comment this firebase login will work from SDK normally; but this will stop the application from working and read the other files on xCode project..

Note that navigatore.onLine() is always true on both cases.

[self.webView.configuration.preferences setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];

Any guide from this point?
Thanks

@bojeil-google
Hello, i hope that you can guide me with this;

when doing a REST request from WKWebView
https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=myKey

1- on normal situation request headers {origin: null}; and request return success and i get the token.

2- on XCode if we add
[self.webView.configuration.preferences setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];
on this case request header {origin: file://} ; accordingly request fail with the following error:

XMLHttpRequest cannot load https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=mykey. Preflight response is not successful.

any comments or guide will be helpful..
thanks

We finally got the cURL command for this. It turns out there is some issue when the preflight OPTIONS request contains an origin with a file:// URL. It's weird that it is manifesting here and now. This is not a client SDK issue. We have filed the bug with the Auth team's backend engineers. You can follow up with the support team on that.

Hello @bojeil-google

Yes they ask me for curl couple days ago and i sent it yesterday...

This fail only when i set [self.webView.configuration.preferences setValue:@true forKey:@"allowFileAccessFromFileURLs"];

curl 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=aaaaaaa' \
-XOPTIONS \
-H 'Access-Control-Request-Headers: cache-control,content-type' \
-H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C107' \
-H 'Origin: file://' \
-H 'Access-Control-Request-Method: POST'

and this the normal one that pass on WKWebview when i remove [self.webView.configuration.preferences setValue:@true forKey:@"allowFileAccessFromFileURLs"];

curl 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=aaaaaa' \
-XOPTIONS \
-H 'Access-Control-Request-Headers: cache-control,content-type' \
-H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C107' \
-H 'Origin: null' \
-H 'Access-Control-Request-Method: POST'

Thanks for follow up...

Any news on this one ? I think I also have the issue (iOS, Ionic)

last reply from support 2 weeks ago

I have checked on our end and there is still a discussion regarding this. Please take note that we cannot disclose details about timelines for the bugfix. You may just watch out the bugfix in our release notes and our blog. I hope for your understanding.

this case opened at 27th feb; after 50 emails they confirm the bug, but i cant have clear response from support if they will fix it.

I think Ionic will be affected if they use WKWebView; note that only if you want to read local files from WKWebView if you change the configuration
[self.webView.configuration.preferences setValue:@TRUE forKey:@"allowFileAccessFromFileURLs"];

otherwise the request origin is valid..

I think problem solved...
Not sure Yet..
Just sent Firebase Support asking for a confirmation..
Anyone still face this error?

Yeah, we apologize for the delay, the original reported CORS problem should be fixed.

What version was this fixed in?

This is a backend related change. It should apply to all versions.

Thanks @bojeil-google for confirmation
Close issue

I am still seeing auth errors logged on our Sentry instance for iOS.

Was this page helpful?
0 / 5 - 0 ratings