Skip to content

Commit 032f12e

Browse files
Implemented Auth::UseUserAccessGroup for C++ SDK
This commit introduces the UseUserAccessGroup method to the Firebase C++ Auth SDK. - On iOS, this method calls the underlying [FIRAuth useUserAccessGroup:error:] Objective-C method to set the user access group for keychain operations. - On Android and desktop platforms, this method is a no-op and returns kAuthErrorNone, as the functionality is specific to iOS keychain services.
1 parent df805b2 commit 032f12e

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

auth/src/android/auth_android.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,5 +676,10 @@ void DisableTokenAutoRefresh(AuthData* auth_data) {}
676676
void InitializeTokenRefresher(AuthData* auth_data) {}
677677
void DestroyTokenRefresher(AuthData* auth_data) {}
678678

679+
AuthError Auth::UseUserAccessGroup(const char* user_access_group) {
680+
// This is an iOS-only feature. No-op on Android.
681+
return kAuthErrorNone;
682+
}
683+
679684
} // namespace auth
680685
} // namespace firebase

auth/src/desktop/auth_desktop.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,5 +768,10 @@ void IdTokenRefreshThread::DisableAuthRefresh() {
768768
ref_count_--;
769769
}
770770

771+
AuthError Auth::UseUserAccessGroup(const char* user_access_group) {
772+
// This is an iOS-only feature. No-op on desktop.
773+
return kAuthErrorNone;
774+
}
775+
771776
} // namespace auth
772777
} // namespace firebase

auth/src/include/firebase/auth.h

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

520+
/// @brief Sets the user access group to use for keychain operations.
521+
///
522+
/// @param[in] user_access_group The user access group ID. For an app to share
523+
/// keychain items with other apps, it must be a member of an access group.
524+
/// For more information, see
525+
/// https://developer.apple.com/documentation/security/keychain_services/keychain_items/sharing_access_to_keychain_items_among_a_collection_of_apps
526+
///
527+
/// @return Returns `kAuthErrorNone` on success, or an error code if the
528+
/// operation failed.
529+
///
530+
/// @note This method is only applicable to iOS. On other platforms, it is a
531+
/// stub and will always return `kAuthErrorNone`.
532+
AuthError UseUserAccessGroup(const char* user_access_group);
533+
520534
private:
521535
/// @cond FIREBASE_APP_INTERNAL
522536
friend class ::firebase::App;

auth/src/ios/auth_ios.mm

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

611+
AuthError Auth::UseUserAccessGroup(const char* user_access_group) {
612+
if (!auth_data_) {
613+
return kAuthErrorUninitialized;
614+
}
615+
NSString* ns_user_access_group =
616+
user_access_group ? [NSString stringWithUTF8String:user_access_group] : nil;
617+
NSError* error = nil;
618+
[AuthImpl(auth_data_) useUserAccessGroup:ns_user_access_group error:&error];
619+
return AuthErrorFromNSError(error);
620+
}
621+
611622
} // namespace auth
612623
} // namespace firebase

0 commit comments

Comments
 (0)