Feat: add in limited use tokens#1385
Conversation
Summary of ChangesHello @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 comprehensive support for limited-use tokens within the Firebase App Check system. It expands the public API for developers to request these specialized tokens, updates the core provider interface to accommodate this new token type, and establishes the necessary communication infrastructure between the C# and C++ components. The changes also include user interface elements and automated tests to ensure the proper functioning and integration of this new feature. Highlights
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for limited-use App Check tokens, which is a valuable feature. The overall implementation is logical, but there are several areas with significant code duplication across both the C# and C++ (SWIG) files. I've provided detailed comments and code suggestions to refactor these sections by extracting common logic into helper methods. Addressing these points will improve the code's maintainability and reduce the chance of future bugs.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for limited-use tokens in App Check, a valuable feature for non-Firebase backends. The changes are comprehensive, touching the public API, C# implementation, C++ interop layer, and tests.
My review focuses on improving maintainability. I've identified several instances of significant code duplication where new methods for limited-use tokens are nearly identical to their existing counterparts. Refactoring this duplicated logic into shared helper methods would make the code cleaner and easier to maintain. I've also suggested modernizing an asynchronous call to use async/await, which improves readability and error handling. Lastly, there's a minor comment inconsistency in one of the new tests.
Overall, the implementation is solid, and addressing these points will enhance the long-term quality of the codebase.
| public System.Threading.Tasks.Task<AppCheckToken> | ||
| GetLimitedUseAppCheckTokenAsync() { | ||
| ThrowIfNull(); | ||
| return appCheckInternal.GetLimitedUseAppCheckTokenAsync().ContinueWith(task => { | ||
| if (task.IsFaulted) { | ||
| throw task.Exception; | ||
| } | ||
| AppCheckTokenInternal tokenInternal = task.Result; | ||
| return AppCheckToken.FromAppCheckTokenInternal(tokenInternal); | ||
| }); |
There was a problem hiding this comment.
Using async/await simplifies asynchronous code, improves readability, and provides better exception handling compared to using ContinueWith. The await keyword automatically unwraps an AggregateException if it contains a single inner exception, making error handling more straightforward.
public async System.Threading.Tasks.Task<AppCheckToken>
GetLimitedUseAppCheckTokenAsync() {
ThrowIfNull();
AppCheckTokenInternal tokenInternal = await appCheckInternal.GetLimitedUseAppCheckTokenAsync();
return AppCheckToken.FromAppCheckTokenInternal(tokenInternal);
}There was a problem hiding this comment.
Umm yeah I'll come back to this and clean both limiteduse and get token together.
| void GetLimitedUseToken(std::function<void(AppCheckToken, int, const std::string&)> | ||
| completion_callback) override { | ||
| if (g_get_limited_use_token_from_csharp) { | ||
| // Save the callback in the map, and generate a key | ||
| int key; | ||
| { | ||
| MutexLock lock(g_pending_get_tokens_mutex); | ||
| key = g_pending_token_keys++; | ||
| g_pending_get_tokens[key] = completion_callback; | ||
| } | ||
| // Queue a call to the C# function that will generate the token. | ||
| firebase::callback::AddCallback( | ||
| new firebase::callback::CallbackValue1String1<int>( | ||
| key, app_->name(), CallGetLimitedUseTokenFromCSharp)); | ||
| } else { | ||
| completion_callback({}, kAppCheckErrorInvalidConfiguration, | ||
| "Missing AppCheckProvider C# configuration"); | ||
| } | ||
| } |
There was a problem hiding this comment.
The implementation of GetLimitedUseToken is almost identical to GetToken. To reduce code duplication, consider refactoring the common logic into a helper function. This helper could take the C# callback function pointer (e.g., g_get_token_from_csharp or g_get_limited_use_token_from_csharp) and the corresponding C++ wrapper function (e.g., CallGetTokenFromCSharp or CallGetLimitedUseTokenFromCSharp) as arguments.
48096d8 to
862ea8d
Compare
I can't get default interface to work so I'll just make it its own interface
7cac6ca to
ac7e120
Compare
Description
Feat: add in limited use tokens
This changes the current interface implementation
IAppCheckProviderto have both aTesting
I have the new limited use token locally
Android:
iOS:

Desktop:

Along with running the integration tests
[replace this line]: # (Describe your testing in detail.)
Type of Change
Place an
xthe applicable box: