Skip to content

Remove deprecated Auth function from C++ SDK #1767

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 6 commits 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
29 changes: 0 additions & 29 deletions auth/integration_test/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,6 @@ TEST_F(FirebaseAuthTest, TestOperationsOnInvalidUser) {
WaitForCompletionOrInvalidStatus(string_future, "GetToken");
EXPECT_NE(string_future.error(), firebase::auth::kAuthErrorNone);

LogDebug("Update Email");
void_future = invalid_user.UpdateEmail(GenerateEmailAddress().c_str());
WaitForCompletionOrInvalidStatus(void_future, "UpdateEmail");
EXPECT_NE(void_future.error(), firebase::auth::kAuthErrorNone);

LogDebug("Update Password");
void_future = invalid_user.UpdatePassword(kTestPassword);
WaitForCompletionOrInvalidStatus(void_future, "UpdatePassword");
Expand Down Expand Up @@ -758,30 +753,6 @@ TEST_F(FirebaseAuthTest, TestUpdateUserProfileEmpty) {
DeleteUser();
}

TEST_F(FirebaseAuthTest, TestUpdateEmailAndPassword) {
std::string email = GenerateEmailAddress();
WaitForCompletion(
auth_->CreateUserWithEmailAndPassword(email.c_str(), kTestPassword),
"CreateUserWithEmailAndPassword");
firebase::auth::User user = auth_->current_user();
EXPECT_TRUE(user.is_valid());

// Update the user's email and password.
const std::string new_email = "new_" + email;
WaitForCompletion(user.UpdateEmail(new_email.c_str()), "UpdateEmail");
WaitForCompletion(user.UpdatePassword(kTestPasswordUpdated),
"UpdatePassword");

firebase::auth::Credential new_email_cred =
firebase::auth::EmailAuthProvider::GetCredential(new_email.c_str(),
kTestPasswordUpdated);
WaitForCompletion(user.Reauthenticate(new_email_cred), "Reauthenticate");
EXPECT_TRUE(user.is_valid());

WaitForCompletion(user.SendEmailVerification(), "SendEmailVerification");
DeleteUser();
}

TEST_F(FirebaseAuthTest, TestVerifyBeforeUpdatingEmail) {
std::string email = GenerateEmailAddress();
WaitForCompletion(
Expand Down
17 changes: 0 additions & 17 deletions auth/samples/src/doc_samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,23 +360,6 @@ void VariousUserManagementChecks(firebase::auth::Auth* auth) {
}
// [END auth_profile_edit_check]
}
{
// [START auth_set_email_check]
firebase::auth::User user = auth->current_user();
if (user.is_valid()) {
user.UpdateEmail("[email protected]")
.OnCompletion(
[](const firebase::Future<void>& completed_future,
void* user_data) {
// We are probably in a different thread right now.
if (completed_future.error() == 0) {
printf("User email address updated.");
}
},
nullptr);
}
// [END auth_set_email_check]
}
{
// [START auth_user_verify_email_check]
firebase::auth::User user = auth->current_user();
Expand Down
22 changes: 0 additions & 22 deletions auth/src/android/user_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ METHOD_LOOKUP_DEFINITION(tokenresult,
X(IsAnonymous, "isAnonymous", "()Z"), \
X(Token, "getIdToken", "(Z)Lcom/google/android/gms/tasks/Task;"), \
X(ProviderData, "getProviderData", "()Ljava/util/List;"), \
X(UpdateEmail, "updateEmail", "(Ljava/lang/String;)" \
"Lcom/google/android/gms/tasks/Task;"), \
X(VerifyBeforeUpdateEmail, "verifyBeforeUpdateEmail", \
"(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task;"), \
X(UpdatePassword, "updatePassword", "(Ljava/lang/String;)" \
Expand Down Expand Up @@ -353,26 +351,6 @@ std::vector<UserInfoInterface> User::provider_data() const {
return provider_data;
}

Future<void> User::UpdateEmail(const char* email) {
if (!ValidUser(auth_data_)) {
return Future<void>();
}
ReferenceCountedFutureImpl& futures = auth_data_->future_impl;
const auto handle = futures.SafeAlloc<void>(kUserFn_UpdateEmail);
JNIEnv* env = Env(auth_data_);

jstring j_email = env->NewStringUTF(email);
jobject pending_result = env->CallObjectMethod(
UserImpl(auth_data_), user::GetMethodId(user::kUpdateEmail), j_email);
env->DeleteLocalRef(j_email);

if (!CheckAndCompleteFutureOnError(env, &futures, handle)) {
RegisterCallback(pending_result, handle, auth_data_, nullptr);
env->DeleteLocalRef(pending_result);
}
return MakeFuture(&futures, handle);
}

Future<void> User::UpdatePassword(const char* password) {
if (!ValidUser(auth_data_)) {
return Future<void>();
Expand Down
14 changes: 0 additions & 14 deletions auth/src/desktop/rpcs/set_account_info_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ SetAccountInfoRequest::SetAccountInfoRequest(::firebase::App& app,
application_data_->returnSecureToken = true;
}

std::unique_ptr<SetAccountInfoRequest>
SetAccountInfoRequest::CreateUpdateEmailRequest(::firebase::App& app,
const char* const api_key,
const char* const email) {
auto request = CreateRequest(app, api_key);
if (email) {
request->application_data_->email = email;
} else {
LogError("No email given");
}
request->UpdatePostFields();
return request;
}

std::unique_ptr<SetAccountInfoRequest>
SetAccountInfoRequest::CreateUpdatePasswordRequest(
::firebase::App& app, const char* const api_key, const char* const password,
Expand Down
2 changes: 0 additions & 2 deletions auth/src/desktop/rpcs/set_account_info_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ namespace auth {

class SetAccountInfoRequest : public AuthRequest {
public:
static std::unique_ptr<SetAccountInfoRequest> CreateUpdateEmailRequest(
::firebase::App& app, const char* api_key, const char* email);
static std::unique_ptr<SetAccountInfoRequest> CreateUpdatePasswordRequest(
::firebase::App& app, const char* api_key, const char* password,
const char* language_code = nullptr);
Expand Down
28 changes: 0 additions & 28 deletions auth/src/desktop/user_desktop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -835,34 +835,6 @@ Future<void> User::Reload() {
callback);
}

Future<void> User::UpdateEmail(const char* const email) {
if (auth_data_ == nullptr) { // user is not valid
return Future<void>(); // invalid future
}
Promise<void> promise(&auth_data_->future_impl, kUserFn_UpdateEmail);
if (!ValidateCurrentUser(&promise, auth_data_)) {
return promise.LastResult();
}
if (!ValidateEmail(&promise, email)) {
return promise.LastResult();
}
if (!ValidateCurrentUser(&promise, auth_data_)) {
return promise.LastResult();
}

const char* language_code = nullptr;
auto auth_impl = static_cast<AuthImpl*>(auth_data_->auth_impl);
if (!auth_impl->language_code.empty()) {
language_code = auth_impl->language_code.c_str();
}

typedef SetAccountInfoRequest RequestT;
auto request = RequestT::CreateUpdateEmailRequest(
*auth_data_->app, GetApiKey(*auth_data_), email);
return CallAsyncWithFreshToken(auth_data_, promise, std::move(request),
PerformSetAccountInfoFlow<void>);
}

Future<void> User::UpdatePassword(const char* const password) {
if (auth_data_ == nullptr) { // user is not valid
return Future<void>(); // invalid future
Expand Down
14 changes: 0 additions & 14 deletions auth/src/include/firebase/auth/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,20 +229,6 @@ class User : public UserInfoInterface {
/// </SWIG>
std::vector<UserInfoInterface> provider_data() const;

/// @deprecated This is a deprecated method. Please use
/// SendEmailVerificationBeforeUpdatingEmail(email) instead.
///
/// Sets the email address for the user.
///
/// May fail if there is already an email/password-based account for the same
/// email address.
FIREBASE_DEPRECATED Future<void> UpdateEmail(const char* email);

/// @deprecated
///
/// Get results of the most recent call to UpdateEmail.
FIREBASE_DEPRECATED Future<void> UpdateEmailLastResult() const;

/// Attempts to change the password for the current user.
///
/// For an account linked to an Identity Provider (IDP) with no password,
Expand Down
14 changes: 0 additions & 14 deletions auth/src/ios/user_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,6 @@ explicit IOSWrappedUserInfo(id<FIRUserInfo> user_info) : user_info_(user_info) {
return provider_data;
}

Future<void> User::UpdateEmail(const char *email) {
if (!ValidUser(auth_data_)) {
return Future<void>();
}
ReferenceCountedFutureImpl &futures = auth_data_->future_impl;
const auto handle = futures.SafeAlloc<void>(kUserFn_UpdateEmail);
[UserImpl(auth_data_) updateEmail:@(email)
completion:^(NSError *_Nullable error) {
futures.Complete(handle, AuthErrorFromNSError(error),
[error.localizedDescription UTF8String]);
}];
return MakeFuture(&futures, handle);
}

Future<void> User::UpdatePassword(const char *password) {
if (!ValidUser(auth_data_)) {
return Future<void>();
Expand Down
1 change: 0 additions & 1 deletion auth/src/user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace firebase {
namespace auth {

AUTH_RESULT_FN(User, GetToken, std::string)
AUTH_RESULT_FN(User, UpdateEmail, void)
AUTH_RESULT_FN(User, UpdatePassword, void)
AUTH_RESULT_FN(User, LinkWithCredential, AuthResult)
AUTH_RESULT_FN(User, Reauthenticate, void)
Expand Down
51 changes: 0 additions & 51 deletions auth/tests/desktop/user_desktop_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,6 @@ TEST_F(UserDesktopTest, TestReload) {
VerifyProviderData(firebase_user_);
}

// Tests the happy case of setting a new email on the currently logged in user.
TEST_F(UserDesktopTest, TestUpdateEmail) {
InitializeConfigWithAFake(GetUrlForApi(API_KEY, "setAccountInfo"),
FakeSetAccountInfoResponse());

// SetAccountInfoResponse contains a new token.
id_token_listener.ExpectChanges(1);
auth_state_listener.ExpectChanges(0);

const std::string new_email = "[email protected]";

EXPECT_NE(new_email, firebase_user_.email());
WaitForFuture(firebase_user_.UpdateEmail(new_email.c_str()));
EXPECT_EQ(new_email, firebase_user_.email());
VerifyProviderData(firebase_user_);
}

// Tests the happy case of setting a new password on the currently logged in
// user.
TEST_F(UserDesktopTest, TestUpdatePassword) {
Expand Down Expand Up @@ -815,16 +798,6 @@ TEST_F(UserDesktopTestSignOutOnError, Reload) {
sem_.Wait();
}

TEST_F(UserDesktopTestSignOutOnError, UpdateEmail) {
CheckSignOutIfUserIsInvalid(
GetUrlForApi(API_KEY, "setAccountInfo"), "USER_NOT_FOUND",
kAuthErrorUserNotFound, [&] {
sem_.Post();
return firebase_user_.UpdateEmail("[email protected]");
});
sem_.Wait();
}

TEST_F(UserDesktopTestSignOutOnError, UpdatePassword) {
CheckSignOutIfUserIsInvalid(
GetUrlForApi(API_KEY, "setAccountInfo"), "USER_DISABLED",
Expand Down Expand Up @@ -881,30 +854,6 @@ TEST_F(UserDesktopTestSignOutOnError, GetToken) {
sem_.Wait();
}

// This test is to expose potential race condition and is primarily intended to
// be run with --config=tsan
TEST_F(UserDesktopTest, TestRaceCondition_SetAccountInfoAndSignOut) {
InitializeConfigWithAFake(GetUrlForApi(API_KEY, "setAccountInfo"),
FakeSetAccountInfoResponse());

// SignOut is engaged on the main thread, whereas UpdateEmail will be executed
// on the background thread; consequently, the order in which they are
// executed is not defined. Nevertheless, this should not lead to any data
// corruption, when UpdateEmail writes to user profile while it's being
// deleted by SignOut. Whichever method succeeds first, user must be signed
// out once both are finished: if SignOut finishes last, it overrides the
// updated user, and if UpdateEmail finishes last, it should note that there
// is no currently signed in user and fail with kAuthErrorUserNotFound.

auto future = firebase_user_.UpdateEmail("some_email");
firebase_auth_->SignOut();
while (future.status() == firebase::kFutureStatusPending) {
}

EXPECT_THAT(future.error(), AnyOf(kAuthErrorNone, kAuthErrorNoSignedInUser));
EXPECT_FALSE(firebase_auth_->current_user().is_valid());
}

// LinkWithProvider tests.
TEST_F(UserDesktopTest, TestLinkWithProviderReturnsUnsupportedError) {
FederatedOAuthProvider provider;
Expand Down
30 changes: 0 additions & 30 deletions auth/tests/user_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,36 +258,6 @@ TEST_F(UserTest, TestGetProviderData) {
EXPECT_TRUE(provider.empty());
}

TEST_F(UserTest, TestUpdateEmail) {
const std::string config =
std::string(
"{"
" config:["
" {fake:'FirebaseUser.updateEmail', futuregeneric:{ticker:1}},"
" {fake:'FIRUser.updateEmail:completion:', futuregeneric:"
"{ticker:1}},") +
SET_ACCOUNT_INFO_SUCCESSFUL_RESPONSE +
" ]"
"}";
firebase::testing::cppsdk::ConfigSet(config.c_str());

EXPECT_NE("[email protected]", firebase_user_.email());
Future<void> result = firebase_user_.UpdateEmail("[email protected]");

// Fake Android & iOS implemented the delay. Desktop stub completed immediately.
#if defined(FIREBASE_ANDROID_FOR_DESKTOP) || FIREBASE_PLATFORM_IOS || \
FIREBASE_PLATFORM_TVOS
EXPECT_EQ(firebase::kFutureStatusPending, result.status());
EXPECT_NE("[email protected]", firebase_user_.email());
firebase::testing::cppsdk::TickerElapse();
#endif // defined(FIREBASE_ANDROID_FOR_DESKTOP) || FIREBASE_PLATFORM_IOS ||
// FIREBASE_PLATFORM_TVOS
MaybeWaitForFuture(result);
EXPECT_EQ(firebase::kFutureStatusComplete, result.status());
EXPECT_EQ(0, result.error());
EXPECT_EQ("[email protected]", firebase_user_.email());
}

TEST_F(UserTest, TestUpdatePassword) {
const std::string config =
std::string(
Expand Down
6 changes: 1 addition & 5 deletions release_build_files/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,7 @@ code.
## Release Notes
### Upcoming Release
- Changes
- iOS: Added an option to explicitly specify your app's `AppDelegate` class
name via the `FirebaseAppDelegateClassName` key in `Info.plist`. This
provides a more direct way for Firebase to interact with your specified
AppDelegate. See "Platform Notes > iOS Method Swizzling >
Specifying Your AppDelegate Class Directly (iOS)" for details.
- Auth: Removed deprecated `User::UpdateEmail` method.

### 12.8.0
- Changes
Expand Down
Loading