-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add FIRAppCheckTokenProtocol
for use in FIRAppCheckProtocol
#13035
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 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
38a69b0
Add `FIRAppCheckTokenProtocol` for use in `FIRAppCheckProtocol`
andrewheard 0550c15
Fix `tokenForcingRefresh` token nullability
andrewheard b112f75
Add tests to verify all types accessible with only interop module
andrewheard 9c31883
Add availability checks for async-await in tests
andrewheard d334648
Add ObjC API tests
andrewheard c740c02
Update min dependency version to 10.28+ in FirebaseAppCheck.podspec
andrewheard 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
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
28 changes: 28 additions & 0 deletions
28
FirebaseAppCheck/Interop/Public/FirebaseAppCheckInterop/FIRAppCheckTokenProtocol.h
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,28 @@ | ||
/* | ||
* Copyright 2024 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. | ||
*/ | ||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
NS_SWIFT_NAME(AppCheckTokenProtocol) | ||
@protocol FIRAppCheckTokenProtocol <NSObject> | ||
|
||
/// A Firebase App Check token. | ||
@property(nonatomic, readonly) NSString *token; | ||
|
||
/// The App Check token's expiration date in the device's local time. | ||
@property(nonatomic, readonly) NSDate *expirationDate; | ||
|
||
@end | ||
NS_ASSUME_NONNULL_END |
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
53 changes: 53 additions & 0 deletions
53
FirebaseAppCheck/Tests/Interop/ObjC/FIRAppCheckInteropAPITests.m
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,53 @@ | ||
// Copyright 2024 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. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <FirebaseAppCheckInterop/FirebaseAppCheckInterop.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface FIRAppCheckInteropAPITests : NSObject | ||
@end | ||
|
||
@implementation FIRAppCheckInteropAPITests | ||
|
||
- (void)usage { | ||
id<FIRAppCheckInterop> appCheckInterop; | ||
|
||
[appCheckInterop getTokenForcingRefresh:NO | ||
completion:^(id<FIRAppCheckTokenResultInterop> tokenResult) { | ||
NSString *__unused token = tokenResult.token; | ||
NSError *__unused _Nullable error = tokenResult.error; | ||
}]; | ||
|
||
NSString *__unused tokenDidChangeNotificationName = | ||
[appCheckInterop tokenDidChangeNotificationName]; | ||
|
||
NSString *__unused notificationTokenKey = [appCheckInterop notificationTokenKey]; | ||
|
||
NSString *__unused notificationAppNameKey = [appCheckInterop notificationAppNameKey]; | ||
|
||
if ([appCheckInterop respondsToSelector:@selector(getLimitedUseTokenWithCompletion:)]) { | ||
[appCheckInterop | ||
getLimitedUseTokenWithCompletion:^(id<FIRAppCheckTokenResultInterop> tokenResult) { | ||
NSString *__unused token = tokenResult.token; | ||
NSError *__unused _Nullable error = tokenResult.error; | ||
}]; | ||
} | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
51 changes: 51 additions & 0 deletions
51
FirebaseAppCheck/Tests/Interop/ObjC/FIRAppCheckProtocolAPITests.m
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,51 @@ | ||
// Copyright 2024 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. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <FirebaseAppCheckInterop/FirebaseAppCheckInterop.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface FIRAppCheckProtocolAPITests : NSObject | ||
@end | ||
|
||
@implementation FIRAppCheckProtocolAPITests | ||
|
||
- (void)usage { | ||
id<FIRAppCheckProtocol> appCheck; | ||
|
||
[appCheck tokenForcingRefresh:NO | ||
completion:^(id<FIRAppCheckTokenProtocol> _Nullable token, | ||
NSError *_Nullable error) { | ||
if (token) { | ||
NSString *__unused tokenValue = token.token; | ||
NSDate *__unused expirationDate = token.expirationDate; | ||
} | ||
}]; | ||
|
||
if ([appCheck respondsToSelector:@selector(limitedUseTokenWithCompletion:)]) { | ||
[appCheck limitedUseTokenWithCompletion:^(id<FIRAppCheckTokenProtocol> _Nullable token, | ||
NSError *_Nullable error) { | ||
if (token) { | ||
NSString *__unused tokenValue = token.token; | ||
NSDate *__unused expirationDate = token.expirationDate; | ||
} | ||
}]; | ||
} | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
64 changes: 64 additions & 0 deletions
64
FirebaseAppCheck/Tests/Interop/Swift/AppCheckInteropAPITests.swift
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,64 @@ | ||
// Copyright 2024 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. | ||
|
||
// MARK: This file is used to evaluate the AppCheckInterop API in Swift. | ||
|
||
import Foundation | ||
|
||
// MARK: Do not import `FirebaseAppCheck`, this file is for `FirebaseAppCheckInterop` only. | ||
|
||
import FirebaseAppCheckInterop | ||
|
||
final class AppCheckInteropAPITests { | ||
let appCheckInterop: AppCheckInterop! = nil | ||
|
||
func usage() { | ||
let _: Void = appCheckInterop.getToken(forcingRefresh: false) { result in | ||
let _: FIRAppCheckTokenResultInterop = result | ||
let _: String = result.token | ||
if let error = result.error { | ||
let _: String = error.localizedDescription | ||
} | ||
} | ||
|
||
let _: String = appCheckInterop.tokenDidChangeNotificationName() | ||
|
||
let _: String = appCheckInterop.notificationTokenKey() | ||
|
||
let _: String = appCheckInterop.notificationAppNameKey() | ||
|
||
guard let getLimitedUseToken: (@escaping AppCheckTokenHandlerInterop) -> Void = | ||
appCheckInterop.getLimitedUseToken else { return } | ||
let _: Void = getLimitedUseToken { result in | ||
let _: FIRAppCheckTokenResultInterop = result | ||
let _: String = result.token | ||
if let error = result.error { | ||
let _: String = error.localizedDescription | ||
} | ||
} | ||
} | ||
|
||
@available(iOS 13, macOS 10.15, macCatalyst 13, tvOS 13, *) | ||
func usage_async() async { | ||
let result: FIRAppCheckTokenResultInterop = | ||
await appCheckInterop.getToken(forcingRefresh: false) | ||
let _: String = result.token | ||
if let error = result.error { | ||
let _: String = error.localizedDescription | ||
} | ||
|
||
// The following fails to compile with "Command SwiftCompile failed with a nonzero exit code". | ||
// let _ = await appCheckInterop.getLimitedUseToken?() | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
FirebaseAppCheck/Tests/Interop/Swift/AppCheckProtocolAPITests.swift
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,58 @@ | ||
// Copyright 2024 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. | ||
|
||
// MARK: This file is used to evaluate the AppCheckProtocol API in Swift. | ||
|
||
import Foundation | ||
|
||
// MARK: Do not import `FirebaseAppCheck`, this file is for `FirebaseAppCheckInterop` only. | ||
|
||
import FirebaseAppCheckInterop | ||
|
||
final class AppCheckProtocolAPITests { | ||
let appCheck: AppCheckProtocol! = nil | ||
|
||
func usage() { | ||
let _: Void = appCheck.token(forcingRefresh: false, completion: { token, error in | ||
if let token: AppCheckTokenProtocol { | ||
let _: String = token.token | ||
let _: Date = token.expirationDate | ||
} | ||
if let error: Error { | ||
let _: String = error.localizedDescription | ||
} | ||
}) | ||
|
||
let _: Void = appCheck.limitedUseToken { token, error in | ||
if let token: AppCheckTokenProtocol { | ||
let _: String = token.token | ||
let _: Date = token.expirationDate | ||
} | ||
if let error: Error { | ||
let _: String = error.localizedDescription | ||
} | ||
} | ||
} | ||
|
||
@available(iOS 13, macOS 10.15, macCatalyst 13, tvOS 13, *) | ||
func usage_async() async { | ||
do { | ||
let token: AppCheckTokenProtocol = try await appCheck.token(forcingRefresh: false) | ||
let _: String = token.token | ||
let _: Date = token.expirationDate | ||
} catch { | ||
let _: String = error.localizedDescription | ||
} | ||
} | ||
} |
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.