Skip to content

Commit

Permalink
Revert "Revert "Temporarily revert breaking API changes for 6.2.3 pat…
Browse files Browse the repository at this point in the history
…ch release (#200)" (#201)"

This reverts commit 8345fcc.
  • Loading branch information
petea committed Sep 13, 2022
1 parent 47b0a73 commit 9c9b36a
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 179 deletions.
14 changes: 7 additions & 7 deletions GoogleSignIn/Sources/GIDAuthentication.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,17 @@ - (NSString *)emmSupport {
return authorization;
}

- (void)doWithFreshTokens:(GIDAuthenticationCompletion)completion {
- (void)doWithFreshTokens:(GIDAuthenticationAction)action {
if (!([self.accessTokenExpirationDate timeIntervalSinceNow] < kMinimalTimeToExpire ||
(self.idToken && [self.idTokenExpirationDate timeIntervalSinceNow] < kMinimalTimeToExpire))) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(self, nil);
action(self, nil);
});
return;
}
@synchronized (_authenticationHandlerQueue) {
// Push the handler into the callback queue.
[_authenticationHandlerQueue addObject:[completion copy]];
[_authenticationHandlerQueue addObject:[action copy]];
if (_authenticationHandlerQueue.count > 1) {
// This is not the first handler in the queue, no fetch is needed.
return;
Expand Down Expand Up @@ -286,9 +286,9 @@ - (void)doWithFreshTokens:(GIDAuthenticationCompletion)completion {
authenticationHandlerQueue = [self->_authenticationHandlerQueue copy];
[self->_authenticationHandlerQueue removeAllObjects];
}
for (GIDAuthenticationCompletion completion in authenticationHandlerQueue) {
for (GIDAuthenticationAction action in authenticationHandlerQueue) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(error ? nil : self, error);
action(error ? nil : self, error);
});
}
}];
Expand All @@ -298,9 +298,9 @@ - (void)doWithFreshTokens:(GIDAuthenticationCompletion)completion {
authenticationHandlerQueue = [self->_authenticationHandlerQueue copy];
[self->_authenticationHandlerQueue removeAllObjects];
}
for (GIDAuthenticationCompletion completion in authenticationHandlerQueue) {
for (GIDAuthenticationAction action in authenticationHandlerQueue) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(error ? nil : self, error);
action(error ? nil : self, error);
});
}
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Expand Down
82 changes: 41 additions & 41 deletions GoogleSignIn/Sources/GIDSignIn.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ - (BOOL)hasPreviousSignIn {
return [authState isAuthorized];
}

- (void)restorePreviousSignInWithCompletion:(nullable GIDSignInCompletion)completion {
[self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCompletion:completion]];
- (void)restorePreviousSignInWithCallback:(nullable GIDSignInCallback)callback {
[self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCallback:callback]];
}

- (BOOL)restorePreviousSignInNoRefresh {
Expand Down Expand Up @@ -217,52 +217,52 @@ - (BOOL)restorePreviousSignInNoRefresh {
- (void)signInWithConfiguration:(GIDConfiguration *)configuration
presentingViewController:(UIViewController *)presentingViewController
hint:(nullable NSString *)hint
completion:(nullable GIDSignInCompletion)completion {
callback:(nullable GIDSignInCallback)callback {
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
presentingViewController:presentingViewController
loginHint:hint
addScopesFlow:NO
completion:completion];
addScopesFlow:NO
callback:callback];
[self signInWithOptions:options];
}

- (void)signInWithConfiguration:(GIDConfiguration *)configuration
presentingViewController:(UIViewController *)presentingViewController
hint:(nullable NSString *)hint
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
completion:(nullable GIDSignInCompletion)completion {
callback:(nullable GIDSignInCallback)callback {
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
presentingViewController:presentingViewController
loginHint:hint
addScopesFlow:NO
scopes:additionalScopes
completion:completion];
callback:callback];
[self signInWithOptions:options];
}

- (void)signInWithConfiguration:(GIDConfiguration *)configuration
presentingViewController:(UIViewController *)presentingViewController
completion:(nullable GIDSignInCompletion)completion {
callback:(nullable GIDSignInCallback)callback {
[self signInWithConfiguration:configuration
presentingViewController:presentingViewController
hint:nil
completion:completion];
callback:callback];
}

