Skip to content

Commit 435d263

Browse files
Implemented Auth::UseUserAccessGroup for iOS and stubbed for other platforms.
This method allows specifying a Keychain Access Group for sharing user authentication data across multiple apps on iOS. It is a no-op on Android and desktop platforms.
1 parent 2240e3c commit 435d263

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed

auth/src/android/auth_android.cc

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

679+
AuthError Auth::UseUserAccessGroup(const char* access_group) {
680+
return kAuthErrorUnimplemented;
681+
}
682+
679683
} // namespace auth
680684
} // namespace firebase

auth/src/auth.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,5 +373,14 @@ AUTH_RESULT_FN(Auth, SignInWithEmailAndPassword, AuthResult)
373373

374374
AUTH_RESULT_FN(Auth, CreateUserWithEmailAndPassword, AuthResult)
375375

376+
AuthError Auth::UseUserAccessGroup(const char* access_group) {
377+
if (!auth_data_) return kAuthErrorUninitialized;
378+
#if FIREBASE_PLATFORM_IOS
379+
return UseUserAccessGroupInternal(auth_data_, access_group);
380+
#else
381+
return kAuthErrorUnimplemented;
382+
#endif // FIREBASE_PLATFORM_IOS
383+
}
384+
376385
} // namespace auth
377386
} // namespace firebase

auth/src/desktop/auth_desktop.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ void DestroyUserDataPersist(AuthData* auth_data) {
632632
auth_data->auth->RemoveAuthStateListener(auth_impl->user_data_persist.get());
633633
}
634634

635+
AuthError Auth::UseUserAccessGroup(const char* access_group) {
636+
return kAuthErrorUnimplemented;
637+
}
638+
635639
void LoadFinishTriggerListeners(AuthData* auth_data) {
636640
MutexLock destructing_lock(auth_data->destructing_mutex);
637641
if (auth_data->destructing) {

auth/src/include/firebase/auth.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,17 @@ class Auth {
497497
/// emulator.
498498
///
499499
void UseEmulator(std::string host, uint32_t port);
500+
501+
/// @brief Sets the user access group to use for data sharing.
502+
///
503+
/// This method is only functional on iOS. On other platforms, it will
504+
/// immediately return kAuthErrorUnimplemented.
505+
///
506+
/// @param[in] access_group The access group to use.
507+
///
508+
/// @return kAuthErrorNone on success, or an AuthError code if an error
509+
/// occurred.
510+
AuthError UseUserAccessGroup(const char* access_group);
500511
#endif //! defined(DOXYGEN), to hide the api from public documentation.
501512

502513
/// Gets the App this auth object is connected to.

auth/src/ios/auth_ios.mm

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

611+
AuthError UseUserAccessGroupInternal(AuthData* auth_data, const char* access_group) {
612+
NSString* access_group_ns_string = access_group ? @(access_group) : nil;
613+
NSError* error = nil;
614+
BOOL success = [AuthImpl(auth_data) useUserAccessGroup:access_group_ns_string error:&error];
615+
if (!success) {
616+
return AuthErrorFromNSError(error);
617+
}
618+
return kAuthErrorNone;
619+
}
620+
611621
} // namespace auth
612622
} // namespace firebase

auth/src/ios/common_ios.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ void SignInCallback(FIRUser *_Nullable user, NSError *_Nullable error,
137137
/// like user interaction errors, they are actually caused by bad provider ids.
138138
NSError *RemapBadProviderIDErrors(NSError *_Nonnull error);
139139

140+
// iOS-specific implementation of Auth::UseUserAccessGroup.
141+
AuthError UseUserAccessGroupInternal(AuthData* auth_data, const char* access_group);
142+
140143
} // namespace auth
141144
} // namespace firebase
142145

0 commit comments

Comments
 (0)