From 2925caa257a14ab834355c77d5ee9ecadc51105a Mon Sep 17 00:00:00 2001 From: Matthew Mathias Date: Wed, 30 Aug 2023 17:13:18 -0700 Subject: [PATCH 1/4] Remove use of GACAppCheckTokenProtocol per AppCheckCore api changes --- .../Implementations/Fake/GIDAppCheckProviderFake.m | 8 ++++---- .../Sources/GIDAppCheck/Implementations/GIDAppCheck.h | 4 ++-- .../Sources/GIDAppCheck/Implementations/GIDAppCheck.m | 6 +++--- GoogleSignIn/Sources/GIDSignIn.m | 4 ++-- GoogleSignIn/Tests/Unit/GIDAppCheckTest.m | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m b/GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m index 0a3dfb1a..49faef73 100644 --- a/GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m +++ b/GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m @@ -22,14 +22,14 @@ @interface GIDAppCheckProviderFake () -@property(nonatomic, strong, nullable) id token; +@property(nonatomic, strong, nullable) GACAppCheckToken *token; @property(nonatomic, strong, nullable) NSError *error; @end @implementation GIDAppCheckProviderFake -- (instancetype)initWithAppCheckToken:(nullable id)token +- (instancetype)initWithAppCheckToken:(nullable GACAppCheckToken *)token error:(nullable NSError *)error { if (self = [super init]) { _token = token; @@ -38,14 +38,14 @@ - (instancetype)initWithAppCheckToken:(nullable id)tok return self; } -- (void)getTokenWithCompletion:(nonnull void (^)(id _Nullable, +- (void)getTokenWithCompletion:(nonnull void (^)(GACAppCheckToken * _Nullable, NSError * _Nullable))handler { dispatch_async(dispatch_get_main_queue(), ^{ handler(self.token, self.error); }); } -- (void)getLimitedUseTokenWithCompletion:(void (^)(id _Nullable, +- (void)getLimitedUseTokenWithCompletion:(void (^)(GACAppCheckToken * _Nullable, NSError * _Nullable))handler { dispatch_async(dispatch_get_main_queue(), ^{ handler(self.token, self.error); diff --git a/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.h b/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.h index 68d0a44e..dde7c9cd 100644 --- a/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.h +++ b/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.h @@ -23,7 +23,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol GACAppCheckProvider; -@protocol GACAppCheckTokenProtocol; +@class GACAppCheckToken; extern NSString *const kGIDAppCheckPreparedKey; @@ -58,7 +58,7 @@ NS_CLASS_AVAILABLE_IOS(14) /// @param completion A `nullable` callback with the `FIRAppCheckToken` if present, or an `NSError` /// otherwise. - (void)getLimitedUseTokenWithCompletion: - (nullable void (^)(id _Nullable token, + (nullable void (^)(GACAppCheckToken * _Nullable token, NSError * _Nullable error))completion; /// Whether or not the App Attest key ID created and the attestation object has been fetched. diff --git a/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m b/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m index 97a74241..dd4b8990 100644 --- a/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m +++ b/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m @@ -35,7 +35,7 @@ static NSString *const kGIDAppAttestBaseURL = @"https://firebaseappcheck.googleapis.com/v1beta"; typedef void (^GIDAppCheckPrepareCompletion)(NSError * _Nullable); -typedef void (^GIDAppCheckTokenCompletion)(id _Nullable, +typedef void (^GIDAppCheckTokenCompletion)(GACAppCheckToken * _Nullable, NSError * _Nullable); @interface GIDAppCheck () @@ -110,7 +110,7 @@ - (void)prepareForAppCheckWithCompletion:(nullable GIDAppCheckPrepareCompletion) return; } - [self.appCheck limitedUseTokenWithCompletion:^(id _Nullable token, + [self.appCheck limitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token, NSError * _Nullable error) { NSError * __block maybeError = error; @synchronized (self) { @@ -139,7 +139,7 @@ - (void)prepareForAppCheckWithCompletion:(nullable GIDAppCheckPrepareCompletion) - (void)getLimitedUseTokenWithCompletion:(nullable GIDAppCheckTokenCompletion)completion { dispatch_async(self.workerQueue, ^{ - [self.appCheck limitedUseTokenWithCompletion:^(id _Nullable token, + [self.appCheck limitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token, NSError * _Nullable error) { if (token) { [self.userDefaults setBool:YES forKey:kGIDAppCheckPreparedKey]; diff --git a/GoogleSignIn/Sources/GIDSignIn.m b/GoogleSignIn/Sources/GIDSignIn.m index bf832d3c..67e4cc9e 100644 --- a/GoogleSignIn/Sources/GIDSignIn.m +++ b/GoogleSignIn/Sources/GIDSignIn.m @@ -646,8 +646,8 @@ - (void)authorizationRequestWithOptions:(GIDSignInInternalOptions *)options comp _timedLoader = [[GIDTimedLoader alloc] initWithPresentingViewController:presentingVC]; } [_timedLoader startTiming]; - [self->_appCheck getLimitedUseTokenWithCompletion: - ^(id _Nullable token, NSError * _Nullable error) { + [self->_appCheck getLimitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token, + NSError * _Nullable error) { OIDAuthorizationRequest *request = nil; if (token) { additionalParameters[kClientAssertionTypeParameter] = kClientAssertionTypeParameterValue; diff --git a/GoogleSignIn/Tests/Unit/GIDAppCheckTest.m b/GoogleSignIn/Tests/Unit/GIDAppCheckTest.m index e84c9a84..b7c3c42a 100644 --- a/GoogleSignIn/Tests/Unit/GIDAppCheckTest.m +++ b/GoogleSignIn/Tests/Unit/GIDAppCheckTest.m @@ -57,7 +57,7 @@ - (void)testGetLimitedUseTokenFailure { GIDAppCheck *appCheck = [[GIDAppCheck alloc] initWithAppCheckProvider:fakeProvider userDefaults:self.userDefaults]; - [appCheck getLimitedUseTokenWithCompletion:^(id _Nullable token, + [appCheck getLimitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token, NSError * _Nullable error) { XCTAssertNil(token); XCTAssertEqualObjects(expectedError, error); @@ -126,7 +126,7 @@ - (void)testGetLimitedUseTokenSucceeds { XCTestExpectation *getLimitedUseTokenSucceedsExpectation = [self expectationWithDescription:@"getLimitedUseToken should succeed"]; - [appCheck getLimitedUseTokenWithCompletion:^(id _Nullable token, + [appCheck getLimitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token, NSError * _Nullable error) { XCTAssertNil(error); XCTAssertNotNil(token); From 3539fb82079c7c179d427269af84f20e4b0892d0 Mon Sep 17 00:00:00 2001 From: Matthew Mathias Date: Wed, 30 Aug 2023 18:39:52 -0700 Subject: [PATCH 2/4] Remove nonnull from completion --- .../Implementations/Fake/GIDAppCheckProviderFake.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m b/GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m index 49faef73..6ca88bc0 100644 --- a/GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m +++ b/GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m @@ -38,8 +38,8 @@ - (instancetype)initWithAppCheckToken:(nullable GACAppCheckToken *)token return self; } -- (void)getTokenWithCompletion:(nonnull void (^)(GACAppCheckToken * _Nullable, - NSError * _Nullable))handler { +- (void)getTokenWithCompletion:(void (^)(GACAppCheckToken * _Nullable, + NSError * _Nullable))handler { dispatch_async(dispatch_get_main_queue(), ^{ handler(self.token, self.error); }); From b0368435d6e86d9a884502cccb0e0807434aeb75 Mon Sep 17 00:00:00 2001 From: Matthew Mathias Date: Thu, 31 Aug 2023 11:15:54 -0700 Subject: [PATCH 3/4] Update api for token result --- GoogleSignIn.podspec | 2 +- .../GIDAppCheck/Implementations/GIDAppCheck.m | 18 ++++++++---------- GoogleSignIn/Tests/Unit/GIDAppCheckTest.m | 4 ++-- Package.swift | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/GoogleSignIn.podspec b/GoogleSignIn.podspec index 8c7d93b7..697f5177 100644 --- a/GoogleSignIn.podspec +++ b/GoogleSignIn.podspec @@ -33,7 +33,7 @@ The Google Sign-In SDK allows users to sign in with their Google account from th ] s.ios.framework = 'UIKit' s.osx.framework = 'AppKit' - s.dependency 'AppCheckCore', '~> 0.1.0-alpha.4' + s.dependency 'AppCheckCore', '~> 0.1.0-alpha.6' s.dependency 'AppAuth', '~> 1.6' s.dependency 'GTMAppAuth', '~> 4.0' s.dependency 'GTMSessionFetcher/Core', '>= 1.1', '< 4.0' diff --git a/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m b/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m index dd4b8990..2e4d2c60 100644 --- a/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m +++ b/GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m @@ -20,7 +20,7 @@ #import #import -#import +#import #import #import "GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.h" @@ -110,17 +110,16 @@ - (void)prepareForAppCheckWithCompletion:(nullable GIDAppCheckPrepareCompletion) return; } - [self.appCheck limitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token, - NSError * _Nullable error) { - NSError * __block maybeError = error; + [self.appCheck limitedUseTokenWithCompletion:^(GACAppCheckTokenResult * _Nonnull result) { + NSError * __block maybeError = result.error; @synchronized (self) { - if (!token && !error) { + if (!result.token && !result.error) { maybeError = [NSError errorWithDomain:kGIDAppCheckErrorDomain code:kGIDAppCheckUnexpectedError userInfo:nil]; } - if (token) { + if (result.token) { [self.userDefaults setBool:YES forKey:kGIDAppCheckPreparedKey]; } @@ -139,13 +138,12 @@ - (void)prepareForAppCheckWithCompletion:(nullable GIDAppCheckPrepareCompletion) - (void)getLimitedUseTokenWithCompletion:(nullable GIDAppCheckTokenCompletion)completion { dispatch_async(self.workerQueue, ^{ - [self.appCheck limitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token, - NSError * _Nullable error) { - if (token) { + [self.appCheck limitedUseTokenWithCompletion:^(GACAppCheckTokenResult * _Nonnull result) { + if (result.token) { [self.userDefaults setBool:YES forKey:kGIDAppCheckPreparedKey]; } if (completion) { - completion(token, error); + completion(result.token, result.error); } }]; }); diff --git a/GoogleSignIn/Tests/Unit/GIDAppCheckTest.m b/GoogleSignIn/Tests/Unit/GIDAppCheckTest.m index b7c3c42a..8ba90887 100644 --- a/GoogleSignIn/Tests/Unit/GIDAppCheckTest.m +++ b/GoogleSignIn/Tests/Unit/GIDAppCheckTest.m @@ -45,7 +45,7 @@ - (void)tearDown { [self.userDefaults removeSuiteNamed:kUserDefaultsTestSuiteName]; } -- (void)testGetLimitedUseTokenFailure { +- (void)testGetLimitedUseTokenFailureReturnsPlaceholder { XCTestExpectation *tokenFailExpectation = [self expectationWithDescription:@"App check token fail"]; NSError *expectedError = [NSError errorWithDomain:kGIDAppCheckErrorDomain @@ -59,7 +59,7 @@ - (void)testGetLimitedUseTokenFailure { [appCheck getLimitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token, NSError * _Nullable error) { - XCTAssertNil(token); + XCTAssertNotNil(token); // If there is an error, we expect a placeholder token XCTAssertEqualObjects(expectedError, error); [tokenFailExpectation fulfill]; }]; diff --git a/Package.swift b/Package.swift index cd74c50d..55687a6d 100644 --- a/Package.swift +++ b/Package.swift @@ -48,7 +48,7 @@ let package = Package( .package( name: "AppCheck", url: "https://github.com/google/app-check.git", - .branch("main")), + .revision("023abd45d302912a4f8387de7ab2b741659faca6")), .package( name: "GTMAppAuth", url: "https://github.com/google/GTMAppAuth.git", From 5a84b220ff7ebd43083f6dc5f7e3c5113ff97dd3 Mon Sep 17 00:00:00 2001 From: Matthew Mathias Date: Thu, 31 Aug 2023 13:53:16 -0700 Subject: [PATCH 4/4] Use git tag as branch for AppCheck in SPM --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 55687a6d..be46e8bd 100644 --- a/Package.swift +++ b/Package.swift @@ -48,7 +48,7 @@ let package = Package( .package( name: "AppCheck", url: "https://github.com/google/app-check.git", - .revision("023abd45d302912a4f8387de7ab2b741659faca6")), + .branch("CocoaPods-0.1.0-alpha.6")), .package( name: "GTMAppAuth", url: "https://github.com/google/GTMAppAuth.git",