Skip to content
Merged
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
24 changes: 13 additions & 11 deletions auth/integration_test/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ void FirebaseAuthTest::Initialize() {

::firebase::ModuleInitializer initializer;
initializer.Initialize(app_, &auth_, [](::firebase::App* app, void* target) {
LogDebug("Try to initialize Firebase Auth");
firebase::InitResult result;
firebase::auth::Auth** auth_ptr =
reinterpret_cast<firebase::auth::Auth**>(target);
Expand All @@ -176,8 +175,6 @@ void FirebaseAuthTest::Initialize() {
ASSERT_EQ(initializer.InitializeLastResult().error(), 0)
<< initializer.InitializeLastResult().error_message();

LogDebug("Successfully initialized Firebase Auth.");

initialized_ = true;
}

Expand Down Expand Up @@ -516,8 +513,9 @@ TEST_F(FirebaseAuthTest, TestLinkAnonymousUserWithEmailCredential) {
firebase::auth::Credential credential =
firebase::auth::EmailAuthProvider::GetCredential(email.c_str(),
kTestPassword);
WaitForCompletion(user->LinkAndRetrieveDataWithCredential(credential),
"LinkAndRetrieveDataWithCredential");
WaitForCompletion(
user->LinkAndRetrieveDataWithCredential_DEPRECATED(credential),
"LinkAndRetrieveDataWithCredential_DEPRECATED");
WaitForCompletion(user->Unlink_DEPRECATED(credential.provider().c_str()),
"Unlink");
SignOut();
Expand Down Expand Up @@ -768,10 +766,12 @@ TEST_F(FirebaseAuthTest, TestAuthPersistenceWithEmailSignin) {
// Save the old provider ID list so we can make sure it's the same once
// it's loaded again.
std::vector<std::string> prev_provider_data_ids;
for (int i = 0; i < auth_->current_user_DEPRECATED()->provider_data().size();
for (int i = 0;
i < auth_->current_user_DEPRECATED()->provider_data_DEPRECATED().size();
i++) {
prev_provider_data_ids.push_back(
auth_->current_user_DEPRECATED()->provider_data()[i]->provider_id());
prev_provider_data_ids.push_back(auth_->current_user_DEPRECATED()
->provider_data_DEPRECATED()[i]
->provider_id());
}
Terminate();
ProcessEvents(2000);
Expand All @@ -782,10 +782,12 @@ TEST_F(FirebaseAuthTest, TestAuthPersistenceWithEmailSignin) {
// Make sure the provider IDs are the same as they were before.
EXPECT_EQ(auth_->current_user_DEPRECATED()->provider_id(), prev_provider_id);
std::vector<std::string> loaded_provider_data_ids;
for (int i = 0; i < auth_->current_user_DEPRECATED()->provider_data().size();
for (int i = 0;
i < auth_->current_user_DEPRECATED()->provider_data_DEPRECATED().size();
i++) {
loaded_provider_data_ids.push_back(
auth_->current_user_DEPRECATED()->provider_data()[i]->provider_id());
loaded_provider_data_ids.push_back(auth_->current_user_DEPRECATED()
->provider_data_DEPRECATED()[i]
->provider_id());
}
EXPECT_TRUE(loaded_provider_data_ids == prev_provider_data_ids);

Expand Down
1 change: 0 additions & 1 deletion auth/src/auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ Auth* Auth::GetAuth(App* app, InitResult* init_result_out) {

// Create a new Auth and initialize.
Auth* auth = new Auth(app, auth_impl);
LogDebug("Creating Auth %p for App %p", auth, app);

// Stick it in the global map so we remember it, and can delete it on
// shutdown.
Expand Down
58 changes: 58 additions & 0 deletions auth/src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
namespace firebase {
namespace auth {

const char* kUserNotInitializedErrorMessage =
"Operation attmpted on an invalid User object.";
const char* kPhoneAuthNotSupportedErrorMessage =
"Phone Auth is not supported on this platform.";

// static member variables
const uint32_t PhoneAuthProvider::kMaxTimeoutMs = 3000;

Expand All @@ -47,6 +52,59 @@ ReferenceCountedFutureImpl* GetCredentialFutureImpl() {
return future_data->api();
}

void CompleteFuture(int error, const char* error_msg,
SafeFutureHandle<void> handle, FutureData* future_data) {
if (future_data->future_impl.ValidFuture(handle)) {
future_data->future_impl.Complete(handle, error, error_msg);
}
}

void CompleteFuture(int error, const char* error_msg,
SafeFutureHandle<std::string> handle,
FutureData* future_data, const std::string& result) {
if (future_data->future_impl.ValidFuture(handle)) {
future_data->future_impl.CompleteWithResult(handle, error, error_msg,
result);
}
}

void CompleteFuture(int error, const char* error_msg,
SafeFutureHandle<User*> handle, FutureData* future_data,
User* user) {
if (future_data->future_impl.ValidFuture(handle)) {
future_data->future_impl.CompleteWithResult(handle, error, error_msg, user);
}
}

void CompleteFuture(int error, const char* error_msg,
SafeFutureHandle<SignInResult> handle,
FutureData* future_data, SignInResult sign_in_result) {
if (future_data->future_impl.ValidFuture(handle)) {
future_data->future_impl.CompleteWithResult(handle, error, error_msg,
sign_in_result);
}
}

// For calls that aren't asynchronous, we can create and complete at the
// same time.
Future<void> CreateAndCompleteFuture(int fn_idx, int error,
const char* error_msg,
FutureData* future_data) {
SafeFutureHandle<void> handle = CreateFuture<void>(fn_idx, future_data);
CompleteFuture(error, error_msg, handle, future_data);
return MakeFuture(&future_data->future_impl, handle);
}

Future<std::string> CreateAndCompleteFuture(int fn_idx, int error,
const char* error_msg,
FutureData* future_data,
const std::string& result) {
SafeFutureHandle<std::string> handle =
CreateFuture<std::string>(fn_idx, future_data);
CompleteFuture(error, error_msg, handle, future_data, result);
return MakeFuture(&future_data->future_impl, handle);
}

void CleanupCredentialFutureImpl() {
StaticFutureData::CleanupFutureDataForModule(&kCredentialFutureIdentifier);
}
Expand Down
62 changes: 61 additions & 1 deletion auth/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@
#ifndef FIREBASE_AUTH_SRC_COMMON_H_
#define FIREBASE_AUTH_SRC_COMMON_H_

#include <string>

#include "auth/src/data.h"

namespace firebase {
namespace auth {

// Error messages used for completing futures. These match the error codes in
// the AdErrorCode enumeration in the C++ API.
extern const char* kUserNotInitializedErrorMessage;
extern const char* kPhoneAuthNotSupportedErrorMessage;

// Enumeration for Credential API functions that return a Future.
// This allows us to hold a Future for the most recent call to that API.
enum CredentialApiFunction {
Expand All @@ -30,6 +37,59 @@ enum CredentialApiFunction {
kNumCredentialFunctions
};

// Hold backing data for returned Futures.
struct FutureData {
explicit FutureData(int num_functions_that_return_futures)
: future_impl(num_functions_that_return_futures) {}

// Handle calls from Futures that the API returns.
ReferenceCountedFutureImpl future_impl;
};

template <class T>
struct FutureCallbackData {
FutureData* future_data;
SafeFutureHandle<T> future_handle;
};

// Create a future and update the corresponding last result.
template <class T>
SafeFutureHandle<T> CreateFuture(int fn_idx, FutureData* future_data) {
return future_data->future_impl.SafeAlloc<T>(fn_idx);
}

// Mark a Future<void> as complete.
void CompleteFuture(int error, const char* error_msg,
SafeFutureHandle<void> handle, FutureData* future_data);

// Mark a Future<std::string> as complete
void CompleteFuture(int error, const char* error_msg,
SafeFutureHandle<std::string> handle,
FutureData* future_data, const std::string& result);

// Mark a Future<User *> as complete
void CompleteFuture(int error, const char* error_msg,
SafeFutureHandle<User*> handle, FutureData* future_data,
User* user);

// Mark a Future<SignInResult> as complete
void CompleteFuture(int error, const char* error_msg,
SafeFutureHandle<SignInResult> handle,
FutureData* future_data, SignInResult result);

// For calls that aren't asynchronous, create and complete a Future<void> at
// the same time.
Future<void> CreateAndCompleteFuture(int fn_idx, int error,
const char* error_msg,
FutureData* future_data);

// For calls that aren't asynchronous, create and complete a
// Future<std::string> at the same time.
Future<std::string> CreateAndCompleteFuture(int fn_idx, int error,
const char* error_msg,
FutureData* future_data,
const std::string& result);

// Platform-specific method to create the wrapped Auth class.
void* CreatePlatformAuth(App* app);

Expand Down Expand Up @@ -62,7 +122,7 @@ void LogHeartbeat(Auth* auth);

// Returns true if `auth_data` has a user that's currently active.
inline bool ValidUser(const AuthData* auth_data) {
return auth_data->user_impl != nullptr;
return auth_data->deprecated_fields.user_deprecated->is_valid();
}

// Notify all the listeners of the state change.
Expand Down
52 changes: 34 additions & 18 deletions auth/src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
namespace firebase {
namespace auth {

// @deprecated
//
// Fields that should be removed when the Auth Breaking Changes Deprecation
// window ends.
struct AuthDataDeprecatedFields {
// Used to return User* objects from deprecated methods.
User* user_deprecated;

// Internal implementation of user_deprecated. This object's contains a
// pointer the platform specific user object, which is updated on User
// operations.
UserInternal* user_internal_deprecated;
};

// Enumeration for API functions that return a Future.
// This allows us to hold a Future for the most recent call to that API.
enum AuthApiFunction {
Expand All @@ -41,7 +55,15 @@ enum AuthApiFunction {
kAuthFn_CreateUserWithEmailAndPassword_DEPRECATED,
kAuthFn_SendPasswordResetEmail,

// External functions in the User API.
// Internal functions that are still handles, but are only used internally:
kInternalFn_GetTokenForRefresher,
kInternalFn_GetTokenForFunctionRegistry,

kAuthFnCount
};

// Constants representing each User function that returns a Future.
enum UserFn {
kUserFn_GetToken,
kUserFn_UpdateEmail,
kUserFn_UpdatePassword,
Expand All @@ -51,19 +73,15 @@ enum AuthApiFunction {
kUserFn_ConfirmEmailVerification,
kUserFn_UpdateUserProfile,
kUserFn_LinkWithCredential_DEPRECATED,
kUserFn_LinkAndRetrieveDataWithCredential,
kUserFn_LinkAndRetrieveDataWithCredential_DEPRECATED,
kUserFn_LinkWithProvider_DEPRECATED,
kUserFn_ReauthenticateWithProvider_DEPRECATED,
kUserFn_Unlink_DEPRECATED,
kUserFn_UpdatePhoneNumberCredential_DEPRECATED,
kUserFn_Reload,
kUserFn_Delete,

// Internal functions that are still handles, but are only used internally:
kInternalFn_GetTokenForRefresher,
kInternalFn_GetTokenForFunctionRegistry,

kNumAuthFunctions
kUserFnCount
};

/// Delete all the user_infos in auth_data and reset the length to zero.
Expand All @@ -76,10 +94,8 @@ struct AuthData {
AuthData()
: app(nullptr),
auth(nullptr),
future_impl(kNumAuthFunctions),
current_user(this),
future_impl(kAuthFnCount),
auth_impl(nullptr),
user_impl(nullptr),
listener_impl(nullptr),
id_token_listener_impl(nullptr),
expect_id_token_listener_callback(false),
Expand All @@ -96,7 +112,6 @@ struct AuthData {
app = nullptr;
auth = nullptr;
auth_impl = nullptr;
user_impl = nullptr;
listener_impl = nullptr;
id_token_listener_impl = nullptr;
}
Expand All @@ -116,23 +131,24 @@ struct AuthData {
/// Backpointer to the external Auth class that holds this internal data.
Auth* auth;

/// @deprecated Remove when Auth deprecation APIs are removed.
///
/// Contains a User object that's updated whenever the current user changes.
/// This is used to return User* values from deprecated Auth and User
/// methods. These methods have been replaced with methods that return
/// Users by value (now that we can copy users.)
AuthDataDeprecatedFields deprecated_fields;

/// Handle calls from Futures that the API returns.
ReferenceCountedFutureImpl future_impl;

/// Identifier used to track futures associated with future_impl.
std::string future_api_id;

/// Unique user for this Auth. Note: we only support one user per Auth.
User current_user;

/// Platform-dependent implementation of Auth (that we're wrapping).
/// For example, on Android `jobject`.
void* auth_impl;

/// Platform-dependent implementation of User (that we're wrapping).
/// For example, on iOS `FIRUser`.
void* user_impl;

/// Platform-dependent implementation of AuthStateListener (that we're
/// wrapping). For example, on Android `jobject`.
void* listener_impl;
Expand Down
46 changes: 45 additions & 1 deletion auth/src/desktop/user_desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,51 @@
namespace firebase {
namespace auth {

// LINT.IfChange
class UserInternal {
public:
// The user's ID, unique to the Firebase project.
std::string uid;

// The associated email, if any.
std::string email;

// The display name, if any.
std::string display_name;

// Associated photo url, if any.
std::string photo_url;

// A provider ID for the user e.g. "Facebook".
std::string provider_id;

// The user's phone number, if any.
std::string phone_number;

// Whether is anonymous.
bool is_anonymous;

// Whether email is verified.
bool is_email_verified;

// Tokens for authentication and authorization.
std::string id_token; // an authorization code or access_token
std::string refresh_token;
std::string access_token;

// The approximate expiration date of the access token.
std::time_t access_token_expiration_date;

// Whether or not the user can be authenticated by provider 'password'.
bool has_email_password_credential;

/// The last sign in UTC timestamp in milliseconds.
/// See https://en.wikipedia.org/wiki/Unix_time for details of UTC.
uint64_t last_sign_in_timestamp;

/// The Firebase user creation UTC timestamp in milliseconds.
uint64_t creation_timestamp;
};

// The desktop-specific UserInfo implementation.
struct UserInfoImpl {
// Note: since Visual Studio 2013 and below don't autogenerate move
Expand Down
Loading