Skip to content

Commit

Permalink
Merge branch 'main' into mdmathias/async-support
Browse files Browse the repository at this point in the history
  • Loading branch information
petea committed Dec 8, 2022
2 parents 0d1f63d + f434473 commit 0f00694
Show file tree
Hide file tree
Showing 53 changed files with 2,190 additions and 1,555 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Build GSI for Valid Architectures

on:
push:
branches:
- main
pull_request:
workflow_dispatch:
schedule:
- cron: '0 8 * * *' # Cron uses UTC; run at nightly at midnight PST

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: tests
name: unit_tests

on:
push:
Expand Down
8 changes: 4 additions & 4 deletions GoogleSignIn.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GoogleSignIn'
s.version = '6.2.4'
s.version = '7.0.0'
s.summary = 'Enables iOS apps to sign in with Google.'
s.description = <<-DESC
The Google Sign-In SDK allows users to sign in with their Google account from third-party apps.
Expand All @@ -12,7 +12,7 @@ The Google Sign-In SDK allows users to sign in with their Google account from th
:git => 'https://github.com/google/GoogleSignIn-iOS.git',
:tag => s.version.to_s
}
ios_deployment_target = '9.0'
ios_deployment_target = '10.0'
osx_deployment_target = '10.15'
s.ios.deployment_target = ios_deployment_target
s.osx.deployment_target = osx_deployment_target
Expand All @@ -33,8 +33,8 @@ 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 'AppAuth', '~> 1.5'
s.dependency 'GTMAppAuth', '~> 1.3'
s.dependency 'GTMSessionFetcher/Core', '>= 1.1', '< 3.0'
s.dependency 'GTMAppAuth', '>= 1.3', '< 3.0'
s.dependency 'GTMSessionFetcher/Core', '>= 1.1', '< 4.0'
s.resource_bundle = {
'GoogleSignIn' => ['GoogleSignIn/Sources/{Resources,Strings}/*']
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#ifdef SWIFT_PACKAGE
@import GTMAppAuth;
#else
#import <GTMAppAuth/GTMAppAuth.h>
#endif

NS_ASSUME_NONNULL_BEGIN

// A specialized GTMAppAuthFetcherAuthorization subclass with EMM support.
@interface GIDAppAuthFetcherAuthorizationWithEMMSupport : GTMAppAuthFetcherAuthorization

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
129 changes: 129 additions & 0 deletions GoogleSignIn/Sources/GIDAppAuthFetcherAuthorizationWithEMMSupport.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <TargetConditionals.h>

#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST

#import "GoogleSignIn/Sources/GIDAppAuthFetcherAuthorizationWithEMMSupport.h"

#import "GoogleSignIn/Sources/GIDEMMSupport.h"

#ifdef SWIFT_PACKAGE
@import AppAuth;
@import GTMAppAuth;
#else
#import <AppAuth/AppAuth.h>
#import <GTMAppAuth/GTMAppAuth.h>
#endif

NS_ASSUME_NONNULL_BEGIN

// The specialized GTMAppAuthFetcherAuthorization delegate that handles potential EMM error
// responses.
@interface GIDAppAuthFetcherAuthorizationEMMChainedDelegate : NSObject

// Initializes with chained delegate and selector.
- (instancetype)initWithDelegate:(id)delegate selector:(SEL)selector;

// The callback method for GTMAppAuthFetcherAuthorization to invoke.
- (void)authentication:(GTMAppAuthFetcherAuthorization *)auth
request:(NSMutableURLRequest *)request
finishedWithError:(nullable NSError *)error;

@end

@implementation GIDAppAuthFetcherAuthorizationEMMChainedDelegate {
// We use a weak reference here to match GTMAppAuthFetcherAuthorization.
__weak id _delegate;
SEL _selector;
// We need to maintain a reference to the chained delegate because GTMAppAuthFetcherAuthorization
// only keeps a weak reference.
GIDAppAuthFetcherAuthorizationEMMChainedDelegate *_retained_self;
}

- (instancetype)initWithDelegate:(id)delegate selector:(SEL)selector {
self = [super init];
if (self) {
_delegate = delegate;
_selector = selector;
_retained_self = self;
}
return self;
}

- (void)authentication:(GTMAppAuthFetcherAuthorization *)auth
request:(NSMutableURLRequest *)request
finishedWithError:(nullable NSError *)error {
[GIDEMMSupport handleTokenFetchEMMError:error completion:^(NSError *_Nullable error) {
if (!self->_delegate || !self->_selector) {
return;
}
NSMethodSignature *signature = [self->_delegate methodSignatureForSelector:self->_selector];
if (!signature) {
return;
}
id argument1 = auth;
id argument2 = request;
id argument3 = error;
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:self->_delegate]; // index 0
[invocation setSelector:self->_selector]; // index 1
[invocation setArgument:&argument1 atIndex:2];
[invocation setArgument:&argument2 atIndex:3];
[invocation setArgument:&argument3 atIndex:4];
[invocation invoke];
}];
// Prepare to deallocate the chained delegate instance because the above block will retain the
// iVar references it uses.
_retained_self = nil;
}

@end

@implementation GIDAppAuthFetcherAuthorizationWithEMMSupport

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
- (void)authorizeRequest:(nullable NSMutableURLRequest *)request
delegate:(id)delegate
didFinishSelector:(SEL)sel {
#pragma clang diagnostic pop
GIDAppAuthFetcherAuthorizationEMMChainedDelegate *chainedDelegate =
[[GIDAppAuthFetcherAuthorizationEMMChainedDelegate alloc] initWithDelegate:delegate
selector:sel];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[super authorizeRequest:request
delegate:chainedDelegate
didFinishSelector:@selector(authentication:request:finishedWithError:)];
#pragma clang diagnostic pop
}

- (void)authorizeRequest:(nullable NSMutableURLRequest *)request
completionHandler:(GTMAppAuthFetcherAuthorizationCompletion)handler {
[super authorizeRequest:request completionHandler:^(NSError *_Nullable error) {
[GIDEMMSupport handleTokenFetchEMMError:error completion:^(NSError *_Nullable error) {
handler(error);
}];
}];
}

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Google LLC
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,12 +14,19 @@
* limitations under the License.
*/

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDAuthentication.h"
#import <Foundation/Foundation.h>

@interface GIDAuthentication (Testing)
@class OIDAuthState;

- (BOOL)isEqual:(id)object;
- (BOOL)isEqualToAuthentication:(GIDAuthentication *)other;
- (NSUInteger)hash;
NS_ASSUME_NONNULL_BEGIN

// Internal class for GIDGoogleUser NSCoding backward compatibility.
@interface GIDAuthentication : NSObject <NSSecureCoding>

@property(nonatomic) OIDAuthState* authState;

- (instancetype)initWithAuthState:(OIDAuthState *)authState;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 0f00694

Please sign in to comment.