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

Remove use of GACAppCheckTokenProtocol per AppCheckCore api changes #337

Merged
merged 4 commits into from
Aug 31, 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
2 changes: 1 addition & 1 deletion GoogleSignIn.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

@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;
Expand All @@ -38,14 +38,14 @@ - (instancetype)initWithAppCheckToken:(nullable id<GACAppCheckTokenProtocol>)tok
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
NS_ASSUME_NONNULL_BEGIN

@protocol GACAppCheckProvider;
@protocol GACAppCheckTokenProtocol;
@class GACAppCheckToken;

extern NSString *const kGIDAppCheckPreparedKey;

Expand Down Expand Up @@ -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.
Expand Down
20 changes: 9 additions & 11 deletions GoogleSignIn/Sources/GIDAppCheck/Implementations/GIDAppCheck.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,7 +35,7 @@
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 ()
Expand Down Expand Up @@ -110,17 +110,16 @@ - (void)prepareForAppCheckWithCompletion:(nullable GIDAppCheckPrepareCompletion)
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];
}

Expand All @@ -139,13 +138,12 @@ - (void)prepareForAppCheckWithCompletion:(nullable GIDAppCheckPrepareCompletion)

- (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);
}
}];
});
Expand Down
4 changes: 2 additions & 2 deletions GoogleSignIn/Sources/GIDSignIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ - (void)authorizationRequestWithOptions:(GIDSignInInternalOptions *)options comp
_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;
Expand Down
8 changes: 4 additions & 4 deletions GoogleSignIn/Tests/Unit/GIDAppCheckTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -57,9 +57,9 @@ - (void)testGetLimitedUseTokenFailure {
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];
}];
Expand Down Expand Up @@ -126,7 +126,7 @@ - (void)testGetLimitedUseTokenSucceeds {
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);
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down