Skip to content

Implement Firebase Auth UseUserAccessGroup for C++ SDK #1758

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 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions auth/src/android/auth_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -676,5 +676,14 @@ void DisableTokenAutoRefresh(AuthData* auth_data) {}
void InitializeTokenRefresher(AuthData* auth_data) {}
void DestroyTokenRefresher(AuthData* auth_data) {}

// Stub implementation for UseUserAccessGroupInternal on Android.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Desktop needs this too.

AuthError UseUserAccessGroupInternal(AuthData* auth_data,
const char* group_id) {
// This function is a no-op on Android.
(void)auth_data;
(void)group_id;
return kAuthErrorNone;
}

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

AUTH_RESULT_FN(Auth, CreateUserWithEmailAndPassword, AuthResult)

// Platform-specific implementation of UseUserAccessGroup.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't pu tthe platform-specific implementation here, put it in auth_android and auth_desktop and auth_ios.

// This is defined in auth_ios.mm for iOS, and auth_stub.cc for other
// platforms.
AuthError UseUserAccessGroupInternal(AuthData* auth_data,
const char* group_id);

AuthError Auth::UseUserAccessGroup(const char* group_id) {
if (!auth_data_) {
return kAuthErrorUninitialized;
}
return UseUserAccessGroupInternal(auth_data_, group_id);
}

} // namespace auth
} // namespace firebase
17 changes: 17 additions & 0 deletions auth/src/include/firebase/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,23 @@ class Auth {
/// not available on the current device.
static Auth* GetAuth(App* app, InitResult* init_result_out = nullptr);

/// @brief Sets the user access group to use for data sharing for the app.
///
/// This method is only applicable to iOS. On other platforms, it's a no-op
/// and will return `kAuthErrorNone`.
///
/// Sets the user access group to use for data sharing for the app. This
/// should be used to share authentication data between apps that have the
/// same access group.
///
/// @param[in] group_id The user access group to use. For example,
/// `com.example.accessgroup`. Set to `nullptr` or an empty string to clear
/// a previously set value and use the default keychain group.
///
/// @return Returns `kAuthErrorNone` on success, or an `AuthError` code if an
/// error occurred.
AuthError UseUserAccessGroup(const char* group_id);

private:
/// @cond FIREBASE_APP_INTERNAL
friend class ::firebase::App;
Expand Down
12 changes: 12 additions & 0 deletions auth/src/ios/auth_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -608,5 +608,17 @@ void DisableTokenAutoRefresh(AuthData *auth_data) {}
void InitializeTokenRefresher(AuthData *auth_data) {}
void DestroyTokenRefresher(AuthData *auth_data) {}

AuthError UseUserAccessGroupInternal(AuthData* auth_data,
const char* group_id) {
NSString* group_id_nsstring = nil;
if (group_id != nullptr && strlen(group_id) > 0) {
group_id_nsstring = [NSString stringWithUTF8String:group_id];
}

NSError* ns_error = nil;
[AuthImpl(auth_data) useUserAccessGroup:group_id_nsstring error:&ns_error];
return AuthErrorFromNSError(ns_error);
}

} // namespace auth
} // namespace firebase
35 changes: 35 additions & 0 deletions auth/src/stub/auth_stub.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2023 Google LLC
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 file should not exist, please put the stub implementations in the Android and Desktop files that already exist.

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "auth/src/include/firebase/auth_error.h"
#include "auth/src/common.h" // For AuthData

namespace firebase {
namespace auth {

// Stub implementation for UseUserAccessGroupInternal on non-iOS platforms.
AuthError UseUserAccessGroupInternal(AuthData* auth_data,
const char* group_id) {
// This function is a no-op on non-iOS platforms.
(void)auth_data;
(void)group_id;
return kAuthErrorNone;
}

// Other stub functions that are not implemented on desktop/non-mobile
// should also go here. For example, if there were other iOS or Android
// specific internal functions called from auth.cc

} // namespace auth
} // namespace firebase
Loading