- (void)addScopes:(NSArray<NSString *> *)scopes
presentingViewController:(UIViewController *)presentingViewController
completion:(nullable GIDSignInCompletion)completion {
callback:(nullable GIDSignInCallback)callback {
// A currentUser must be available in order to complete this flow.
if (!self.currentUser) {
// No currentUser is set, notify callback of failure.
NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
code:kGIDSignInErrorCodeNoCurrentUser
userInfo:nil];
if (completion) {
if (callback) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(nil, error);
callback(nil, error);
});
}
return;
Expand All @@ -278,7 +278,7 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
presentingViewController:presentingViewController
loginHint:self.currentUser.profile.email
addScopesFlow:YES
completion:completion];
callback:callback];

NSSet<NSString *> *requestedScopes = [NSSet setWithArray:scopes];
NSMutableSet<NSString *> *grantedScopes =
Expand All @@ -290,9 +290,9 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
code:kGIDSignInErrorCodeScopesAlreadyGranted
userInfo:nil];
if (completion) {
if (callback) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(nil, error);
callback(nil, error);
});
}
return;
Expand All @@ -310,52 +310,52 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
- (void)signInWithConfiguration:(GIDConfiguration *)configuration
presentingWindow:(NSWindow *)presentingWindow
hint:(nullable NSString *)hint
completion:(nullable GIDSignInCompletion)completion {
callback:(nullable GIDSignInCallback)callback {
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
presentingWindow:presentingWindow
loginHint:hint
addScopesFlow:NO
completion:completion];
addScopesFlow:NO
callback:callback];
[self signInWithOptions:options];
}

- (void)signInWithConfiguration:(GIDConfiguration *)configuration
presentingWindow:(NSWindow *)presentingWindow
completion:(nullable GIDSignInCompletion)completion {
callback:(nullable GIDSignInCallback)callback {
[self signInWithConfiguration:configuration
presentingWindow:presentingWindow
hint:nil
completion:completion];
callback:callback];
}

- (void)signInWithConfiguration:(GIDConfiguration *)configuration
presentingWindow:(NSWindow *)presentingWindow
hint:(nullable NSString *)hint
additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
completion:(nullable GIDSignInCompletion)completion {
callback:(nullable GIDSignInCallback)callback {
GIDSignInInternalOptions *options =
[GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
presentingWindow:presentingWindow
loginHint:hint
addScopesFlow:NO
scopes:additionalScopes
completion:completion];
callback:callback];
[self signInWithOptions:options];
}

- (void)addScopes:(NSArray<NSString *> *)scopes
presentingWindow:(NSWindow *)presentingWindow
completion:(nullable GIDSignInCompletion)completion {
presentingWindow:(NSWindow *)presentingWindow
callback:(nullable GIDSignInCallback)callback {
// A currentUser must be available in order to complete this flow.
if (!self.currentUser) {
// No currentUser is set, notify callback of failure.
NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
code:kGIDSignInErrorCodeNoCurrentUser
userInfo:nil];
if (completion) {
if (callback) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(nil, error);
callback(nil, error);
});
}
return;
Expand All @@ -371,7 +371,7 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
presentingWindow:presentingWindow
loginHint:self.currentUser.profile.email
addScopesFlow:YES
completion:completion];
callback:callback];

NSSet<NSString *> *requestedScopes = [NSSet setWithArray:scopes];
NSMutableSet<NSString *> *grantedScopes =
Expand All @@ -383,9 +383,9 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
code:kGIDSignInErrorCodeScopesAlreadyGranted
userInfo:nil];
if (completion) {
if (callback) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(nil, error);
callback(nil, error);
});
}
return;
Expand All @@ -411,7 +411,7 @@ - (void)signOut {
[self removeAllKeychainEntries];
}

