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

OAuthProvider is missing constructor #5392

Closed
AgainPsychoX opened this issue Aug 27, 2021 · 10 comments · Fixed by #5397
Closed

OAuthProvider is missing constructor #5392

AgainPsychoX opened this issue Aug 27, 2021 · 10 comments · Fixed by #5397
Assignees

Comments

@AgainPsychoX
Copy link

Environment

  • Firebase SDK version: 9.0.0
  • Firebase Product: auth

Problem

Firebase Auth API v9 does not have OAuthProvider constructor, or at least in TypeScript typings.

API v9: https://firebase.google.com/docs/reference/js/auth.oauthprovider (no constructor or a way to get new instance OAuthProvider)

API v8: https://firebase.google.com/docs/reference/js/v8/firebase.auth.OAuthCredential (it's fine at v8)

Even comment docs suggest it should be there (:
a

I need it as I want to use OIDC (https://cloud.google.com/identity-platform/docs/web/oidc), but no constructor, no addScope.

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@AgainPsychoX
Copy link
Author

I tried using

const twitchAuthProvider = {providerId: 'oidc.twitch'} as AuthProvider;
const result = await signInWithPopup(Auth, twitchAuthProvider);

but of course it won't work, because it's not FederatedAuthProvider.

Kinda major bug, can't use custom auth providers with API v9.

@Feiyang1
Copy link
Member

It is a typing issue. The constructor is actually there at runtime. I will work on a fix tomorrow.

Can you suppress the ts error as a workaround for now?

// ts-ignore
new OAuthProvider('oidc.twitch');

@Feiyang1 Feiyang1 self-assigned this Aug 27, 2021
@AgainPsychoX
Copy link
Author

Two possible workarounds:

const FixedOAuthProvider = OAuthProvider as { new(providerId: string): OAuthProvider };
const twitchAuthProvider = new FixedOAuthProvider('oidc.twitch');

or

// @ts-ignore
const twitchAuthProvider = new OAuthProvider('oidc.twitch');

@cungminh2710
Copy link

cungminh2710 commented Aug 28, 2021

Yup new OAuthProvider('apple.com') won't work. Worked fine in beta channel though These workarounds can be used in the meantime

@jpike88
Copy link

jpike88 commented Aug 30, 2021

Just ran into this issue on Cordova, @Feiyang1 is it related?:

const auth = getAuth(Environment.firebaseInstance);
			const provider = new GoogleAuthProvider();
			try {
				await signInWithRedirect(auth, provider, cordovaPopupRedirectResolver);
			} catch (error) {
				// swallow this, just return.
				return;
			}
			const result = await getRedirectResult(auth);
			const credential = GoogleAuthProvider.credentialFromResult(result);
			await this.handleSSOAuthResult(
				AuthProviders.Google,
				result.user.email,
				credential.idToken
			);

This should work but errors. Error is being caused here:
https://github.com/firebase/firebase-js-sdk/blame/509c18fbc1a0d4f85a0ca8c7cfef8e3b0f3183ec/packages/auth/src/platform_browser/strategies/redirect.ts#L95

@jpike88
Copy link

jpike88 commented Aug 30, 2021

Also none of the above workarounds work for me, that assert still trips even when the console seems to be indicating that the OAuthProvider is a subclass of FederatedProvider...

This is broken and a critical issue for us

Screenshot 2021-08-30 at 3 24 02 PM

Should also add that our build target is es6, and we're using fuse-box as a bundler

@jpike88
Copy link

jpike88 commented Aug 30, 2021

More investigating...

If I remove that above line from the vendor code and just force things through, a browser tab opens with this URL:

https://auth.formpigeon.com/__/auth/handler?apiKey=API_KEY_GOES_HERE&appName=%5BDEFAULT%5D&authType=signInViaRedirect&v=9.0.0

obfuscated values: API_KEY_GOES_HERE

But it's a white screen with the text 'The requested action is invalid.'

But when I test on a working version ([email protected]), the url is this:

https://auth.aquipa.com/__/auth/handler?apiKey=API_KEY_GOES_HERE&appName=%5BDEFAULT%5D&authType=signInViaRedirect&providerId=google.com&scopes=profile&v=8.6.4&ibi=COM.COM.MYAPP&appDisplayName=APP_NAME&sessionId=SESSION_ID

obfuscated values: API_KEY_GOES_HERE, COM.COM.MYAPP, APP_NAME, SESSION_ID

This means that the provider is failing both provider instanceof FederatedAuthProvider and provider instanceof BaseOAuthProvider checks, as those asserts need to pass in order to append all the urlParams. Therefore the instanceof asserts in the following PR have broken things hard:

1de07ba

Maybe instead of instanceof, a 'type' property can be checked against instead. @sam-gc you should probably see this too

MY WORKAROUND: Replace all instances of provider instanceof FederatedAuthProvider and provider instanceof BaseOAuthProvider with true in order to pass the asserts, and everything works properly.

@Feiyang1
Copy link
Member

It is fixed in 9.0.1.

@jpike88 Thanks for the report and investigation. It seems to be a different issue than the original one. Can you please open a new issue, so we can track it there properly?

@jpike88
Copy link

jpike88 commented Aug 31, 2021

@Feiyang1 you're right, it's a different issue, just tried with 9.0.1 and still present. opened an issue at #5420

@firebase firebase locked and limited conversation to collaborators Sep 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants