-
Notifications
You must be signed in to change notification settings - Fork 132
Add support for limited use tokens #1811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,15 @@ public Task<AppCheckToken> getToken() { | |
| return taskCompletionSource.getTask(); | ||
| } | ||
|
|
||
| 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(); | ||
| } | ||
|
Comment on lines
+44
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new 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);
} |
||
|
|
||
| /** | ||
| * Called by C++ with a token in order to complete the java task. | ||
| */ | ||
|
|
@@ -58,4 +67,10 @@ public void handleGetTokenResult(TaskCompletionSource<AppCheckToken> taskComplet | |
| */ | ||
| private native void nativeGetToken( | ||
| long cProvider, TaskCompletionSource<AppCheckToken> task_completion_source); | ||
|
|
||
| /** | ||
| * This function is implemented in the AppCheck C++ library (app_check_android.cc). | ||
| */ | ||
| private native void nativeGetLimitedUseToken( | ||
| long cProvider, TaskCompletionSource<AppCheckToken> task_completion_source); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new method
getLimitedUseTokenWithCompletion:is almost identical to the existinggetTokenWithCompletion:method. To avoid code duplication, consider extracting the common logic into a private helper method that takes a boolean flag to decide whether to callGetTokenorGetLimitedUseToken.For example:
Then both
getTokenWithCompletion:andgetLimitedUseTokenWithCompletion:can call this helper.