Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ kfurue <pulpits.37-shims@icloud.com>
Max Wojczuk <developer@mwojczuk.xyz>
Julian Pscheid <julian@pscheid.com>
Artem Shevchenko <art.shevchen@gmail.com>
Adem Ocel <moosyroot@gmail.com>
18 changes: 18 additions & 0 deletions docs/app-check/default-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,24 @@ This limitation is easiest to miss on a simulator, where the Apple SDK
already defaults to the debug provider. See
[flutterfire#18613](https://github.com/firebase/flutterfire/issues/18613).

### Leaving out the reCAPTCHA Enterprise SDK on iOS {:#without-recaptcha}

With Swift Package Manager, the iOS plugin adds the
[reCAPTCHA Enterprise SDK](https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk)
so that `AppleReCaptchaProvider` works without extra setup. If your app uses
another Apple provider, set the `FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA`
environment variable when building to leave the SDK out of the app:

```bash
FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true flutter build ios
```

You can also add this variable to your Xcode scheme's environment variables
for persistent configuration. With CocoaPods, the plugin does not add the SDK;
to use `AppleReCaptchaProvider`, add `pod 'RecaptchaEnterprise'` to your app's
`Podfile`. Without the SDK, `AppleReCaptchaProvider` configures no provider
and App Check token requests fail.

## Next steps

Once the App Check library is installed in your app, start distributing the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,31 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import Foundation
import PackageDescription

let firebaseSdkVersion: Version = "13.2.0"

/// Set FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true to leave out the reCAPTCHA
/// Enterprise SDK if the app does not use AppleReCaptchaProvider.
/// e.g. FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=true flutter build ios
let withoutRecaptcha =
ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] != nil
Comment on lines +16 to +17

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Checking != nil on the environment variable means that if a user explicitly sets FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA=false (for example, in their CI/CD environment or Xcode scheme to temporarily disable the opt-out), it will still evaluate to true because the environment variable exists.

It is safer and more robust to check if the value is explicitly "true".

Suggested change
let withoutRecaptcha =
ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] != nil
let withoutRecaptcha =
ProcessInfo.processInfo.environment["FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA"] == "true"


var recaptchaPackages: [Package.Dependency] = []
var recaptchaProducts: [Target.Dependency] = []
if !withoutRecaptcha {
recaptchaPackages.append(
.package(
url: "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk.git",
from: "18.0.0"
)
)
recaptchaProducts.append(
.product(name: "RecaptchaEnterprise", package: "recaptcha-enterprise-mobile-sdk")
)
}

let package = Package(
name: "firebase_app_check",
platforms: [
Expand All @@ -19,22 +40,17 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/firebase/firebase-ios-sdk", exact: firebaseSdkVersion),
.package(
url: "https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk.git",
from: "18.0.0"
),
.package(name: "firebase_core", path: "../firebase_core"),
.package(name: "FlutterFramework", path: "../FlutterFramework"),
],
] + recaptchaPackages,
targets: [
.target(
name: "firebase_app_check",
dependencies: [
.product(name: "FirebaseAppCheck", package: "firebase-ios-sdk"),
.product(name: "RecaptchaEnterprise", package: "recaptcha-enterprise-mobile-sdk"),
.product(name: "firebase-core", package: "firebase_core"),
.product(name: "FlutterFramework", package: "FlutterFramework"),
],
] + recaptchaProducts,
resources: [
.process("Resources")
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,21 @@ class AppCheckProviderWrapper: NSObject, AppCheckProvider {
delegateProvider = appAttestProvider ?? DeviceCheckProvider(app: app)
case "recaptcha":
#if os(iOS)
if let recaptchaSiteKey {
// The reCAPTCHA Enterprise SDK can be left out of the build (CocoaPods,
// or FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA with Swift Package Manager).
// RecaptchaProvider then raises an Objective-C exception, so look up the
// class the Firebase SDK uses to detect it first.
let recaptchaLinked = NSClassFromString("RecaptchaEnterprise.RCARecaptcha") != nil
if recaptchaLinked, let recaptchaSiteKey {
delegateProvider = RecaptchaProvider(app: app, siteKey: recaptchaSiteKey)
} else {
delegateProvider = nil
}
if delegateProvider == nil {
if !recaptchaLinked {
print(
"Firebase App Check: failed to initialize RecaptchaProvider. Link the reCAPTCHA Enterprise SDK."
)
} else if delegateProvider == nil {
print(
"Firebase App Check: failed to initialize RecaptchaProvider. Ensure site key is provided."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class AppleAppAttestWithDeviceCheckFallbackProvider
}

/// reCAPTCHA provider for Apple platforms.
///
/// Only available on iOS, and only if the app links the reCAPTCHA Enterprise
/// SDK: Swift Package Manager builds add it unless
/// `FIREBASE_APP_CHECK_WITHOUT_RECAPTCHA` is set; CocoaPods builds need the
/// `RecaptchaEnterprise` pod in the app's `Podfile`. Without the SDK, no
/// provider is configured and token requests fail.
class AppleReCaptchaProvider extends AppleAppCheckProvider {
/// Creates an Apple reCAPTCHA provider with a required [siteKey].
const AppleReCaptchaProvider(this.siteKey) : super('recaptcha');
Expand Down
Loading