- (void)disconnectWithCompletion:(nullable GIDDisconnectCompletion)completion {
- (void)disconnectWithCallback:(nullable GIDDisconnectCallback)callback {
GIDGoogleUser *user = _currentUser;
OIDAuthState *authState = user.authentication.authState;
if (!authState) {
Expand All @@ -428,9 +428,9 @@ - (void)disconnectWithCompletion:(nullable GIDDisconnectCompletion)completion {
if (!token) {
[self signOut];
// Nothing to do here, consider the operation successful.
if (completion) {
if (callback) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(nil);
callback(nil);
});
}
return;
Expand All @@ -453,9 +453,9 @@ - (void)disconnectWithCompletion:(nullable GIDDisconnectCompletion)completion {
if (!error) {
[self signOut];
}
if (completion) {
if (callback) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(error);
callback(error);
});
}
}];
Expand Down Expand Up @@ -538,10 +538,10 @@ - (void)signInWithOptions:(GIDSignInInternalOptions *)options {
if (error) {
[self authenticateWithOptions:options];
} else {
if (options.completion) {
if (options.callback) {
self->_currentOptions = nil;
dispatch_async(dispatch_get_main_queue(), ^{
options.completion(self->_currentUser, nil);
options.callback(self->_currentUser, nil);
});
}
}
Expand Down Expand Up @@ -707,10 +707,10 @@ - (void)authenticateWithOptions:(GIDSignInInternalOptions *)options {
NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
code:kGIDSignInErrorCodeHasNoAuthInKeychain
userInfo:nil];
if (options.completion) {
if (options.callback) {
_currentOptions = nil;
dispatch_async(dispatch_get_main_queue(), ^{
options.completion(nil, error);
options.callback(nil, error);
});
}
return;
Expand Down Expand Up @@ -881,11 +881,11 @@ - (void)addCompletionCallback:(GIDAuthFlow *)authFlow {
__weak GIDAuthFlow *weakAuthFlow = authFlow;
[authFlow addCallback:^() {
GIDAuthFlow *handlerAuthFlow = weakAuthFlow;
if (self->_currentOptions.completion) {
GIDSignInCompletion completion = self->_currentOptions.completion;
if (self->_currentOptions.callback) {
GIDSignInCallback callback = self->_currentOptions.callback;
self->_currentOptions = nil;
dispatch_async(dispatch_get_main_queue(), ^{
completion(self->_currentUser, handlerAuthFlow.error);
callback(self->_currentUser, handlerAuthFlow.error);
});
}
}];
Expand Down
14 changes: 7 additions & 7 deletions GoogleSignIn/Sources/GIDSignInInternalOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, readonly, weak, nullable) NSWindow *presentingWindow;
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST

/// The completion block to be called at the completion of the flow.
@property(nonatomic, readonly, nullable) GIDSignInCompletion completion;
/// The callback block to be called at the completion of the flow.
@property(nonatomic, readonly, nullable) GIDSignInCallback callback;

/// The scopes to be used during the flow.
@property(nonatomic, copy, nullable) NSArray<NSString *> *scopes;
Expand All @@ -69,32 +69,32 @@ NS_ASSUME_NONNULL_BEGIN
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
completion:(nullable GIDSignInCompletion)completion;
callback:(nullable GIDSignInCallback)callback;

+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingViewController:(nullable UIViewController *)presentingViewController
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
scopes:(nullable NSArray *)scopes
completion:(nullable GIDSignInCompletion)completion;
callback:(nullable GIDSignInCallback)callback;

#elif TARGET_OS_OSX
+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingWindow:(nullable NSWindow *)presentingWindow
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
completion:(nullable GIDSignInCompletion)completion;
callback:(nullable GIDSignInCallback)callback;

+ (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
presentingWindow:(nullable NSWindow *)presentingWindow
loginHint:(nullable NSString *)loginHint
addScopesFlow:(BOOL)addScopesFlow
scopes:(nullable NSArray *)scopes
completion:(nullable GIDSignInCompletion)completion;
callback:(nullable GIDSignInCallback)callback;
#endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST

/// Creates the options to sign in silently.
+ (instancetype)silentOptionsWithCompletion:(GIDSignInCompletion)completion;
+ (instancetype)silentOptionsWithCallback:(GIDSignInCallback)callback;

/// Creates options with the same values as the receiver, except for the "extra parameters", and
/// continuation flag, which are replaced by the arguments passed to this method.
Expand Down
Loading

0 comments on commit 9c9b36a

Please sign in to comment.