firebase / quickstart-js

Firebase Quickstart Samples for Web
https://firebase.google.com
Apache License 2.0
5.05k stars 3.66k forks source link

SignInWithRedirect with Google provider does not work inside content script in chrome extension in v4.1.2 #147

Open sachinjain024 opened 7 years ago

sachinjain024 commented 7 years ago

Browser: Chrome and Firefox Browser version: Firefox v52 and Chrome v58 Operating system: MaxOS Operating system version: v10.12.5

What steps will reproduce the problem:

  1. git clone https://github.com/sachinjain024/practicebook practicebook
  2. Go to chrome://settings
  3. Enable Developer Mode
  4. Click on Load unpacked extension
  5. Select the directory web-extensions-master/firebase-authentication
  6. Open http://www.requestly.in
  7. Click on Login with Firebase
  8. After login, click on 'Login Status`
  9. It says - No user is logged in

What is the expected result? User should be logged in. Similar behaviour works well in Firebase v1 but faced this issue when trying to upgrade to v4.

What happens instead of that? User is taken to google signin screen and then he comes back to original site. Now when we check for current login status of user, it says user is not logged in.

Please provide any other information below, and attach a screenshot if possible. I have asked similar question here: https://stackoverflow.com/questions/44858133/using-authentication-inside-firebase-as-content-script-in-chrome-extension

Screenshots

screenshot 2017-07-01 12 04 20 screenshot 2017-07-01 12 04 29 screenshot 2017-07-01 12 04 36
maximtop commented 6 years ago

@sachinjain024 Hi! Have you found how to use firebase authentification in content script?

sachinjain024 commented 6 years ago

@maximtop No I could not find a proper solution to this. Instead what I did is the following:-

  1. Include firebase as normal page script
  2. Use HTML5 post messaging api between content script and page script to perform all firebase operations.

Have a look at this POC. I also used the above approach and it worked fine for me.

Currently, I am using the same in extension Requestly for authentication purpose and all other firebase interactions. You can check this out on https://www.requestly.in/rules after installing the extension and try to create and share a rule.

maximtop commented 6 years ago

@sachinjain024 Thank you! I already came to message passing too. But I use chrome api for this purpose https://developer.chrome.com/apps/messaging

sachinjain024 commented 6 years ago

@maximtop You can use chrome apis to communicate between different script types supported in chrome extension but if you are using firebase at page level, you can not use chrome apis. In which particular script type, you are using firebase ?

maximtop commented 6 years ago

@sachinjain024 If i get you, I use message passing to send message from content script to background script, and use response to print some data from firebase db on my site for authenticated user.

sachinjain024 commented 6 years ago

@maximtop Gotcha! But how are you authenticating the user in background script ?

maximtop commented 6 years ago

User authenticates in extension on the options page. After that I import firebase instance in background script and check there if user is authenticated. Sorry I can't show you code because it is in an private gitlab repository. If you are interested in realization I can make an simple example to show you, later.

sachinjain024 commented 6 years ago

@maximtop Thanks for sharing this. No code is not required! I get the idea. Can you just tell me how did you import firebase instance in background from options page. Because localstorage is shared among options page and background so if user is logged into options page, you can detect it in background ?

maximtop commented 6 years ago

@sachinjain024 Yes I think it works that way. Actually I created files with firebase, initialized firebase and after that exported it. Then I import it in option.js or background.js.