Skip to content

Commit 038ea43

Browse files
Implement Firebase Auth UseUserAccessGroup for C++ iOS SDK
This commit introduces the `UseUserAccessGroup` method to the Firebase Authentication C++ SDK. This method is specific to iOS and allows developers to specify a keychain access group for user data. It calls the underlying Objective-C method `[FIRAuth useUserAccessGroup:error:]`. On Android and desktop platforms, this method is a no-op stub and returns `kAuthErrorNone` as per its documented behavior for non-iOS platforms. Key changes: - Added `Auth::UseUserAccessGroup(const char* access_group)` to the public header `auth/src/include/firebase/auth.h` with Doxygen comments. - Implemented the iOS-specific logic in `auth/src/ios/auth_ios.mm`, including error conversion from `NSError` to `AuthError`. - Added stub implementations in `auth/src/desktop/auth_desktop.cc` and `auth/src/android/auth_android.cc` returning `kAuthErrorNone`.
1 parent 648848c commit 038ea43

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

auth/src/android/auth_android.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,12 @@ void Auth::UseEmulator(std::string host, uint32_t port) {
670670
SetEmulatorJni(auth_data_, host.c_str(), port);
671671
}
672672

673+
AuthError Auth::UseUserAccessGroup(const char* access_group) {
674+
(void)access_group; // Unused on Android.
675+
// This is an iOS-only feature, so it's a no-op on Android.
676+
return kAuthErrorNone;
677+
}
678+
673679
// Not implemented for Android.
674680
void EnableTokenAutoRefresh(AuthData* auth_data) {}
675681
void DisableTokenAutoRefresh(AuthData* auth_data) {}

auth/src/desktop/auth_desktop.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,12 @@ void Auth::UseEmulator(std::string host, uint32_t port) {
575575
auth_impl->assigned_emulator_url.append(std::to_string(port));
576576
}
577577

578+
AuthError Auth::UseUserAccessGroup(const char* access_group) {
579+
(void)access_group; // Unused on desktop.
580+
// This is an iOS-only feature, so it's a no-op on desktop.
581+
return kAuthErrorNone;
582+
}
583+
578584
void InitializeTokenRefresher(AuthData* auth_data) {
579585
auto auth_impl = static_cast<AuthImpl*>(auth_data->auth_impl);
580586
auth_impl->token_refresh_thread.Initialize(auth_data);

auth/src/include/firebase/auth.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,25 @@ class Auth {
502502
/// Gets the App this auth object is connected to.
503503
App& app();
504504

505+
/// @brief Modifies this Auth instance to use the specified keychain access
506+
/// group.
507+
///
508+
/// Accessing the keychain requires that the application has the keychain
509+
/// sharing capability and that the level of entitling access to the keychain
510+
/// is `any` (런타임에 여러 앱에서 키체인 항목을 공유하도록 허용). See
511+
/// https://developer.apple.com/documentation/security/keychain_services/keychain_items/sharing_access_to_keychain_items_among_a_collection_of_apps
512+
/// for more details.
513+
///
514+
/// @note This method is only functional on iOS. On other platforms, it's a
515+
/// no-op and will return kAuthErrorNone.
516+
///
517+
/// @param[in] access_group The keychain access group to use. Set to @c nullptr
518+
/// to use the default app bundle ID access group.
519+
///
520+
/// @return kAuthErrorNone on success, or an AuthError code if an error
521+
/// occurred.
522+
AuthError UseUserAccessGroup(const char* access_group);
523+
505524
/// Returns the Auth object for an App. Creates the Auth if required.
506525
///
507526
/// To get the Auth object for the default app, use,

auth/src/ios/auth_ios.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,19 @@ void SignInCallback(FIRUser *_Nullable user, NSError *_Nullable error,
590590
SetEmulatorJni(auth_data_, host.c_str(), port);
591591
}
592592

593+
AuthError Auth::UseUserAccessGroup(const char* access_group) {
594+
if (!auth_data_) {
595+
return kAuthErrorUninitialized;
596+
}
597+
NSString* ns_access_group = access_group ? @(access_group) : nil;
598+
NSError* error = nil;
599+
BOOL success = [AuthImpl(auth_data_) useUserAccessGroup:ns_access_group error:&error];
600+
if (!success) {
601+
return AuthErrorFromNSError(error);
602+
}
603+
return kAuthErrorNone;
604+
}
605+
593606
// Remap iOS SDK errors reported by the UIDelegate. While these errors seem like
594607
// user interaction errors, they are actually caused by bad provider ids.
595608
NSError *RemapBadProviderIDErrors(NSError *_Nonnull error) {

0 commit comments

Comments
 (0)