Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ private GeneratedAndroidFirebaseCore.CoreFirebaseOptions firebaseOptionsToMap(
firebaseOptions.setDatabaseURL(options.getDatabaseUrl());
firebaseOptions.setStorageBucket(options.getStorageBucket());
firebaseOptions.setTrackingId(options.getGaTrackingId());
// TODO(recaptchaSiteKey): Map recaptchaSiteKey if stored.

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

To resolve this TODO and map the recaptchaSiteKey back when converting options, you can update the signature of firebaseOptionsToMap to accept the app name, allowing you to retrieve the stored key from the static map:

private GeneratedAndroidFirebaseCore.CoreFirebaseOptions firebaseOptionsToMap(
    @Nullable String appName, FirebaseOptions options) {
  // ...
  if (appName != null && customRecaptchaSiteKey.containsKey(appName)) {
    firebaseOptions.setRecaptchaSiteKey(customRecaptchaSiteKey.get(appName));
  }
  return firebaseOptions.build();
}

Then update the call sites:

  1. In firebaseAppToMap:
initializeResponse.setOptions(firebaseOptionsToMap(firebaseApp.getName(), firebaseApp.getOptions()));
  1. In optionsFromResource:
taskCompletionSource.setResult(firebaseOptionsToMap(null, options));


return firebaseOptions.build();
}
Expand Down Expand Up @@ -165,6 +166,8 @@ public void initializeApp(
customAuthDomain.put(appName, initializeAppRequest.getAuthDomain());
}

// TODO(recaptchaSiteKey): Store or use recaptchaSiteKey if needed.

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

To make the recaptchaSiteKey accessible to other native plugins (such as App Check) on Android, we should store it in a static map, similar to how customAuthDomain is handled.

Please declare the static map at the class level:

public static Map<String, String> customRecaptchaSiteKey = new HashMap<>();

And store the key during initialization as shown in the suggestion.

Suggested change
// TODO(recaptchaSiteKey): Store or use recaptchaSiteKey if needed.
if (initializeAppRequest.getRecaptchaSiteKey() != null) {
customRecaptchaSiteKey.put(appName, initializeAppRequest.getRecaptchaSiteKey());
}


FirebaseApp firebaseApp =
FirebaseApp.initializeApp(applicationContext, options, appName);
taskCompletionSource.setResult(Tasks.await(firebaseAppToMap(firebaseApp)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,16 @@ public void setAppGroupId(@Nullable String setterArg) {
this.appGroupId = setterArg;
}

private @Nullable String recaptchaSiteKey;

public @Nullable String getRecaptchaSiteKey() {
return recaptchaSiteKey;
}

public void setRecaptchaSiteKey(@Nullable String setterArg) {
this.recaptchaSiteKey = setterArg;
}

/** Constructor is non-public to enforce null safety; use Builder. */
CoreFirebaseOptions() {}

Expand All @@ -402,7 +412,8 @@ && pigeonDeepEquals(deepLinkURLScheme, that.deepLinkURLScheme)
&& pigeonDeepEquals(androidClientId, that.androidClientId)
&& pigeonDeepEquals(iosClientId, that.iosClientId)
&& pigeonDeepEquals(iosBundleId, that.iosBundleId)
&& pigeonDeepEquals(appGroupId, that.appGroupId);
&& pigeonDeepEquals(appGroupId, that.appGroupId)
&& pigeonDeepEquals(recaptchaSiteKey, that.recaptchaSiteKey);
}

@Override
Expand All @@ -423,7 +434,8 @@ public int hashCode() {
androidClientId,
iosClientId,
iosBundleId,
appGroupId
appGroupId,
recaptchaSiteKey
};
return pigeonDeepHashCode(fields);
}
Expand Down Expand Up @@ -542,6 +554,14 @@ public static final class Builder {
return this;
}

private @Nullable String recaptchaSiteKey;

@CanIgnoreReturnValue
public @NonNull Builder setRecaptchaSiteKey(@Nullable String setterArg) {
this.recaptchaSiteKey = setterArg;
return this;
}

