Skip to content

Commit ba34419

Browse files
Googlera-maurice
authored andcommitted
Auth: C++ API support for existing Generic IDP implementation on iOS.
C++ API implementation calls into the Objective C Firebase Auth iOS SDK. Includes updates to the ios_testapp, integration tests, and a new ios_util function to handle converting Vectors of strings to NSMutableArrays. Moved the GetProviderId functions of the C++ providers to the header so that the implementation is common across all targets. Currently iOS does not support User linkWithProvider and reauthenticateWithProvider, but it's in the works. For now the implementation gets a credential and the uses that to linke/reauthenticate before returning the SignInResult. PiperOrigin-RevId: 262596855
1 parent e05fe72 commit ba34419

14 files changed

+188
-39
lines changed

app/src/util_ios.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ typedef BOOL (
138138
// blacklist we keep).
139139
void ForEachAppDelegateClass(void (^block)(Class));
140140

141+
// Convert a string array into an NSMutableArray.
142+
NSMutableArray *StringVectorToNSMutableArray(
143+
const std::vector<std::string> &vector);
144+
141145
// Convert a string map to NSDictionary.
142146
NSDictionary *StringMapToNSDictionary(
143147
const std::map<std::string, std::string> &string_map);

app/src/util_ios.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ void ForEachAppDelegateClass(void (^block)(Class)) {
157157
std::string();
158158
}
159159

160+
NSMutableArray *StringVectorToNSMutableArray(const std::vector<std::string> &vector) {
161+
NSMutableArray<NSString *> *array = [[NSMutableArray alloc] initWithCapacity:vector.size()];
162+
for (auto &element : vector) {
163+
[array addObject:StringToNSString(element)];
164+
}
165+
return array;
166+
}
167+
160168
NSMutableArray* StdVectorToNSMutableArray(const std::vector<Variant>& vector) {
161169
NSMutableArray* array =
162170
[[NSMutableArray alloc] initWithCapacity:vector.size()];

auth/src/data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ enum AuthApiFunction {
3838
kAuthFn_SignInAnonymously,
3939
kAuthFn_SignInWithEmailAndPassword,
4040
kAuthFn_SignInWithProvider,
41-
kAuthFn_LinkWithProvider,
42-
kAuthFn_ReauthenticateWithProvider,
4341
kAuthFn_CreateUserWithEmailAndPassword,
4442
kAuthFn_SendPasswordResetEmail,
4543

@@ -54,6 +52,8 @@ enum AuthApiFunction {
5452
kUserFn_UpdateUserProfile,
5553
kUserFn_LinkWithCredential,
5654
kUserFn_LinkAndRetrieveDataWithCredential,
55+
kUserFn_LinkWithProvider,
56+
kUserFn_ReauthenticateWithProvider,
5757
kUserFn_Unlink,
5858
kUserFn_UpdatePhoneNumberCredential,
5959
kUserFn_Reload,

auth/src/desktop/auth_providers/facebook_auth_provider.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,5 @@ Credential FacebookAuthProvider::GetCredential(const char* const access_token) {
2929
new CredentialImpl{new FacebookAuthCredential(access_token)}};
3030
}
3131

32-
// static
33-
const char* FacebookAuthProvider::GetProviderId() {
34-
return "facebook.com";
35-
}
36-
3732
} // namespace auth
3833
} // namespace firebase

auth/src/desktop/auth_providers/federated_auth_provider.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Future<SignInResult> CreateAuthFuture(AuthData* auth_data,
5959
auth_data->future_impl.CompleteWithResult(
6060
handle, kAuthErrorFederatedProviderAreadyInUse,
6161
"Provider operation already in progress.",
62-
/*SignInResult=*/{});
62+
/*result=*/{});
6363
return MakeFuture(&auth_data->future_impl, handle);
6464
} else if (future_base.status() == kFutureStatusInvalid) {
6565
// initialize the future.
@@ -94,7 +94,7 @@ Future<SignInResult> FederatedOAuthProvider::Link(AuthData* auth_data) {
9494
assert(auth_data);
9595
FIREBASE_ASSERT_RETURN(Future<SignInResult>(), handler_);
9696
Future<SignInResult> future =
97-
CreateAuthFuture(auth_data, kAuthFn_LinkWithProvider);
97+
CreateAuthFuture(auth_data, kUserFn_LinkWithProvider);
9898
if (future.status() == kFutureStatusPending) {
9999
AuthCompletionHandle* auth_completion_handle = new AuthCompletionHandle(
100100
SafeFutureHandle<SignInResult>(future.GetHandle()), auth_data);
@@ -108,7 +108,7 @@ Future<SignInResult> FederatedOAuthProvider::Reauthenticate(
108108
assert(auth_data);
109109
FIREBASE_ASSERT_RETURN(Future<SignInResult>(), handler_);
110110
Future<SignInResult> future =
111-
CreateAuthFuture(auth_data, kAuthFn_ReauthenticateWithProvider);
111+
CreateAuthFuture(auth_data, kUserFn_ReauthenticateWithProvider);
112112
if (future.status() == kFutureStatusPending) {
113113
AuthCompletionHandle* auth_completion_handle = new AuthCompletionHandle(
114114
SafeFutureHandle<SignInResult>(future.GetHandle()), auth_data);

auth/src/desktop/auth_providers/github_auth_provider.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,5 @@ Credential GitHubAuthProvider::GetCredential(const char* const token) {
2828
return Credential{new CredentialImpl{new GitHubAuthCredential(token)}};
2929
}
3030

31-
// static
32-
const char* GitHubAuthProvider::GetProviderId() {
33-
return "github.com";
34-
}
35-
3631
} // namespace auth
3732
} // namespace firebase

auth/src/desktop/auth_providers/google_auth_provider.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,5 @@ Credential GoogleAuthProvider::GetCredential(const char* const id_token,
3737
}
3838
}
3939

40-
// static
41-
const char* GoogleAuthProvider::GetProviderId() {
42-
return "google.com";
43-
}
44-
4540
} // namespace auth
4641
} // namespace firebase

