Skip to content

feat: Implement UseUserAccessGroup for iOS #1750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions auth/src/android/auth_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,5 +676,13 @@ void DisableTokenAutoRefresh(AuthData* auth_data) {}
void InitializeTokenRefresher(AuthData* auth_data) {}
void DestroyTokenRefresher(AuthData* auth_data) {}

#if !FIREBASE_PLATFORM_IOS
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the #if.

// Stub for non-iOS platforms.
void Auth::UseUserAccessGroup(const char* user_access_group) {
// This function is only implemented on iOS.
(void)user_access_group; // Mark as used to avoid compiler warnings.
}
#endif // !FIREBASE_PLATFORM_IOS

} // namespace auth
} // namespace firebase
8 changes: 8 additions & 0 deletions auth/src/auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,5 +373,13 @@ AUTH_RESULT_FN(Auth, SignInWithEmailAndPassword, AuthResult)

AUTH_RESULT_FN(Auth, CreateUserWithEmailAndPassword, AuthResult)

#if !FIREBASE_PLATFORM_IOS
// Stub for non-iOS platforms.
void Auth::UseUserAccessGroup(const char* user_access_group) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function isn't necessary in this file, since it's covered in all 3 platform-specific files.

// This function is only implemented on iOS.
(void)user_access_group; // Mark as used to avoid compiler warnings.
}
#endif // !FIREBASE_PLATFORM_IOS

} // namespace auth
} // namespace firebase
8 changes: 8 additions & 0 deletions auth/src/desktop/auth_desktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -768,5 +768,13 @@ void IdTokenRefreshThread::DisableAuthRefresh() {
ref_count_--;
}

#if !FIREBASE_PLATFORM_IOS
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the #if here.

// Stub for non-iOS platforms.
void Auth::UseUserAccessGroup(const char* user_access_group) {
// This function is only implemented on iOS.
(void)user_access_group; // Mark as used to avoid compiler warnings.
}
#endif // !FIREBASE_PLATFORM_IOS

} // namespace auth
} // namespace firebase
18 changes: 18 additions & 0 deletions auth/src/include/firebase/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,24 @@ class Auth {
/// Get results of the most recent call to SendPasswordResetEmail.
Future<void> SendPasswordResetEmailLastResult() const;

/// @brief Specifies a user access group for keychain data sharing for the
/// current app.
///
/// @details This method is only functional on iOS. On other platforms, it is
/// a no-op.
///
/// Setting this will allow the application to share user credentials with
/// other applications that are members of the same access group.
///
/// After this is called, all future get and set keychain operations will use
/// the new user access group. By default, this is nil and credentials are
/// only accessible by the current application.
///
/// @param[in] user_access_group The user access group string to use.
/// Pass `nullptr` or an empty string to reset to the default (app-only)
/// access group.
void UseUserAccessGroup(const char* user_access_group);

#ifndef SWIG
/// @brief Registers a listener to changes in the authentication state.
///
Expand Down
17 changes: 17 additions & 0 deletions auth/src/ios/auth_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,22 @@ void DisableTokenAutoRefresh(AuthData *auth_data) {}
void InitializeTokenRefresher(AuthData *auth_data) {}
void DestroyTokenRefresher(AuthData *auth_data) {}

void Auth::UseUserAccessGroup(const char* user_access_group) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the method to return AuthError so we can properly handle if any error is returned.

if (!auth_data_) return;
NSString* access_group_nsstring = nil;
if (user_access_group != nullptr && strlen(user_access_group) > 0) {
access_group_nsstring = [NSString stringWithUTF8String:user_access_group];
}

NSError* error = nil;
BOOL success = [AuthImpl(auth_data_) useUserAccessGroup:access_group_nsstring error:&error];
if (!success || error) {
LogWarning("Error setting user access group: %s",
[[error localizedDescription] UTF8String]);
// Note: The C++ method is void, so we're not propagating the error further up.
// If specific error handling is needed in C++, the method signature would need to change.
}
}

} // namespace auth
} // namespace firebase
Loading