public @NonNull CoreFirebaseOptions build() {
CoreFirebaseOptions pigeonReturn = new CoreFirebaseOptions();
pigeonReturn.setApiKey(apiKey);
Expand All @@ -558,13 +578,14 @@ public static final class Builder {
pigeonReturn.setIosClientId(iosClientId);
pigeonReturn.setIosBundleId(iosBundleId);
pigeonReturn.setAppGroupId(appGroupId);
pigeonReturn.setRecaptchaSiteKey(recaptchaSiteKey);
return pigeonReturn;
}
}

@NonNull
ArrayList<Object> toList() {
ArrayList<Object> toListResult = new ArrayList<>(14);
public ArrayList<Object> toList() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this intentionally made public here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the pigeon generated code, the updated pigeon version we had a few releases ago drives this change.

ArrayList<Object> toListResult = new ArrayList<>(15);
toListResult.add(apiKey);
toListResult.add(appId);
toListResult.add(messagingSenderId);
Expand All @@ -579,6 +600,7 @@ ArrayList<Object> toList() {
toListResult.add(iosClientId);
toListResult.add(iosBundleId);
toListResult.add(appGroupId);
toListResult.add(recaptchaSiteKey);
return toListResult;
}

Expand Down Expand Up @@ -612,6 +634,8 @@ ArrayList<Object> toList() {
pigeonResult.setIosBundleId((String) iosBundleId);
Object appGroupId = pigeonVar_list.get(13);
pigeonResult.setAppGroupId((String) appGroupId);
Object recaptchaSiteKey = pigeonVar_list.get(14);
pigeonResult.setRecaptchaSiteKey((String) recaptchaSiteKey);
return pigeonResult;
}
}
Expand Down Expand Up @@ -740,7 +764,7 @@ public static final class Builder {
}

