@@ -37,6 +37,8 @@ using ::firebase::auth::FacebookAuthProvider;
3737using ::firebase::auth::GitHubAuthProvider;
3838using ::firebase::auth::GoogleAuthProvider;
3939using ::firebase::auth::kAuthErrorFailure ;
40+ using ::firebase::auth::kAuthErrorInvalidCredential ;
41+ using ::firebase::auth::kAuthErrorInvalidProviderId ;
4042using ::firebase::auth::kAuthErrorNone ;
4143using ::firebase::auth::OAuthProvider;
4244using ::firebase::auth::PhoneAuthProvider;
@@ -47,6 +49,10 @@ using ::firebase::auth::User;
4749using ::firebase::auth::UserInfoInterface;
4850using ::firebase::auth::UserMetadata;
4951
52+ #if TARGET_OS_IPHONE
53+ using ::firebase::auth::GameCenterAuthProvider;
54+ #endif
55+
5056// Set this to true, and set the email/password, to test a custom email address.
5157static const bool kTestCustomEmail = false ;
5258static const char kCustomEmail [] = " custom.email@example.com" ;
@@ -874,7 +880,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
874880 WaitForSignInFuture (
875881 facebook_bad,
876882 " Auth::SignInWithCredential() bad Facebook credentials" ,
877- ::firebase::auth:: kAuthErrorOperationNotAllowed , auth);
883+ kAuthErrorInvalidProviderId , auth);
878884 }
879885
880886 // Use bad GitHub credentials. Should fail.
@@ -885,7 +891,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
885891 auth->SignInWithCredential (git_hub_cred_bad);
886892 WaitForSignInFuture (
887893 git_hub_bad, " Auth::SignInWithCredential() bad GitHub credentials" ,
888- ::firebase::auth:: kAuthErrorOperationNotAllowed , auth);
894+ kAuthErrorInvalidProviderId , auth);
889895 }
890896
891897 // Use bad Google credentials. Should fail.
@@ -895,7 +901,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
895901 Future<User*> google_bad = auth->SignInWithCredential (google_cred_bad);
896902 WaitForSignInFuture (
897903 google_bad, " Auth::SignInWithCredential() bad Google credentials" ,
898- kAuthErrorFailure , auth);
904+ kAuthErrorInvalidCredential , auth);
899905 }
900906
901907 // Use bad Google credentials, missing an optional parameter. Should fail.
@@ -905,7 +911,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
905911 Future<User*> google_bad = auth->SignInWithCredential (google_cred_bad);
906912 WaitForSignInFuture (
907913 google_bad, " Auth::SignInWithCredential() bad Google credentials" ,
908- kAuthErrorFailure , auth);
914+ kAuthErrorInvalidCredential , auth);
909915 }
910916
911917#if defined(__ANDROID__)
@@ -918,10 +924,51 @@ extern "C" int common_main(int argc, const char* argv[]) {
918924 WaitForSignInFuture (
919925 play_games_bad,
920926 " Auth:SignInWithCredential() bad Play Games credentials" ,
921- kAuthErrorFailure , auth);
927+ kAuthErrorInvalidCredential , auth);
922928 }
923929#endif // defined(__ANDROID__)
924930
931+ #if TARGET_OS_IPHONE
932+ // Test Game Center status/login
933+ {
934+ // Check if the current user is authenticated to GameCenter
935+ bool is_authenticated = GameCenterAuthProvider::IsPlayerAuthenticated ();
936+ if (!is_authenticated) {
937+ LogMessage (" Not signed into Game Center, skipping test." );
938+ } else {
939+ LogMessage (" Signed in, testing Game Center authentication." );
940+
941+ // Get the Game Center credential from the device
942+ Future<Credential> game_center_credential_future =
943+ GameCenterAuthProvider::GetCredential ();
944+ WaitForFuture (
945+ game_center_credential_future,
946+ " GameCenterAuthProvider::GetCredential()" ,
947+ kAuthErrorNone );
948+
949+ const AuthError credential_error =
950+ static_cast <AuthError>(game_center_credential_future.error ());
951+
952+ // Only attempt to sign in if we were able to get a credential.
953+ if (credential_error == kAuthErrorNone ) {
954+ const Credential* gc_credential_ptr =
955+ game_center_credential_future.result ();
956+
957+ if (gc_credential_ptr == nullptr ) {
958+ LogMessage (" Failed to retrieve Game Center credential." );
959+ } else {
960+ Future<User*> game_center_user =
961+ auth->SignInWithCredential (*gc_credential_ptr);
962+ WaitForFuture (game_center_user,
963+ " Auth::SignInWithCredential() test Game Center "
964+ " credential signin" ,
965+ kAuthErrorNone );
966+ }
967+ }
968+ }
969+ }
970+ #endif // TARGET_OS_IPHONE
971+
925972 // Use bad Twitter credentials. Should fail.
926973 {
927974 Credential twitter_cred_bad = TwitterAuthProvider::GetCredential (
@@ -930,7 +977,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
930977 auth->SignInWithCredential (twitter_cred_bad);
931978 WaitForSignInFuture (
932979 twitter_bad, " Auth::SignInWithCredential() bad Twitter credentials" ,
933- ::firebase::auth:: kAuthErrorOperationNotAllowed , auth);
980+ kAuthErrorInvalidProviderId , auth);
934981 }
935982
936983 // Use bad OAuth credentials. Should fail.
@@ -940,7 +987,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
940987 Future<User*> oauth_bad = auth->SignInWithCredential (oauth_cred_bad);
941988 WaitForSignInFuture (
942989 oauth_bad, " Auth::SignInWithCredential() bad OAuth credentials" ,
943- ::firebase::auth:: kAuthErrorFailure , auth);
990+ kAuthErrorInvalidProviderId , auth);
944991 }
945992
946993 // Test Auth::SendPasswordResetEmail().
@@ -1029,7 +1076,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
10291076 anonymous_user->LinkWithCredential (twitter_cred_bad);
10301077 WaitForFuture (link_bad_future,
10311078 " User::LinkWithCredential() with bad credential" ,
1032- ::firebase::auth:: kAuthErrorOperationNotAllowed );
1079+ kAuthErrorInvalidProviderId );
10331080 ExpectTrue (" Linking maintains user" ,
10341081 auth->current_user () == pre_link_user);
10351082 }
@@ -1046,7 +1093,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
10461093 auth->SignInWithCredential (twitter_cred_bad);
10471094 WaitForFuture (signin_bad_future,
10481095 " Auth::SignInWithCredential() with bad credential" ,
1049- ::firebase::auth:: kAuthErrorOperationNotAllowed , auth);
1096+ kAuthErrorInvalidProviderId , auth);
10501097 ExpectTrue (" Failed sign in maintains user" ,
10511098 auth->current_user () == pre_signin_user);
10521099 }
0 commit comments