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/Fake/GIDAppCheckProviderFake.m b/GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m index 0a3dfb1a..6ca88bc0 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, - NSError * _Nullable))handler { +- (void)getTokenWithCompletion:(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..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" @@ -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,17 +110,16 @@ - (void)prepareForAppCheckWithCompletion:(nullable GIDAppCheckPrepareCompletion) return; } - [self.appCheck limitedUseTokenWithCompletion:^(id _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:^(id _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/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..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 @@ -57,9 +57,9 @@ - (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); + XCTAssertNotNil(token); // If there is an error, we expect a placeholder token XCTAssertEqualObjects(expectedError, error); [tokenFailExpectation fulfill]; }]; @@ -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); diff --git a/Package.swift b/Package.swift index cd74c50d..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", - .branch("main")), + .branch("CocoaPods-0.1.0-alpha.6")), .package( name: "GTMAppAuth", url: "https://github.com/google/GTMAppAuth.git",