Преглед изворни кода

Remove use of GACAppCheckTokenProtocol per AppCheckCore api changes (#337)

mdmathias пре 2 година
родитељ
комит
de9f81df4f

+ 1 - 1
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'

+ 5 - 5
GoogleSignIn/Sources/GIDAppCheck/Implementations/Fake/GIDAppCheckProviderFake.m

@@ -22,14 +22,14 @@ NSUInteger const kGIDAppCheckProviderFakeError = 1;
 
 @interface GIDAppCheckProviderFake ()
 
-@property(nonatomic, strong, nullable) id<GACAppCheckTokenProtocol> token;
+@property(nonatomic, strong, nullable) GACAppCheckToken *token;
 @property(nonatomic, strong, nullable) NSError *error;
 
 @end
 
 @implementation GIDAppCheckProviderFake
 
-- (instancetype)initWithAppCheckToken:(nullable id<GACAppCheckTokenProtocol>)token
+- (instancetype)initWithAppCheckToken:(nullable GACAppCheckToken *)token
                                 error:(nullable NSError *)error {
   if (self = [super init]) {
     _token = token;
@@ -38,14 +38,14 @@ NSUInteger const kGIDAppCheckProviderFakeError = 1;
   return self;
 }
 
-- (void)getTokenWithCompletion:(nonnull void (^)(id<GACAppCheckTokenProtocol> _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<GACAppCheckTokenProtocol> _Nullable,
+- (void)getLimitedUseTokenWithCompletion:(void (^)(GACAppCheckToken * _Nullable,
                                                    NSError * _Nullable))handler {
   dispatch_async(dispatch_get_main_queue(), ^{
     handler(self.token, self.error);

+ 2 - 2
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<GACAppCheckTokenProtocol> _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.

+ 9 - 11
GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m

@@ -20,7 +20,7 @@
 
 #import <AppCheckCore/GACAppCheck.h>
 #import <AppCheckCore/GACAppCheckSettings.h>
-#import <AppCheckCore/GACAppCheckToken.h>
+#import <AppCheckCore/GACAppCheckTokenResult.h>
 #import <AppCheckCore/GACAppAttestProvider.h>
 
 #import "GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.h"
@@ -35,7 +35,7 @@ static NSString *const kGIDAppAttestResourceNameFormat = @"oauthClients/%@";
 static NSString *const kGIDAppAttestBaseURL = @"https://firebaseappcheck.googleapis.com/v1beta";
 
 typedef void (^GIDAppCheckPrepareCompletion)(NSError * _Nullable);
-typedef void (^GIDAppCheckTokenCompletion)(id<GACAppCheckTokenProtocol> _Nullable,
+typedef void (^GIDAppCheckTokenCompletion)(GACAppCheckToken * _Nullable,
                                            NSError * _Nullable);
 
 @interface GIDAppCheck ()
@@ -110,17 +110,16 @@ typedef void (^GIDAppCheckTokenCompletion)(id<GACAppCheckTokenProtocol> _Nullabl
       return;
     }
 
-    [self.appCheck limitedUseTokenWithCompletion:^(id<GACAppCheckTokenProtocol> _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 @@ typedef void (^GIDAppCheckTokenCompletion)(id<GACAppCheckTokenProtocol> _Nullabl
 
 - (void)getLimitedUseTokenWithCompletion:(nullable GIDAppCheckTokenCompletion)completion {
   dispatch_async(self.workerQueue, ^{
-    [self.appCheck limitedUseTokenWithCompletion:^(id<GACAppCheckTokenProtocol> _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);
       }
     }];
   });

+ 2 - 2
GoogleSignIn/Sources/GIDSignIn.m

@@ -646,8 +646,8 @@ static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
         _timedLoader = [[GIDTimedLoader alloc] initWithPresentingViewController:presentingVC];
       }
       [_timedLoader startTiming];
-      [self->_appCheck getLimitedUseTokenWithCompletion:
-          ^(id<GACAppCheckTokenProtocol> _Nullable token, NSError * _Nullable error) {
+      [self->_appCheck getLimitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token,
+                                                          NSError * _Nullable error) {
         OIDAuthorizationRequest *request = nil;
         if (token) {
           additionalParameters[kClientAssertionTypeParameter] = kClientAssertionTypeParameterValue;

+ 4 - 4
GoogleSignIn/Tests/Unit/GIDAppCheckTest.m

@@ -45,7 +45,7 @@ NS_CLASS_AVAILABLE_IOS(14)
   [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 @@ NS_CLASS_AVAILABLE_IOS(14)
   GIDAppCheck *appCheck = [[GIDAppCheck alloc] initWithAppCheckProvider:fakeProvider
                                                            userDefaults:self.userDefaults];
 
-  [appCheck getLimitedUseTokenWithCompletion:^(id<GACAppCheckTokenProtocol> _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 @@ NS_CLASS_AVAILABLE_IOS(14)
   XCTestExpectation *getLimitedUseTokenSucceedsExpectation =
       [self expectationWithDescription:@"getLimitedUseToken should succeed"];
 
-  [appCheck getLimitedUseTokenWithCompletion:^(id<GACAppCheckTokenProtocol> _Nullable token,
+  [appCheck getLimitedUseTokenWithCompletion:^(GACAppCheckToken * _Nullable token,
                                                NSError * _Nullable error) {
     XCTAssertNil(error);
     XCTAssertNotNil(token);

+ 1 - 1
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",