Skip to content

Conversation

@AustinBenoit
Copy link
Contributor

Description

Provide details of the change, and generalize the change in the PR title above.


Testing

Describe how you've tested these changes. Link any manually triggered Integration tests or CPP binary SDK Packaging Github Action workflows, if applicable.

Added a new integration test and ran them locally to ensure they pass.


Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

Notes

  • Bug fixes and feature changes require an update to the Release Notes section of release_build_files/readme.md.
  • Read the contribution guidelines CONTRIBUTING.md.
  • Changes to the public API require an internal API review. If you'd like to help us make Firebase APIs better, please propose your change in a feature request so that we can discuss it together.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @AustinBenoit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant new feature to the Firebase App Check C++ SDK: support for limited use tokens. This enhancement allows developers to request App Check tokens specifically designed for short-lived or single-use operations, improving the flexibility and security posture of applications. The changes span across the core App Check provider interface, platform-specific implementations for Android and iOS, and the desktop debug provider, ensuring comprehensive coverage and testability.

Highlights

  • Limited Use Token Support: Introduced support for requesting 'limited use tokens' within the App Check C++ SDK, providing a new mechanism for token acquisition tailored for specific scenarios.
  • API Extension: The AppCheckProvider interface has been extended with a new virtual method, GetLimitedUseToken, allowing custom providers to implement specific logic for these tokens. A default fallback to GetToken is provided if not overridden.
  • Platform Integration: Implemented platform-specific bindings for Android (JNI) and iOS (Objective-C) to expose the GetLimitedUseToken functionality, ensuring consistent behavior across supported platforms.
  • Desktop Debug Provider Update: The DebugAppCheckProvider for desktop now explicitly supports limited use tokens, with the underlying request mechanism updated to include a limited_use flag in the DebugTokenRequest.
  • Integration Testing: A new integration test has been added to verify the correct functionality of the GetLimitedUseToken method using the DebugAppCheckProvider.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for 'Limited Use Tokens' in Firebase App Check across various platforms. The changes include adding a GetLimitedUseToken method to the AppCheckProvider interface with a default implementation that falls back to GetToken if not overridden. The Debug provider for desktop is updated to implement GetLimitedUseToken by calling a new internal GetTokenInternal method with a limited_use flag, which is then propagated to the DebugTokenRequest via a new SetLimitedUse method and a limited_use field in its FlatBuffers schema. For Android, JNI bindings for nativeGetLimitedUseToken are added, though the provided diffs show an issue where the nativeGetToken implementation was modified to call GetLimitedUseToken, and the nativeGetLimitedUseToken implementation appears incomplete. On iOS, a new getLimitedUseTokenWithCompletion: method is added to FIRAppCheckProvider to call the C++ GetLimitedUseToken. An integration test for TestDebugProviderValidLimitedUseToken is also added. Review comments highlight code duplication in the new Android and iOS getLimitedUseToken implementations, suggesting extraction of common logic into helper methods, and point out a typo ('Limted' to 'Limited') in the release notes.

Comment on lines +62 to +73
- (void)getLimitedUseTokenWithCompletion:(nonnull void (^)(FIRAppCheckToken* _Nullable,
NSError* _Nullable))handler {
auto token_callback{[handler](firebase::app_check::AppCheckToken token, int error_code,
const std::string& error_message) {
NSError* ios_error = firebase::app_check::internal::AppCheckErrorToNSError(
static_cast<firebase::app_check::AppCheckError>(error_code), error_message);
FIRAppCheckToken* ios_token =
firebase::app_check::internal::AppCheckTokenToFIRAppCheckToken(token);
handler(ios_token, ios_error);
}};
_cppProvider->GetLimitedUseToken(token_callback);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This new method getLimitedUseTokenWithCompletion: is almost identical to the existing getTokenWithCompletion: method. To avoid code duplication, consider extracting the common logic into a private helper method that takes a boolean flag to decide whether to call GetToken or GetLimitedUseToken.

For example:

- (void)getTokenInternalWithLimitedUse:(BOOL)limitedUse
                            completion:(nonnull void (^)(FIRAppCheckToken* _Nullable,
                                                         NSError* _Nullable))handler {
  auto token_callback{[handler](firebase::app_check::AppCheckToken token, int error_code,
                                const std::string& error_message) {
    NSError* ios_error = firebase::app_check::internal::AppCheckErrorToNSError(
        static_cast<firebase::app_check::AppCheckError>(error_code), error_message);
    FIRAppCheckToken* ios_token =
        firebase::app_check::internal::AppCheckTokenToFIRAppCheckToken(token);
    handler(ios_token, ios_error);
  }};
  if (limitedUse) {
    _cppProvider->GetLimitedUseToken(token_callback);
  } else {
    _cppProvider->GetToken(token_callback);
  }
}

Then both getTokenWithCompletion: and getLimitedUseTokenWithCompletion: can call this helper.

Comment on lines +44 to +51
public Task<AppCheckToken> getLimitedUseToken() {
TaskCompletionSource<AppCheckToken> taskCompletionSource =
new TaskCompletionSource<AppCheckToken>();
// Call the C++ provider to get an AppCheckToken and set the task result.
// The C++ code will call handleGetTokenResult with the resulting token.
nativeGetLimitedUseToken(cProvider, taskCompletionSource);
return taskCompletionSource.getTask();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new getLimitedUseToken() method is very similar to the existing getToken() method. To reduce code duplication, you could extract the common logic into a private helper method. This helper could accept a functional interface that wraps the native method call.

For example (assuming Java 8+):

  private Task<AppCheckToken> getTokenInternal(
      java.util.function.BiConsumer<Long, TaskCompletionSource<AppCheckToken>> nativeMethod) {
    TaskCompletionSource<AppCheckToken> taskCompletionSource = new TaskCompletionSource<>();
    // Call the C++ provider to get an AppCheckToken and set the task result.
    // The C++ code will call handleGetTokenResult with the resulting token.
    nativeMethod.accept(cProvider, taskCompletionSource);
    return taskCompletionSource.getTask();
  }

  @Override
  public Task<AppCheckToken> getToken() {
    return getTokenInternal(this::nativeGetToken);
  }

  public Task<AppCheckToken> getLimitedUseToken() {
    return getTokenInternal(this::nativeGetLimitedUseToken);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant