-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[FAL] Add limited-use token support #15099
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
0eeb7a2
Add config support
daymxn 6c878ff
fmt
daymxn e6de038
Migrate to nested config
daymxn 086e673
Mix invalid references
daymxn 4c9d28b
Fix invalid reference (again)
daymxn 8a06ee5
fmt
daymxn 8659455
Remove unnecessary Encodable
daymxn 56d1f5f
Update AppCheckOptions.swift
daymxn 1b6c09c
Update FirebaseAI.swift
daymxn 1dfbce5
Update FirebaseAI/Sources/AppCheckOptions.swift
daymxn 6dddd09
Update FirebaseAI/Sources/AppCheckOptions.swift
daymxn a188a79
Update FirebaseAI/Sources/AppCheckOptions.swift
daymxn fa2bc36
Add changelog entry
daymxn 8ab664c
Update tests using `createInstance`
daymxn 860ee49
Use default params when initializing config
daymxn 187de4f
formatting
daymxn 10f445c
manual formatting
daymxn 8ce15d2
Fix broken link in unit tests
daymxn ce0da47
Add missing default arg on GenerativeModel for config
daymxn 9a9a1c5
Update FirebaseAI/CHANGELOG.md
daymxn 446f62d
Add error message
daymxn 61c5ad6
formatting
daymxn 4f84809
Merge branch 'daymxn-fal-limitedusetokens-support' of github.com:fire…
daymxn 9c551c7
Update domain to be more adaptive
daymxn cc578bd
Update AppCheckOptions.swift
daymxn 604ec4c
Update AppCheckOptions.swift
daymxn 9ef2511
Update AppCheckOptions.swift
daymxn 0857ffa
Update AppCheckOptions.swift
daymxn d3e31eb
Update AppCheckOptions.swift
daymxn df24a84
Update FirebaseAI/Sources/AppCheckOptions.swift
daymxn 3e6c17d
Migrate to parameter instead of config struct
daymxn 0a0976b
Update CHANGELOG.md
daymxn cb0d3c8
formatting
daymxn 17113f3
Remove trailing whitespace
daymxn 4e10e12
Merge branch 'main' into daymxn-fal-limitedusetokens-support
daymxn 4774502
Fix left overs from config struct
daymxn e80fade
Make app check token result sendable
daymxn cd7312a
formatting
daymxn b5940dc
Fix missing param
daymxn 4a8ea12
Add limited use tests
daymxn 1dc7d7f
Update FirebaseAI.swift
daymxn 19b4522
Update CHANGELOG.md
daymxn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2025 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/// Configurable options for how App Check is used within a ``FirebaseAI`` instance. | ||
/// | ||
/// Can be set when creating a ``FirebaseAI.Config``. | ||
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) | ||
public struct AppCheckOptions: Sendable, Hashable { | ||
/// Use `limitedUseTokens`, instead of the standard cached tokens, when sending requests | ||
/// to the backend. | ||
let requireLimitedUseTokens: Bool | ||
|
||
/// Creates a new ``AppCheckOptions`` value. | ||
/// | ||
/// - Parameters: | ||
/// - requireLimitedUseTokens: When sending tokens to the backend, this option enables | ||
/// the usage of App Check's `limitedUseTokens` instead of the standard cached tokens. | ||
daymxn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// A new `limitedUseToken` will be generated for each request; providing a lower attack | ||
daymxn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// surface for malicious parties to hijack tokens. When used alongside [replay protection](https://firebase.google.com/docs/app-check/custom-resource-backend#replay-protection), | ||
daymxn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// `limitedUseTokens` are also _consumed_ after each request, ensuring they can't be used | ||
daymxn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// again. | ||
/// | ||
/// _To prevent breakage, this flag is set to `false` by default._ | ||
daymxn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// > Important: Replay protection is not currently supported for the FirebaseAI backend. | ||
/// > While this feature is being developed, you can still migrate to using | ||
/// > `limitedUseTokens`. Because `limitedUseTokens` are backwards compatable, you can still | ||
daymxn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// > use them without replay protection. Due to their shorter TTL over standard App Check | ||
/// > tokens, they still provide a security benefit. | ||
/// > | ||
/// > Migrating to `limitedUseTokens` ahead of time will also allow you to enable replay | ||
/// > protection down the road (when support is added), without breaking your users. | ||
public init(requireLimitedUseTokens: Bool = false) { | ||
self.requireLimitedUseTokens = requireLimitedUseTokens | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.