firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.86k stars 891 forks source link

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

Open burtonator opened 4 years ago

burtonator commented 4 years ago

[REQUIRED] Describe your environment

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
burtonator commented 4 years ago

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.

burtonator commented 4 years ago

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.

malcolmdeck commented 4 years ago

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

nopol10 commented 3 years ago

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

burtonator commented 3 years ago

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

nopol10 commented 3 years ago

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 commented 3 years ago

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);
rachelmyers commented 3 years ago

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.

nopol10 commented 3 years ago

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

pier-verdu commented 3 years ago

@nopol10 do you find a solution?

nopol10 commented 3 years ago

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

imolorhe commented 1 year ago

@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?