Skip to content

Commit a1975e4

Browse files
Googlera-maurice
authored andcommitted
Activating the Generic IDP Federated Auth feature which was locked behind Internal_Experimental preprocessor definitions.
- Reordered User SWIG sections. They were in two different locations (and SWIG has been known to ignore the second section) so now they're cohesive. - Added kProviderId and ProviderId constants to the C++ and C# Auth providers, respectively. - Reordered AuthProviders in credential.h so that they're alphabetical. PiperOrigin-RevId: 286210488
1 parent 62ac010 commit a1975e4

File tree

5 files changed

+96
-93
lines changed

5 files changed

+96
-93
lines changed

auth/src/common.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ namespace {
2727
static const char kCredentialFutureIdentifier[17] = "Auth-Credentials";
2828
}
2929

30+
const char* const EmailAuthProvider::kProviderId = "password";
31+
const char* const FacebookAuthProvider::kProviderId = "facebook.com";
32+
const char* const GameCenterAuthProvider::kProviderId = "gc.apple.com";
33+
const char* const GitHubAuthProvider::kProviderId = "github.com";
34+
const char* const GoogleAuthProvider::kProviderId = "google.com";
35+
const char* const MicrosoftAuthProvider::kProviderId = "microsoft.com";
36+
const char* const PhoneAuthProvider::kProviderId = "phone";
37+
const char* const PlayGamesAuthProvider::kProviderId = "playgames.google.com";
38+
const char* const TwitterAuthProvider::kProviderId = "twitter.com";
39+
const char* const YahooAuthProvider::kProviderId = "yahoo.com";
40+
3041
ReferenceCountedFutureImpl* GetCredentialFutureImpl() {
3142
StaticFutureData* future_data = StaticFutureData::GetFutureDataForModule(
3243
&kCredentialFutureIdentifier, kNumCredentialFunctions);

auth/src/include/firebase/auth.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ struct AuthData;
4343
class AuthStateListener;
4444
class IdTokenListener;
4545
class PhoneAuthProvider;
46-
#ifdef INTERNAL_EXPERIMENTAL
4746
struct AuthCompletionHandle;
4847
class FederatedAuthProvider;
4948
class FederatedOAuthProvider;
5049
class SignInResult;
51-
#endif // INTERNAL_EXPERIMENTAL
5250

5351
/// @brief Firebase authentication object.
5452
///
@@ -238,7 +236,6 @@ class Auth {
238236
/// Get results of the most recent call to @ref SignInWithCredential.
239237
Future<User*> SignInWithCredentialLastResult() const;
240238

241-
#ifdef INTERNAL_EXPERIMENTAL
242239
/// Sign-in a user authenticated via a federated auth provider.
243240
///
244241
/// @param[in] provider Contains information on the provider to authenticate
@@ -251,7 +248,6 @@ class Auth {
251248
/// code: kAuthErrorUnimplemented.
252249
Future<SignInResult> SignInWithProvider(
253250
FederatedAuthProvider* provider);
254-
#endif // INTERNAL_EXPERIMENTAL
255251

256252
/// Asynchronously logs into Firebase with the given credentials.
257253
///
@@ -628,13 +624,13 @@ class IdTokenListener {
628624

629625
#endif // not SWIG
630626

631-
#ifdef INTERNAL_EXPERIMENTAL
632627
/// @brief Used to authenticate with Federated Auth Providers.
633628
///
634629
/// The federated auth provider implementation may facilitate multiple provider
635630
/// types in the future, with support for OAuth to start.
636631
class FederatedAuthProvider {
637632
public:
633+
#ifdef INTERNAL_EXPERIMENTAL
638634
#ifndef SWIG
639635
/// @brief Contains resulting information of a user authenticated by a
640636
/// Federated Auth Provider. This information will be used by the internal
@@ -793,6 +789,7 @@ class FederatedAuthProvider {
793789
const char* error_message);
794790
};
795791
#endif // not SWIG
792+
#endif // INTERNAL_EXPERIMENTAL
796793

797794
FederatedAuthProvider() { }
798795
virtual ~FederatedAuthProvider() {}
@@ -816,6 +813,7 @@ class FederatedAuthProvider {
816813
/// account linking and user reauthentication, respectively.
817814
class FederatedOAuthProvider : public FederatedAuthProvider {
818815
public:
816+
#ifdef INTERNAL_EXPERIMENTAL
819817
#ifndef SWIG
820818
/// @brief A FederatedAuthProvider typed specifically for OAuth Authentication
821819
/// handling.
@@ -825,6 +823,7 @@ class FederatedOAuthProvider : public FederatedAuthProvider {
825823
typedef FederatedAuthProvider::Handler<FederatedOAuthProviderData>
826824
AuthHandler;
827825
#endif // !SWIG
826+
#endif // INTERNAL_EXPERIMENTAL
828827

829828
/// Constructs an unconfigured provider.
830829
FederatedOAuthProvider();
@@ -864,6 +863,7 @@ class FederatedOAuthProvider : public FederatedAuthProvider {
864863
/// user linking.
865864
void SetProviderData(const FederatedOAuthProviderData& provider_data);
866865

866+
#ifdef INTERNAL_EXPERIMENTAL
867867
#ifndef SWIG
868868
/// @brief Configures the use of an AuthHandler for non-mobile systems.
869869
///
@@ -876,6 +876,7 @@ class FederatedOAuthProvider : public FederatedAuthProvider {
876876
/// of this FederatedOAuthProvider.
877877
void SetAuthHandler(AuthHandler* handler);
878878
#endif // !SWIG
879+
#endif // INTERNAL_EXPERIMENTAL
879880

880881
private:
881882
friend class ::firebase::auth::Auth;
@@ -887,7 +888,6 @@ class FederatedOAuthProvider : public FederatedAuthProvider {
887888
FederatedOAuthProviderData provider_data_;
888889
AuthHandler* handler_;
889890
};
890-
#endif // INTERNAL_EXPERIMENTAL
891891

892892

893893
} // namespace auth

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

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ class Credential {
5454
/// @cond FIREBASE_APP_INTERNAL
5555
friend class EmailAuthProvider;
5656
friend class FacebookAuthProvider;
57+
friend class GameCenterAuthProvider;
5758
friend class GitHubAuthProvider;
5859
friend class GoogleAuthProvider;
5960
friend class JniAuthPhoneListener;
61+
friend class MicrosoftAuthProvider;
6062
friend class OAuthProvider;
6163
friend class PhoneAuthProvider;
6264
friend class PlayGamesAuthProvider;
6365
friend class TwitterAuthProvider;
64-
friend class GameCenterAuthProvider;
66+
friend class YahooAuthProvider;
6567
/// @endcond
6668
#endif // !SWIG
6769

@@ -131,6 +133,9 @@ class EmailAuthProvider {
131133
///
132134
/// @returns New Credential.
133135
static Credential GetCredential(const char* email, const char* password);
136+
137+
/// The string used to identify this provider.
138+
static const char* const kProviderId;
134139
};
135140

136141
/// @brief Use an access token provided by Facebook to authenticate.
@@ -143,10 +148,30 @@ class FacebookAuthProvider {
143148
/// @returns New Credential.
144149
static Credential GetCredential(const char* access_token);
145150

146-
#ifdef INTERNAL_EXPERIMENTAL
147-
/// The provider id string used for FederatedAuth.
148-
static constexpr const char* const kProviderId = "facebook.com";
149-
#endif // INTERNAL_EXPERIMENTAL
151+
/// The string used to identify this provider.
152+
static const char* const kProviderId;
153+
};
154+
155+
/// @brief GameCenter (iOS) auth provider
156+
class GameCenterAuthProvider {
157+
public:
158+
/// Generate a credential from GameCenter for the current user.
159+
///
160+
/// @return a Future that will be fulfilled with the resulting credential.
161+
static Future<Credential> GetCredential();
162+
163+
/// Get the result of the most recent GetCredential() call.
164+
///
165+
/// @return an object which can be used to retrieve the Credential.
166+
static Future<Credential> GetCredentialLastResult();
167+
168+
/// Tests to see if the current user is signed in to GameCenter.
169+
///
170+
/// @return true if the user is signed in, false otherwise.
171+
static bool IsPlayerAuthenticated();
172+
173+
/// The string used to identify this provider.
174+
static const char* const kProviderId;
150175
};
151176

152177
/// @brief Use an access token provided by GitHub to authenticate.
@@ -159,10 +184,8 @@ class GitHubAuthProvider {
159184
/// @returns New Credential.
160185
static Credential GetCredential(const char* token);
161186

162-
#ifdef INTERNAL_EXPERIMENTAL
163-
/// The provider id string used for FederatedAuth.
164-
constexpr static const char* const kProviderId = "github.com";
165-
#endif // INTERNAL_EXPERIMENTAL
187+
/// The string used to identify this provider.
188+
static const char* const kProviderId;
166189
};
167190

168191
/// @brief Use an ID token and access token provided by Google to authenticate.
@@ -177,62 +200,17 @@ class GoogleAuthProvider {
177200
static Credential GetCredential(const char* id_token,
178201
const char* access_token);
179202

180-
#ifdef INTERNAL_EXPERIMENTAL
181-
/// The provider id string used for FederatedAuth.
182-
constexpr static const char* const kProviderId = "google.com";
183-
#endif // INTERNAL_EXPERIMENTAL
184-
};
185-
186-
/// @brief Use a server auth code provided by Google Play Games to authenticate.
187-
class PlayGamesAuthProvider {
188-
public:
189-
/// Generate a credential from the given Server Auth Code.
190-
///
191-
/// @param server_auth_code Play Games Sign in Server Auth Code.
192-
///
193-
/// @returns New Credential.
194-
static Credential GetCredential(const char* server_auth_code);
195-
196-
#ifdef INTERNAL_EXPERIMENTAL
197-
/// The provider id string used for FederatedAuth.
198-
constexpr static const char* const kProviderId = "playgames.google.com";
199-
#endif // INTERNAL_EXPERIMENTAL
200-
};
201-
202-
/// @brief Use a token and secret provided by Twitter to authenticate.
203-
class TwitterAuthProvider {
204-
public:
205-
/// Generate a credential from the given Twitter token and password.
206-
///
207-
/// @param token The Twitter OAuth token.
208-
/// @param secret The Twitter OAuth secret.
209-
///
210-
/// @returns New Credential.
211-
static Credential GetCredential(const char* token, const char* secret);
212-
213-
#ifdef INTERNAL_EXPERIMENTAL
214-
/// The provider id string used for FederatedAuth.
215-
constexpr static const char* const kProviderId = "twitter.com";
216-
#endif // INTERNAL_EXPERIMENTAL
203+
/// The string used to identify this provider.
204+
static const char* const kProviderId;
217205
};
218206

219207

220-
#ifdef INTERNAL_EXPERIMENTAL
221-
/// @brief Use an access token provided by Yahoo to authenticate.
222-
class YahooAuthProvider {
223-
public:
224-
/// The provider id string used for FederatedAuth.
225-
constexpr static const char* const kProviderId = "yahoo.com";
226-
};
227-
228208
/// @brief Use an access token provided by Microsoft to authenticate.
229209
class MicrosoftAuthProvider {
230210
public:
231-
/// The provider id string used for FederatedAuth.
232-
constexpr static const char* const kProviderId = "microsoft.com";
211+
/// The string used to identify this provider.
212+
static const char* const kProviderId;
233213
};
234-
#endif // INTERNAL_EXPERIMENTAL
235-
236214

237215
/// @brief OAuth2.0+UserInfo auth provider (OIDC compliant and non-compliant).
238216
class OAuthProvider {
@@ -248,25 +226,6 @@ class OAuthProvider {
248226
const char* access_token);
249227
};
250228

251-
/// @brief GameCenter (iOS) auth provider
252-
class GameCenterAuthProvider {
253-
public:
254-
/// Generate a credential from GameCenter for the current user.
255-
///
256-
/// @return a Future that will be fulfilled with the resulting credential.
257-
static Future<Credential> GetCredential();
258-
259-
/// Get the result of the most recent GetCredential() call.
260-
///
261-
/// @return an object which can be used to retrieve the Credential.
262-
static Future<Credential> GetCredentialLastResult();
263-
264-
/// Tests to see if the current user is signed in to GameCenter.
265-
///
266-
/// @return true if the user is signed in, false otherwise.
267-
static bool IsPlayerAuthenticated();
268-
};
269-
270229
/// @brief Use phone number text messages to authenticate.
271230
///
272231
/// Allows developers to use the phone number and SMS verification codes
@@ -595,6 +554,9 @@ class PhoneAuthProvider {
595554
/// PhoneAuthProvider.
596555
static PhoneAuthProvider& GetInstance(Auth* auth);
597556

557+
/// The string used to identify this provider.
558+
static const char* const kProviderId;
559+
598560
private:
599561
friend struct AuthData;
600562
friend class JniAuthPhoneListener;
@@ -608,6 +570,44 @@ class PhoneAuthProvider {
608570
PhoneAuthProviderData* data_;
609571
};
610572

573+
/// @brief Use a server auth code provided by Google Play Games to authenticate.
574+
class PlayGamesAuthProvider {
575+
public:
576+
/// Generate a credential from the given Server Auth Code.
577+
///
578+
/// @param server_auth_code Play Games Sign in Server Auth Code.
579+
///
580+
/// @return New Credential.
581+
static Credential GetCredential(const char* server_auth_code);
582+
583+
/// The string used to identify this provider.
584+
static const char* const kProviderId;
585+
};
586+
587+
/// @brief Use a token and secret provided by Twitter to authenticate.
588+
class TwitterAuthProvider {
589+
public:
590+
/// Generate a credential from the given Twitter token and password.
591+
///
592+
/// @param token The Twitter OAuth token.
593+
/// @param secret The Twitter OAuth secret.
594+
///
595+
/// @return New Credential.
596+
static Credential GetCredential(const char* token, const char* secret);
597+
598+
/// The string used to identify this provider.
599+
static const char* const kProviderId;
600+
};
601+
602+
603+
/// @brief Use an access token provided by Yahoo to authenticate.
604+
class YahooAuthProvider {
605+
public:
606+
/// The string used to identify this provider.
607+
static const char* const kProviderId;
608+
};
609+
610+
611611
} // namespace auth
612612
} // namespace firebase
613613

auth/src/include/firebase/auth/types.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
#ifndef FIREBASE_AUTH_CLIENT_CPP_SRC_INCLUDE_FIREBASE_AUTH_TYPES_H_
1818
#define FIREBASE_AUTH_CLIENT_CPP_SRC_INCLUDE_FIREBASE_AUTH_TYPES_H_
1919

20-
#ifdef INTERNAL_EXPERIMENTAL
2120
#include <map>
2221
#include <string>
2322
#include <vector>
24-
#endif // INTERNAL_EXPERIMENTAL
2523

2624
namespace firebase {
2725
namespace auth {
@@ -424,7 +422,6 @@ enum AuthError {
424422
#endif // INTERNAL_EXEPERIMENTAL
425423
};
426424

427-
#ifdef INTERNAL_EXPERIMENTAL
428425
/// @brief Contains information required to authenticate with a third party
429426
/// provider.
430427
struct FederatedProviderData {
@@ -443,6 +440,7 @@ struct FederatedOAuthProviderData : FederatedProviderData {
443440
this->provider_id = provider;
444441
}
445442

443+
#ifndef SWIG
446444
/// @brief Initializes the provider data structure with the specified provider
447445
/// id, scopes and custom parameters.
448446
FederatedOAuthProviderData(
@@ -452,14 +450,14 @@ struct FederatedOAuthProviderData : FederatedProviderData {
452450
this->scopes = scopes;
453451
this->custom_parameters = custom_parameters;
454452
}
453+
#endif
455454

456455
/// OAuth parmeters which specify which rights of access are being requested.
457456
std::vector<std::string> scopes;
458457

459458
/// OAuth parameters which are provided to the federated provider service.
460459
std::map<std::string, std::string> custom_parameters;
461460
};
462-
#endif // INTERNAL_EXPERIMENTAL
463461

464462
} // namespace auth
465463
} // namespace firebase

0 commit comments

Comments
 (0)