@NonNull
ArrayList<Object> toList() {
public ArrayList<Object> toList() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question re: public

ArrayList<Object> toListResult = new ArrayList<>(4);
toListResult.add(name);
toListResult.add(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ - (CoreFirebaseOptions *)optionsFromFIROptions:(FIROptions *)options {
pigeonOptions.iosBundleId = (id)options.bundleID ?: [NSNull null];
pigeonOptions.iosClientId = (id)options.clientID ?: [NSNull null];
pigeonOptions.appGroupId = (id)options.appGroupID ?: [NSNull null];
// TODO(recaptchaSiteKey): Map recaptchaSiteKey if stored.

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

To resolve this TODO and map the recaptchaSiteKey back when converting options, you can update the signature of optionsFromFIROptions: to accept the app name, allowing you to retrieve the stored key from the static dictionary:

- (CoreFirebaseOptions *)optionsFromFIROptions:(FIROptions *)options appName:(nullable NSString *)appName {
  // ...
  if (appName != nil && customRecaptchaSiteKeys[appName] != nil) {
    pigeonOptions.recaptchaSiteKey = customRecaptchaSiteKeys[appName];
  }
  return pigeonOptions;
}

Then update the call sites:

  1. In initializeResponseFromFIRApp::
response.options = [self optionsFromFIROptions:firebaseApp.options appName:appNameDart];
  1. In optionsFromResourceWithCompletion::
// Pass nil or default app name if applicable

return pigeonOptions;
}

Expand Down Expand Up @@ -178,6 +179,8 @@ - (void)initializeAppAppName:(nonnull NSString *)appName
options.appGroupID = initializeAppRequest.appGroupId;
}

// TODO(recaptchaSiteKey): Store or use recaptchaSiteKey if needed.

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

To make the recaptchaSiteKey accessible to other native plugins (such as App Check) on iOS, we should store it in a static dictionary, similar to how customAuthDomains is handled.

Please declare the static dictionary and a getter at the class level:

static NSMutableDictionary<NSString *, NSString *> *customRecaptchaSiteKeys;

+ (void)initialize {
  if (self == [FLTFirebaseCorePlugin self]) {
    customAuthDomains = [[NSMutableDictionary alloc] init];
    customRecaptchaSiteKeys = [[NSMutableDictionary alloc] init];
  }
}

+ (NSString *)getCustomRecaptchaSiteKey:(NSString *)appName {
  return customRecaptchaSiteKeys[appName];
}

And store the key during initialization as shown in the suggestion.

  if (initializeAppRequest.recaptchaSiteKey != nil) {
    customRecaptchaSiteKeys[appNameIos] = initializeAppRequest.recaptchaSiteKey;
  }


if (initializeAppRequest.authDomain != nil) {
customAuthDomains[appNameIos] = initializeAppRequest.authDomain;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ NS_ASSUME_NONNULL_BEGIN
androidClientId:(nullable NSString *)androidClientId
iosClientId:(nullable NSString *)iosClientId
iosBundleId:(nullable NSString *)iosBundleId
appGroupId:(nullable NSString *)appGroupId;
appGroupId:(nullable NSString *)appGroupId
recaptchaSiteKey:(nullable NSString *)recaptchaSiteKey;
@property(nonatomic, copy) NSString *apiKey;
@property(nonatomic, copy) NSString *appId;
@property(nonatomic, copy) NSString *messagingSenderId;
Expand All @@ -47,6 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy, nullable) NSString *iosClientId;
@property(nonatomic, copy, nullable) NSString *iosBundleId;
@property(nonatomic, copy, nullable) NSString *appGroupId;
@property(nonatomic, copy, nullable) NSString *recaptchaSiteKey;
@end

@interface CoreInitializeResponse : NSObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ + (instancetype)makeWithApiKey:(NSString *)apiKey
androidClientId:(nullable NSString *)androidClientId
iosClientId:(nullable NSString *)iosClientId
iosBundleId:(nullable NSString *)iosBundleId
appGroupId:(nullable NSString *)appGroupId {
appGroupId:(nullable NSString *)appGroupId
recaptchaSiteKey:(nullable NSString *)recaptchaSiteKey {
CoreFirebaseOptions *pigeonResult = [[CoreFirebaseOptions alloc] init];
pigeonResult.apiKey = apiKey;
pigeonResult.appId = appId;
Expand All @@ -159,6 +160,7 @@ + (instancetype)makeWithApiKey:(NSString *)apiKey
pigeonResult.iosClientId = iosClientId;
pigeonResult.iosBundleId = iosBundleId;
pigeonResult.appGroupId = appGroupId;
pigeonResult.recaptchaSiteKey = recaptchaSiteKey;
return pigeonResult;
}
+ (CoreFirebaseOptions *)fromList:(NSArray<id> *)list {
Expand All @@ -177,6 +179,7 @@ + (CoreFirebaseOptions *)fromList:(NSArray<id> *)list {
pigeonResult.iosClientId = GetNullableObjectAtIndex(list, 11);
pigeonResult.iosBundleId = GetNullableObjectAtIndex(list, 12);
pigeonResult.appGroupId = GetNullableObjectAtIndex(list, 13);
pigeonResult.recaptchaSiteKey = GetNullableObjectAtIndex(list, 14);
return pigeonResult;
}
+ (nullable CoreFirebaseOptions *)nullableFromList:(NSArray<id> *)list {
Expand All @@ -198,6 +201,7 @@ + (nullable CoreFirebaseOptions *)nullableFromList:(NSArray<id> *)list {
self.iosClientId ?: [NSNull null],
self.iosBundleId ?: [NSNull null],
self.appGroupId ?: [NSNull null],
self.recaptchaSiteKey ?: [NSNull null],
];
}
- (BOOL)isEqual:(id)object {
Expand All @@ -221,7 +225,8 @@ - (BOOL)isEqual:(id)object {
FLTPigeonDeepEquals(self.androidClientId, other.androidClientId) &&
FLTPigeonDeepEquals(self.iosClientId, other.iosClientId) &&
FLTPigeonDeepEquals(self.iosBundleId, other.iosBundleId) &&
FLTPigeonDeepEquals(self.appGroupId, other.appGroupId);
FLTPigeonDeepEquals(self.appGroupId, other.appGroupId) &&
FLTPigeonDeepEquals(self.recaptchaSiteKey, other.recaptchaSiteKey);
}

- (NSUInteger)hash {
Expand All @@ -240,6 +245,7 @@ - (NSUInteger)hash {
result = result * 31 + FLTPigeonDeepHash(self.iosClientId);
result = result * 31 + FLTPigeonDeepHash(self.iosBundleId);
result = result * 31 + FLTPigeonDeepHash(self.appGroupId);
result = result * 31 + FLTPigeonDeepHash(self.recaptchaSiteKey);
return result;
}
@end
Expand Down
36 changes: 32 additions & 4 deletions packages/firebase_core/firebase_core/windows/messages.g.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ CoreFirebaseOptions::CoreFirebaseOptions(
const std::string* storage_bucket, const std::string* measurement_id,
const std::string* tracking_id, const std::string* deep_link_u_r_l_scheme,
const std::string* android_client_id, const std::string* ios_client_id,
const std::string* ios_bundle_id, const std::string* app_group_id)
const std::string* ios_bundle_id, const std::string* app_group_id,
const std::string* recaptcha_site_key)
: api_key_(api_key),
app_id_(app_id),
messaging_sender_id_(messaging_sender_id),
Expand Down Expand Up @@ -287,7 +288,10 @@ CoreFirebaseOptions::CoreFirebaseOptions(
ios_bundle_id_(ios_bundle_id ? std::optional<std::string>(*ios_bundle_id)
: std::nullopt),
app_group_id_(app_group_id ? std::optional<std::string>(*app_group_id)
: std::nullopt) {}
: std::nullopt),
recaptcha_site_key_(recaptcha_site_key
? std::optional<std::string>(*recaptcha_site_key)
: std::nullopt) {}

const std::string& CoreFirebaseOptions::api_key() const { return api_key_; }

Expand Down Expand Up @@ -453,9 +457,23 @@ void CoreFirebaseOptions::set_app_group_id(std::string_view value_arg) {
app_group_id_ = value_arg;
}

const std::string* CoreFirebaseOptions::recaptcha_site_key() const {
return recaptcha_site_key_ ? &(*recaptcha_site_key_) : nullptr;
}

void CoreFirebaseOptions::set_recaptcha_site_key(
const std::string_view* value_arg) {
recaptcha_site_key_ =
value_arg ? std::optional<std::string>(*value_arg) : std::nullopt;
}

void CoreFirebaseOptions::set_recaptcha_site_key(std::string_view value_arg) {
recaptcha_site_key_ = value_arg;
}

EncodableList CoreFirebaseOptions::ToEncodableList() const {
EncodableList list;
list.reserve(14);
list.reserve(15);
list.push_back(EncodableValue(api_key_));
list.push_back(EncodableValue(app_id_));
list.push_back(EncodableValue(messaging_sender_id_));
Expand All @@ -481,6 +499,8 @@ EncodableList CoreFirebaseOptions::ToEncodableList() const {
: EncodableValue());
list.push_back(app_group_id_ ? EncodableValue(*app_group_id_)
: EncodableValue());
list.push_back(recaptcha_site_key_ ? EncodableValue(*recaptcha_site_key_)
: EncodableValue());
return list;
}

Expand Down Expand Up @@ -531,6 +551,11 @@ CoreFirebaseOptions CoreFirebaseOptions::FromEncodableList(
if (!encodable_app_group_id.IsNull()) {
decoded.set_app_group_id(std::get<std::string>(encodable_app_group_id));
}
auto& encodable_recaptcha_site_key = list[14];
if (!encodable_recaptcha_site_key.IsNull()) {
decoded.set_recaptcha_site_key(
std::get<std::string>(encodable_recaptcha_site_key));
}
return decoded;
}

Expand All @@ -551,7 +576,9 @@ bool CoreFirebaseOptions::operator==(const CoreFirebaseOptions& other) const {
other.android_client_id_) &&
PigeonInternalDeepEquals(ios_client_id_, other.ios_client_id_) &&
PigeonInternalDeepEquals(ios_bundle_id_, other.ios_bundle_id_) &&
PigeonInternalDeepEquals(app_group_id_, other.app_group_id_);
PigeonInternalDeepEquals(app_group_id_, other.app_group_id_) &&
PigeonInternalDeepEquals(recaptcha_site_key_,
other.recaptcha_site_key_);
}

bool CoreFirebaseOptions::operator!=(const CoreFirebaseOptions& other) const {
Expand All @@ -574,6 +601,7 @@ size_t CoreFirebaseOptions::Hash() const {
result = result * 31 + PigeonInternalDeepHash(ios_client_id_);
result = result * 31 + PigeonInternalDeepHash(ios_bundle_id_);
result = result * 31 + PigeonInternalDeepHash(app_group_id_);
result = result * 31 + PigeonInternalDeepHash(recaptcha_site_key_);
return result;
}

Expand Down
12 changes: 7 additions & 5 deletions packages/firebase_core/firebase_core/windows/messages.g.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class CoreFirebaseOptions {
const std::string* storage_bucket, const std::string* measurement_id,
const std::string* tracking_id, const std::string* deep_link_u_r_l_scheme,
const std::string* android_client_id, const std::string* ios_client_id,
const std::string* ios_bundle_id, const std::string* app_group_id);
const std::string* ios_bundle_id, const std::string* app_group_id,
const std::string* recaptcha_site_key);

const std::string& api_key() const;
void set_api_key(std::string_view value_arg);
Expand Down Expand Up @@ -130,6 +131,10 @@ class CoreFirebaseOptions {
void set_app_group_id(const std::string_view* value_arg);
void set_app_group_id(std::string_view value_arg);

const std::string* recaptcha_site_key() const;
void set_recaptcha_site_key(const std::string_view* value_arg);
void set_recaptcha_site_key(std::string_view value_arg);

bool operator==(const CoreFirebaseOptions& other) const;
bool operator!=(const CoreFirebaseOptions& other) const;
/// Returns a hash code value for the object. This method is supported for the
Expand All @@ -140,11 +145,9 @@ class CoreFirebaseOptions {
static CoreFirebaseOptions FromEncodableList(
const ::flutter::EncodableList& list);

public:
public:
::flutter::EncodableList ToEncodableList() const;

private:
private:
friend class CoreInitializeResponse;
friend class FirebaseCoreHostApi;
Expand All @@ -164,6 +167,7 @@ class CoreFirebaseOptions {
std::optional<std::string> ios_client_id_;
std::optional<std::string> ios_bundle_id_;
std::optional<std::string> app_group_id_;
std::optional<std::string> recaptcha_site_key_;
};

// Generated class from Pigeon that represents data sent in messages.
Expand Down Expand Up @@ -209,11 +213,9 @@ class CoreInitializeResponse {
static CoreInitializeResponse FromEncodableList(
const ::flutter::EncodableList& list);

public:
public:
::flutter::EncodableList ToEncodableList() const;

private:
private:
friend class FirebaseCoreHostApi;
friend class FirebaseAppHostApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FirebaseOptions {
this.iosClientId,
this.iosBundleId,
this.appGroupId,
this.recaptchaSiteKey,
});

/// Named constructor to create [FirebaseOptions] from a the response of Pigeon channel.
Expand All @@ -71,7 +72,8 @@ class FirebaseOptions {
androidClientId = options.androidClientId,
iosClientId = options.iosClientId,
iosBundleId = options.iosBundleId,
appGroupId = options.appGroupId;
appGroupId = options.appGroupId,
recaptchaSiteKey = options.recaptchaSiteKey;

/// Returns a copy of this FirebaseOptions with the given fields replaced with
/// the new values.
Expand All @@ -90,6 +92,7 @@ class FirebaseOptions {
String? iosClientId,
String? iosBundleId,
String? appGroupId,
String? recaptchaSiteKey,
}) {
return FirebaseOptions(
apiKey: apiKey ?? this.apiKey,
Expand All @@ -106,6 +109,7 @@ class FirebaseOptions {
iosClientId: iosClientId ?? this.iosClientId,
iosBundleId: iosBundleId ?? this.iosBundleId,
appGroupId: appGroupId ?? this.appGroupId,
recaptchaSiteKey: recaptchaSiteKey ?? this.recaptchaSiteKey,
);
}

Expand Down Expand Up @@ -174,6 +178,9 @@ class FirebaseOptions {
/// This property is used on iOS only.
final String? appGroupId;

/// The reCAPTCHA site key used for App Check.
final String? recaptchaSiteKey;

/// The current instance as a [Map].
Map<String, String?> get asMap {
return <String, String?>{
Expand All @@ -191,6 +198,7 @@ class FirebaseOptions {
'iosClientId': iosClientId,
'iosBundleId': iosBundleId,
'appGroupId': appGroupId,
'recaptchaSiteKey': recaptchaSiteKey,
};
}

Expand Down
Loading
Loading