Skip to content

Commit 41eb0e2

Browse files
Implement UseUserAccessGroup for Firebase Auth C++ SDK
This commit adds the UseUserAccessGroup method to the Firebase Auth C++ SDK. - On iOS, this method calls the native [FIRAuth useUserAccessGroup:error:] method to specify a user access group for iCloud keychain access. - On other platforms (desktop, Android), this method is a no-op and returns kAuthErrorNone as it's an iOS-only feature. Public API has been added to firebase::auth::Auth in auth.h, with implementations in auth_ios.mm (iOS) and auth_desktop.cc (stub for other platforms).
1 parent e9ab71d commit 41eb0e2

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

auth/src/desktop/auth_desktop.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ 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+
// This is an iOS-only feature. No-op on other platforms.
580+
return kAuthErrorNone;
581+
}
582+
578583
void InitializeTokenRefresher(AuthData* auth_data) {
579584
auto auth_impl = static_cast<AuthImpl*>(auth_data->auth_impl);
580585
auth_impl->token_refresh_thread.Initialize(auth_data);

auth/src/include/firebase/auth.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,21 @@ class Auth {
517517
/// not available on the current device.
518518
static Auth* GetAuth(App* app, InitResult* init_result_out = nullptr);
519519

520+
/// @brief Specifies a user access group for iCloud keychain access.
521+
///
522+
/// This method is only functional on iOS. On other platforms, it is a no-op
523+
/// and will always return `kAuthErrorNone`.
524+
///
525+
/// If you are using iCloud keychain synchronization, you will need to call
526+
/// this method to set the user access group.
527+
///
528+
/// @param[in] access_group The user access group to use. Set to `nullptr` or
529+
/// an empty string to use the default access group.
530+
///
531+
/// @return `kAuthErrorNone` on success, or an AuthError code if an error
532+
/// occurred.
533+
AuthError UseUserAccessGroup(const char* access_group);
534+
520535
private:
521536
/// @cond FIREBASE_APP_INTERNAL
522537
friend class ::firebase::App;

auth/src/ios/auth_ios.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,5 +608,23 @@ void DisableTokenAutoRefresh(AuthData *auth_data) {}
608608
void InitializeTokenRefresher(AuthData *auth_data) {}
609609
void DestroyTokenRefresher(AuthData *auth_data) {}
610610

611+
AuthError Auth::UseUserAccessGroup(const char* access_group_str) {
612+
if (!auth_data_) {
613+
return kAuthErrorUninitialized;
614+
}
615+
NSString* access_group_ns_str = nil;
616+
if (access_group_str != nullptr && strlen(access_group_str) > 0) {
617+
access_group_ns_str = [NSString stringWithUTF8String:access_group_str];
618+
}
619+
620+
NSError* error = nil;
621+
BOOL success = [AuthImpl(auth_data_) useUserAccessGroup:access_group_ns_str error:&error];
622+
if (success) {
623+
return kAuthErrorNone;
624+
} else {
625+
return AuthErrorFromNSError(error);
626+
}
627+
}
628+
611629
} // namespace auth
612630
} // namespace firebase

0 commit comments

Comments
 (0)