firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

FR: Support moz-extension as well as chrome-extension.

Open InputNeuron opened this issue 6 years ago • 13 comments

[REQUIRED] Describe your environment

  • Operating System version: Mac OS X 10.15
  • Browser version: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:82.0) Gecko/20100101 Firefox/82.0
  • Firebase SDK version: 7.24.0
  • Firebase Product: auth (auth, database, storage, etc)

Firefox extensions use the scheme moz-extension but Firebase auth only works with chrome-extension.

Maybe there needs to be a web-extension URI scheme?

Anyway. Firebase auth needs to support this as our chrome extension works fine but won't work in Firebase.

This should be a super simple fix and I can just submit a PR.

Steps to reproduce:

Relevant Code:

https://stackblitz.com/fork/firebase-issue-sandbox

// TODO(you): code here to reproduce the problem

InputNeuron avatar Oct 27 '20 18:10 InputNeuron

Looking through this now the main issue is that a number of things assume chrome extension not extensions for other platforms/browsers.

For example:

/**
 * @private @const {string} The Chrome extension invalid origin message
 *     template.
 */
fireauth.InvalidOriginError.CHROME_EXTENSION_MESSAGE_TEMPLATE_ = 'This chrom' +
    'e extension ID (chrome-extension://%s) is not authorized to run this op' +
    'eration. Add it to the OAuth redirect domains list in the Firebase cons' +
    'ole -> Auth section -> Sign in method tab.';

... I'm not sure it makes sense to create a error for all of them so we might need to pass the extension scheme.

InputNeuron avatar Oct 27 '20 18:10 InputNeuron

I have a branch here:

https://github.com/polar-app/firebase-js-sdk

but I think it will require a bit more work as there needs to be a generic method to work with extension types. I'm sure Safari and MS Edge have different extension schemes and those should be supported too.

InputNeuron avatar Oct 27 '20 18:10 InputNeuron

Hey there! I've filed b/172259549 to track this feature request internally :)

malcolmdeck avatar Nov 02 '20 19:11 malcolmdeck

Hello, are there any updates on if or when this will be addressed?

nopol10 avatar Jan 04 '21 16:01 nopol10

This is a big issue too as it's anti-competitive for Google to block other browsers (whether inadvertent or not).

InputNeuron avatar Jan 04 '21 19:01 InputNeuron

Changing this SDK alone is not enough to allow moz-extension to work as the Authorized domains list in Firebase Console prevents the addition of moz-extension:// domains.

Anyone know of a workaround that allows auth to work in Firefox extensions?

nopol10 avatar Jan 09 '21 13:01 nopol10

For Google auth I ended up using browser.identity.launchWebAuthFlow (to https://accounts.google.com/o/oauth2/v2/auth with the client ID used by Firebase), parsing the id token in the result and calling the following:

const credential = firebase.auth.GoogleAuthProvider.credential(idToken);
const userCredentials = await firebase.auth().signInWithCredential(credential);

nopol10 avatar Jan 10 '21 14:01 nopol10

Hi! I'm on the Firebase team. This would be a welcomed community contribution. Feel free to open your PR as a work in progress if you'd like feedback.

rachelmyers avatar Jan 19 '21 22:01 rachelmyers

Hi @rachelmyers, as mentioned earlier, even if the SDK were to allow moz-extension, it would not work as the following page in the Firebase console does not allow moz-extension:// to be input. image

nopol10 avatar Jan 20 '21 00:01 nopol10

@nopol10 do you find a solution?

pier-verdu avatar Jun 09 '21 09:06 pier-verdu

For Google auth I ended up using browser.identity.launchWebAuthFlow (to https://accounts.google.com/o/oauth2/v2/auth with the client ID used by Firebase), parsing the id token in the result and calling the following:

const credential = firebase.auth.GoogleAuthProvider.credential(idToken);
const userCredentials = await firebase.auth().signInWithCredential(credential);

@Pierre-CLIND this was what I used to overcome the issue. A more complete implementation can be found here: https://github.com/nopol10/nekocap/blob/1c5dff15b11e7bc4bce206a42437e68b33150f6c/src/common/providers/parse/parse-provider.tsx#L80

nopol10 avatar Jun 09 '21 15:06 nopol10

@nopol10 I still get the auth/unauthorized-domain and auth/operation-not-supported-in-this-environment errors following the logic in your code. When I try to add the mozilla extension, I get the validation error you mentioned. Is there something I am missing?

imolorhe avatar Jan 21 '23 21:01 imolorhe

For Google auth I ended up using browser.identity.launchWebAuthFlow (to https://accounts.google.com/o/oauth2/v2/auth with the client ID used by Firebase), parsing the id token in the result and calling the following:

const credential = firebase.auth.GoogleAuthProvider.credential(idToken);
const userCredentials = await firebase.auth().signInWithCredential(credential);

@Pierre-CLIND this was what I used to overcome the issue. A more complete implementation can be found here: https://github.com/nopol10/nekocap/blob/1c5dff15b11e7bc4bce206a42437e68b33150f6c/src/common/providers/parse/parse-provider.tsx#L80

Sorry for necro, but I think this can help anyone in the future who is developing a cross-platform browser extension for Chrome/Chromium and Firefox using Firebase as their auth provider and Firestore for their db.

nopol10's solution worked for me, but I had to apply the same solution for my Chrome login because otherwise my Firestore security rules WOULD NOT PICK UP that a user had been auth'ed in after they logged in. You can see more about why here, hopefully this helps anyone: https://github.com/p-o-f/ShareYT/commit/49619e0d2110636c1086717fc325b891dd5fff5a

p-o-f avatar Sep 15 '25 03:09 p-o-f