Skip to content
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

Make tokenDelegate nullable in GACAppCheck #11592

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions AppCheckCore/Sources/Core/GACAppCheck.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ @interface GACAppCheck ()
@property(nonatomic, readonly) id<GACAppCheckProvider> appCheckProvider;
@property(nonatomic, readonly) id<GACAppCheckStorageProtocol> storage;
@property(nonatomic, readonly) id<GACAppCheckSettingsProtocol> settings;
@property(nonatomic, readonly, weak) id<GACAppCheckTokenDelegate> tokenDelegate;
@property(nonatomic, readonly, nullable, weak) id<GACAppCheckTokenDelegate> tokenDelegate;

@property(nonatomic, readonly, nullable) id<GACAppCheckTokenRefresherProtocol> tokenRefresher;

Expand All @@ -65,7 +65,7 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName
storage:(id<GACAppCheckStorageProtocol>)storage
tokenRefresher:(id<GACAppCheckTokenRefresherProtocol>)tokenRefresher
settings:(id<GACAppCheckSettingsProtocol>)settings
tokenDelegate:(id<GACAppCheckTokenDelegate>)tokenDelegate {
tokenDelegate:(nullable id<GACAppCheckTokenDelegate>)tokenDelegate {
self = [super init];
if (self) {
_instanceName = instanceName;
Expand All @@ -89,8 +89,8 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName
- (instancetype)initWithInstanceName:(NSString *)instanceName
appCheckProvider:(id<GACAppCheckProvider>)appCheckProvider
settings:(id<GACAppCheckSettingsProtocol>)settings
tokenDelegate:(id<GACAppCheckTokenDelegate>)tokenDelegate
resourceName:(NSString *)resourceName
tokenDelegate:(nullable id<GACAppCheckTokenDelegate>)tokenDelegate
keychainAccessGroup:(nullable NSString *)accessGroup {
GACAppCheckTokenRefreshResult *refreshResult =
[[GACAppCheckTokenRefreshResult alloc] initWithStatusNever];
Expand Down Expand Up @@ -204,7 +204,9 @@ - (void)getLimitedUseTokenWithCompletion:(GACAppCheckTokenHandlerInterop)handler
initWithStatusSuccessAndExpirationDate:token.expirationDate
receivedAtDate:token.receivedAtDate];
[self.tokenRefresher updateWithRefreshResult:refreshResult];
[self.tokenDelegate tokenDidUpdate:token instanceName:self.instanceName];
if (self.tokenDelegate) {
[self.tokenDelegate tokenDidUpdate:token instanceName:self.instanceName];
}
return token;
});
}
Expand Down
12 changes: 9 additions & 3 deletions AppCheckCore/Sources/Public/AppCheckCore/GACAppCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ NS_SWIFT_NAME(AppCheckCore)
- (instancetype)init NS_UNAVAILABLE;

/// Returns an instance of `AppCheck` for an application.
/// @param appCheckProvider An `AppCheckCoreProvider` instance that provides App Check tokens.
/// @return An instance of `AppCheckCore` corresponding to the provided `app`.
/// @param appCheckProvider An object that provides App Check tokens.
/// @param settings An object that provides App Check settings.
/// @param resourceName The name of the resource protected by App Check; for a Firebase App this is
/// "projects/{project_id}/apps/{app_id}".
/// @param tokenDelegate A delegate that receives token update notifications.
/// @param accessGroup The identifier for a keychain group that the app shares items with; if
/// provided, requires the Keychain Access Groups Entitlement.
/// @return An instance of `AppCheckCore` with the specified token provider.
- (instancetype)initWithInstanceName:(NSString *)instanceName
appCheckProvider:(id<GACAppCheckProvider>)appCheckProvider
settings:(id<GACAppCheckSettingsProtocol>)settings
tokenDelegate:(id<GACAppCheckTokenDelegate>)tokenDelegate
resourceName:(NSString *)resourceName
tokenDelegate:(nullable id<GACAppCheckTokenDelegate>)tokenDelegate
keychainAccessGroup:(nullable NSString *)accessGroup;

@end
Expand Down
4 changes: 2 additions & 2 deletions AppCheckCore/Tests/Unit/Core/GACAppCheckTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ - (instancetype)initWithInstanceName:(NSString *)instanceName
storage:(id<GACAppCheckStorageProtocol>)storage
tokenRefresher:(id<GACAppCheckTokenRefresherProtocol>)tokenRefresher
settings:(id<GACAppCheckSettingsProtocol>)settings
tokenDelegate:(id<GACAppCheckTokenDelegate>)tokenDelegate;
tokenDelegate:(nullable id<GACAppCheckTokenDelegate>)tokenDelegate;

@end

Expand Down Expand Up @@ -147,8 +147,8 @@ - (void)testAppCheckInit {
GACAppCheck *appCheck = [[GACAppCheck alloc] initWithInstanceName:kAppName
appCheckProvider:mockProvider
settings:mockSettings
tokenDelegate:mockTokenDelegate
resourceName:kResourceName
tokenDelegate:mockTokenDelegate
keychainAccessGroup:kAppGroupID];
XCTAssert([appCheck isKindOfClass:[GACAppCheck class]]);

Expand Down
2 changes: 1 addition & 1 deletion AppCheckCore/Tests/Unit/Swift/AppCheckAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ final class AppCheckAPITests {
instanceName: app.name,
appCheckProvider: DummyAppCheckProvider(),
settings: DummyAppCheckSettings(),
tokenDelegate: DummyAppCheckTokenDelegate(),
resourceName: resourceName,
tokenDelegate: DummyAppCheckTokenDelegate(),
keychainAccessGroup: app.options.appGroupID
)

Expand Down
Loading