diff --git a/auth/src/android/auth_android.cc b/auth/src/android/auth_android.cc index e0a9a669cb..335a9e5173 100644 --- a/auth/src/android/auth_android.cc +++ b/auth/src/android/auth_android.cc @@ -676,5 +676,10 @@ void DisableTokenAutoRefresh(AuthData* auth_data) {} void InitializeTokenRefresher(AuthData* auth_data) {} void DestroyTokenRefresher(AuthData* auth_data) {} +AuthError Auth::UseUserAccessGroup(const char* access_group) { + // This is an iOS-only feature. No-op on other platforms. + return kAuthErrorNone; +} + } // namespace auth } // namespace firebase diff --git a/auth/src/desktop/auth_desktop.cc b/auth/src/desktop/auth_desktop.cc index dc9aca2950..e934013c64 100644 --- a/auth/src/desktop/auth_desktop.cc +++ b/auth/src/desktop/auth_desktop.cc @@ -575,6 +575,11 @@ void Auth::UseEmulator(std::string host, uint32_t port) { auth_impl->assigned_emulator_url.append(std::to_string(port)); } +AuthError Auth::UseUserAccessGroup(const char* access_group) { + // This is an iOS-only feature. No-op on other platforms. + return kAuthErrorNone; +} + void InitializeTokenRefresher(AuthData* auth_data) { auto auth_impl = static_cast(auth_data->auth_impl); auth_impl->token_refresh_thread.Initialize(auth_data); diff --git a/auth/src/include/firebase/auth.h b/auth/src/include/firebase/auth.h index f6809c4a57..ce363424af 100644 --- a/auth/src/include/firebase/auth.h +++ b/auth/src/include/firebase/auth.h @@ -517,6 +517,26 @@ class Auth { /// not available on the current device. static Auth* GetAuth(App* app, InitResult* init_result_out = nullptr); + /// @brief Specifies a user access group for iCloud keychain access. + /// + /// This method is only functional on iOS. On other platforms, it is a no-op + /// and will always return `kAuthErrorNone`. + /// + /// If you are using iCloud keychain synchronization, you will need to call + /// this method to set the user access group. + /// + /// @param[in] access_group The user access group to use. + /// - On iOS, if `nullptr` is provided, `nil` will be passed to the + /// underlying SDK, typically resetting to the default or app's main + /// access group. + /// - On iOS, if an empty string (`""`) is provided, an empty `NSString` + /// will be passed to the underlying SDK. + /// - On other platforms, this parameter is ignored. + /// + /// @return `kAuthErrorNone` on success, or an AuthError code if an error + /// occurred (iOS only). + AuthError UseUserAccessGroup(const char* access_group); + private: /// @cond FIREBASE_APP_INTERNAL friend class ::firebase::App; diff --git a/auth/src/ios/auth_ios.mm b/auth/src/ios/auth_ios.mm index a0292ba3b8..78746c391e 100644 --- a/auth/src/ios/auth_ios.mm +++ b/auth/src/ios/auth_ios.mm @@ -608,5 +608,23 @@ void DisableTokenAutoRefresh(AuthData *auth_data) {} void InitializeTokenRefresher(AuthData *auth_data) {} void DestroyTokenRefresher(AuthData *auth_data) {} +AuthError Auth::UseUserAccessGroup(const char* access_group_str) { + if (!auth_data_) { + return kAuthErrorUninitialized; + } + NSString* access_group_ns_str = nil; + if (access_group_str != nullptr) { + access_group_ns_str = [NSString stringWithUTF8String:access_group_str]; + } + + NSError* error = nil; + BOOL success = [AuthImpl(auth_data_) useUserAccessGroup:access_group_ns_str error:&error]; + if (success) { + return kAuthErrorNone; + } else { + return AuthErrorFromNSError(error); + } +} + } // namespace auth } // namespace firebase