-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
feat(app-check): adds all web providers as an option #812
feat(app-check): adds all web providers as an option #812
Conversation
Thank you. I'm currently working on the update to Capacitor 7. I will soon take a look at your PR. |
@eljass Wouldn't it be easier to let the user pass the provider directly? import { AppCheckProvider } from 'firebase/app-check';
export interface InitializeOptions {
...
provider: AppCheckProvider?
} |
Co-authored-by: Robin Genz <[email protected]>
Co-authored-by: Robin Genz <[email protected]>
I was thinking this, but in case there would be new provider presented by Firebase before it is implemented in this plugin I think it was clearer to limit to ones currently tested and supported. Also, with this typing it requires user to initialize the provider like: import { ReCaptchaEnterpriseProvider } from 'firebase/app-check'
initializeAppCheck({
provider: ReCaptchaEnterpriseProvider,
siteKey: "abcd"
}) This would work and make the plugin's provider selection cleaner, but at the same time it makes it harder to check if required options are present (such as |
@eljass I thought we could do it like that: import { FirebaseAppCheck } from '@capacitor-firebase/app-check';
import { AppCheckProvider } from 'firebase/app-check';
const initialize = async () => {
const provider = new ReCaptchaV3Provider("..."); // User creates the provider with all options
await FirebaseAppCheck.initialize({
provider: provider // No `customProviderOptions` are needed
});
}; Or are there any limitations? |
@robingenz let me refresh my memory and test it out that way. |
@robingenz For some reason I cannot make it work either with direct type exports: /**
* Set used app check provider for Web.
*
* Only available for Web.
*
* Read more: https://firebase.google.com/docs/app-check/web/custom-provider
*
* @since 7.1.0
* @default ReCaptchaV3Provider
*/
provider: ReCaptchaEnterpriseProvider | ReCaptchaV3Provider | CustomProvider; Don't know if its my environment or what. |
I just realized we are not allowed to import types from the Firebase JS SDK anyway, since the Firebase JS SDK is only an optional dependency of this plugin. You can just set the type from export interface InitializeOptions {
/**
* The provider to use for App Check. Must be an instance of
* `ReCaptchaV3Provider`, `ReCaptchaEnterpriseProvider`, or `CustomProvider`.
*
* Only available for Web.
*
* @since 7.1.0
* @see https://firebase.google.com/docs/app-check/web/custom-provider
*/
provider?: any;
} That's not best practice, but in this case it would be fine with me. |
@robingenz How do you feel runtime validations then? Should we check something like this for example? Or do we just trust that the errors from Firebase SDK is enough if invalid provider is set? const isValidProvider = (provider: unknown): provider is AppCheckOptions['provider'] => {
return (
provider instanceof ReCaptchaV3Provider ||
provider instanceof ReCaptchaEnterpriseProvider ||
provider instanceof CustomProvider
)
}
export class FirebaseAppCheckWeb
extends WebPlugin
implements FirebaseAppCheckPlugin
{
// ...other things
public async initialize(options?: InitializeOptions): Promise<void> {
// ...other things
let provider = options?.provider
if (!!provider) {
if (!!provider && !isValidProvider(provider)) {
throw new Error('Invalid provider')
}
} else {
if (!options?.siteKey) throw new Error(FirebaseAppCheckWeb.errorSiteKeyMissing)
provider = new ReCaptchaV3Provider(options?.siteKey)
}
this.appCheckInstance = initializeAppCheck(app, {
provider,
isTokenAutoRefreshEnabled: options.isTokenAutoRefreshEnabled,
});
}
// ...rest of other things
} |
I want to keep it simple at the moment. Let the Firebase JS SDK do the validation. |
@robingenz suggested way implemented now |
@capacitor-firebase/analytics
@capacitor-firebase/app
@capacitor-firebase/app-check
@capacitor-firebase/authentication
@capacitor-firebase/crashlytics
@capacitor-firebase/firestore
@capacitor-firebase/functions
@capacitor-firebase/messaging
@capacitor-firebase/performance
@capacitor-firebase/remote-config
@capacitor-firebase/storage
commit: |
Co-authored-by: Robin Genz <[email protected]>
Thank you! |
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run changeset
).Adds option to use different attestation providers in web. This adds support for reCaptcha Enterprise and Custom provider in addition to existing reCaptcha v3.
Close #811