auth/src/desktop/auth_providers/playgames_auth_provider.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,5 @@ Credential PlayGamesAuthProvider::GetCredential(
3030
new CredentialImpl{new PlayGamesAuthCredential(server_auth_code)}};
3131
}
3232

33-
// static
34-
const char* PlayGamesAuthProvider::GetProviderId() {
35-
return "playgames.google.com";
36-
}
37-
3833
} // namespace auth
3934
} // namespace firebase

auth/src/desktop/auth_providers/twitter_auth_provider.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,5 @@ Credential TwitterAuthProvider::GetCredential(const char* const token,
3030
new CredentialImpl{new TwitterAuthCredential(token, secret)}};
3131
}
3232

33-
// static
34-
const char* TwitterAuthProvider::GetProviderId() {
35-
return "twitter.com";
36-
}
37-
3833
} // namespace auth
3934
} // namespace firebase

auth/src/include/firebase/auth/credential.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class FacebookAuthProvider {
151151
/// @see Auth::SignInWithProvider
152152
/// @see User::ReauthenticateWithProvider
153153
/// @see User::LinkWithProvider
154-
static const char* GetProviderId();
154+
static const char* GetProviderId() { return "facebook.com"; }
155155
#endif // INTERNAL_EXPERIMENTAL
156156
};
157157

@@ -173,7 +173,7 @@ class GitHubAuthProvider {
173173
/// @see Auth::SignInWithProvider
174174
/// @see User::ReauthenticateWithProvider
175175
/// @see User::LinkWithProvider
176-
static const char* GetProviderId();
176+
static const char* GetProviderId() { return "github.com"; }
177177
#endif // INTERNAL_EXPERIMENTAL
178178
};
179179

@@ -197,7 +197,7 @@ class GoogleAuthProvider {
197197
/// @see Auth::SignInWithProvider
198198
/// @see User::ReauthenticateWithProvider
199199
/// @see User::LinkWithProvider
200-
static const char* GetProviderId();
200+
static const char* GetProviderId() { return "google.com"; }
201201
#endif // INTERNAL_EXPERIMENTAL
202202
};
203203

@@ -219,7 +219,7 @@ class PlayGamesAuthProvider {
219219
/// @see Auth::SignInWithProvider
220220
/// @see User::ReauthenticateWithProvider
221221
/// @see User::LinkWithProvider
222-
static const char* GetProviderId();
222+
static const char* GetProviderId() { return "playgames.google.com"; }
223223
#endif // INTERNAL_EXPERIMENTAL
224224
};
225225

@@ -242,7 +242,7 @@ class TwitterAuthProvider {
242242
/// @see Auth::SignInWithProvider
243243
/// @see User::ReauthenticateWithProvider
244244
/// @see User::LinkWithProvider
245-
static const char* GetProviderId();
245+
static const char* GetProviderId() { return "twitter.com"; }
246246
#endif // INTERNAL_EXPERIMENTAL
247247
};
248248

0 commit comments

Comments
 (0)