Skip to content
Prev Previous commit
Next Next commit
Updated syntax and more based on api proposal feedback
  • Loading branch information
AlmostMatt committed Aug 31, 2022
commit e16cd03235467488b8c3f6db15d1a99eaeabf65c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AppCheckProvider {
* Returns a {@link Future} which resolves to a valid {@link AppCheckToken} or an {@link Exception}
* in the case that an unexpected failure occurred while getting the token.
*/
virtual Future<AppCheckToken> getToken() = 0;
virtual Future<AppCheckToken> GetToken() = 0;
}

} // namespace app_check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class AppCheckProviderFactory {
* Gets the {@link AppCheckProvider} associated with the given {@link FirebaseApp} instance, or
* creates one if none already exists.
*/
// @NonNull
virtual AppCheckProvider createProvider(const App& app) = 0;
virtual AppCheckProvider* CreateProvider(const App& app) = 0;
}

} // namespace app_check
Expand Down
36 changes: 0 additions & 36 deletions app_check/src/include/firebase/app_check/app_check_token.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ namespace app_check {
/**
* Implementation of an {@link AppCheckProviderFactory} that builds {@link DebugAppCheckProvider}s.
*/
class DebugAppCheckProviderFactory implements AppCheckProviderFactory {
class DebugAppCheckProviderFactory : public AppCheckProviderFactory {

public:
/**
* Gets an instance of this class for installation into a {@link
* com.google.firebase.appcheck.FirebaseAppCheck} instance. If no debug secret is found in {@link
* com.google.firebase.appcheck.AppCheck} instance. If no debug secret is found in {@link
* android.content.SharedPreferences}, a new debug secret will be generated and printed to the
* logcat. The debug secret should then be added to the allow list in the Firebase Console.
*/
static DebugAppCheckProviderFactory getInstance();
static DebugAppCheckProviderFactory GetInstance();

AppCheckProvider createProvider(const App& app) override;
AppCheckProvider* CreateProvider(const App& app) override;
}

} // namespace app_check
Expand Down
71 changes: 41 additions & 30 deletions app_check/src/include/firebase/app_check/firebase_app_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,77 +15,88 @@
namespace firebase {
namespace app_check {

class FirebaseAppCheck { // ALMOSTMATT: implements InternalAppCheckTokenProvider
/// Struct to hold tokens emitted by the Firebase App Check service which are minted upon a successful
/// application verification. These tokens are the federated output of a verification flow, the
/// structure of which is independent of the mechanism by which the application was verified.
struct AppCheckToken {

public:
/** Gets the default instance of {@code FirebaseAppCheck}. */
static FirebaseAppCheck getInstance();
/// A Firebase App Check token.
std::string token;

/// A Firebase App Check token expiration date in the device local time.
long expire_time_millis;
}

class AppCheckListener {
virtual ~AppCheckListener();
/**
* This method gets invoked on the UI thread on changes to the token state. Does not trigger on
* token expiry.
*/
virtual void OnAppCheckTokenChanged(const AppCheckToken& token) = 0;
}

class AppCheck {

public:
/**
* Gets the instance of {@code FirebaseAppCheck} associated with the given {@link FirebaseApp}
* Gets the instance of {@code AppCheck} associated with the given {@link FirebaseApp}
* instance.
*/
static FirebaseAppCheck getInstance(const App& app);
static AppCheck* GetInstance(::firebase::App* app);

/**
* Installs the given {@link AppCheckProviderFactory}, overwriting any that were previously
* associated with this {@code FirebaseAppCheck} instance. Any {@link AppCheckTokenListener}s
* attached to this {@code FirebaseAppCheck} instance will be transferred from existing factories
* associated with this {@code AppCheck} instance. Any {@link AppCheckTokenListener}s
* attached to this {@code AppCheck} instance will be transferred from existing factories
* to the newly installed one.
*
* <p>Automatic token refreshing will only occur if the global {@code
* isDataCollectionDefaultEnabled} flag is set to true. To allow automatic token refreshing for
* Firebase App Check without changing the {@code isDataCollectionDefaultEnabled} flag for other
* Firebase SDKs, use {@link #setAppCheckProviderFactory(AppCheckProviderFactory, boolean)}
* instead or call {@link #setTokenAutoRefreshEnabled(boolean)} after installing the {@code
* Firebase SDKs, use {@link #setAppCheckProviderFactory(AppCheckProviderFactory, bool)}
* instead or call {@link #setTokenAutoRefreshEnabled(bool)} after installing the {@code
* factory}.
*
* This method should be called before initializing the Firebase App.
*/
virtual void setAppCheckProviderFactory(const AppCheckProviderFactory& factory) = 0;
static void SetAppCheckProviderFactory(const AppCheckProviderFactory& factory) = 0;

/**
* Installs the given {@link AppCheckProviderFactory}, overwriting any that were previously
* associated with this {@code FirebaseAppCheck} instance. Any {@link AppCheckTokenListener}s
* attached to this {@code FirebaseAppCheck} instance will be transferred from existing factories
* associated with this {@code AppCheck} instance. Any {@link AppCheckTokenListener}s
* attached to this {@code AppCheck} instance will be transferred from existing factories
* to the newly installed one.
*
* <p>Automatic token refreshing will only occur if the {@code isTokenAutoRefreshEnabled} field is
* set to true. To use the global {@code isDataCollectionDefaultEnabled} flag for determining
* automatic token refreshing, call {@link
* #setAppCheckProviderFactory(AppCheckProviderFactory)} instead.
*
* This method should be called before initializing the Firebase App.
*/
// ALMOSTMATT: does iOS have this variation?
virtual void setAppCheckProviderFactory(
const AppCheckProviderFactory& factory, boolean isTokenAutoRefreshEnabled) = 0;
static void SetAppCheckProviderFactory(
AppCheckProviderFactory* factory, bool is_token_auto_refresh_enabled) = 0;

/** Sets the {@code isTokenAutoRefreshEnabled} flag. */
virtual void setTokenAutoRefreshEnabled(boolean isTokenAutoRefreshEnabled) = 0;
static void SetTokenAutoRefreshEnabled(bool is_token_auto_refresh_enabled) = 0;

/**
* Requests a Firebase App Check token. This method should be used ONLY if you need to authorize
* requests to a non-Firebase backend. Requests to Firebase backends are authorized automatically
* if configured.
*/
virtual Future<AppCheckToken> getAppCheckToken(boolean forceRefresh) = 0;
Future<AppCheckToken> GetAppCheckToken(bool force_refresh) = 0;

/**
* Registers an {@link AppCheckListener} to changes in the token state. This method should be used
* ONLY if you need to authorize requests to a non-Firebase backend. Requests to Firebase backends
* are authorized automatically if configured.
*/
virtual void addAppCheckListener(AppCheckListener* listener) = 0;
void AddAppCheckListener(AppCheckListener* listener) = 0;

/** Unregisters an {@link AppCheckListener} to changes in the token state. */
virtual void removeAppCheckListener(AppCheckListener* listener) = 0;

// ALMOSTMATT: should this be a separate file? or a non-nested class? it is an interface so is virtual
class AppCheckListener {
virtual ~AppCheckListener();
/**
* This method gets invoked on the UI thread on changes to the token state. Does not trigger on
* token expiry.
*/
virtual void onAppCheckTokenChanged(const AppCheckToken& token) = 0;
}
void RemoveAppCheckListener(AppCheckListener* listener) = 0;
}

} // namespace app_check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,14 @@
* Implementation of an {@link AppCheckProviderFactory} that builds {@link
* PlayIntegrityAppCheckProvider}s. This is the default implementation.
*/
public class PlayIntegrityAppCheckProviderFactory implements AppCheckProviderFactory {
class PlayIntegrityAppCheckProviderFactory : public AppCheckProviderFactory {

private static final PlayIntegrityAppCheckProviderFactory instance =
new PlayIntegrityAppCheckProviderFactory();
public:
/**
* Gets an instance of this class for installation into a {@link
* com.google.firebase.appcheck.AppCheck} instance.
*/
static PlayIntegrityAppCheckProviderFactory GetInstance();

/**
* Gets an instance of this class for installation into a {@link
* com.google.firebase.appcheck.FirebaseAppCheck} instance.
*/
@NonNull
public static PlayIntegrityAppCheckProviderFactory getInstance() {
return instance;
}

@NonNull
@Override
public AppCheckProvider create(@NonNull FirebaseApp firebaseApp) {
return new PlayIntegrityAppCheckProvider(firebaseApp);
}
AppCheckProvider* CreateProvider(const App& app) override;
}
27 changes: 8 additions & 19 deletions app_check/src/safetynet/safety_net_app_check_provider_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,14 @@
* Implementation of an {@link AppCheckProviderFactory} that builds {@link
* SafetyNetAppCheckProvider}s. This is the default implementation.
*/
public class SafetyNetAppCheckProviderFactory implements AppCheckProviderFactory {
class SafetyNetAppCheckProviderFactory : public AppCheckProviderFactory {

private static final SafetyNetAppCheckProviderFactory instance =
new SafetyNetAppCheckProviderFactory();
public:
/**
* Gets an instance of this class for installation into a {@link
* com.google.firebase.appcheck.AppCheck} instance.
*/
static SafetyNetAppCheckProviderFactory GetInstance();

private SafetyNetAppCheckProviderFactory() {}

/**
* Gets an instance of this class for installation into a {@link
* com.google.firebase.appcheck.FirebaseAppCheck} instance.
*/
@NonNull
public static SafetyNetAppCheckProviderFactory getInstance() {
return instance;
}

@NonNull
@Override
public AppCheckProvider create(@NonNull FirebaseApp firebaseApp) {
return new SafetyNetAppCheckProvider(firebaseApp);
}
AppCheckProvider* CreateProvider(const App& app) override;
}