Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,27 @@ jobs:

spm-build-test:
runs-on: macOS-latest
strategy:
matrix:
sdk: ['macosx', 'iphonesimulator']
include:
Comment thread
Alex-4-Git marked this conversation as resolved.
Resolved
- sdk: 'macosx'
destination: '"platform=OS X,arch=x86_64"'
- sdk: 'iphonesimulator'
destination: '"platform=iOS Simulator,name=iPhone 11"'
steps:
- uses: actions/checkout@v2
- name: Build unit test target
run: |
xcodebuild \
-scheme GoogleSignIn \
-sdk 'iphonesimulator' \
-destination 'platform=iOS Simulator,name=iPhone 11' \
-sdk ${{ matrix.sdk }} \
-destination ${{ matrix.destination }} \
build-for-testing
- name: Run unit test target
run: |
xcodebuild \
-scheme GoogleSignIn \
-sdk 'iphonesimulator' \
-destination 'platform=iOS Simulator,name=iPhone 11' \
-sdk ${{ matrix.sdk }} \
-destination ${{ matrix.destination }} \
test-without-building
8 changes: 7 additions & 1 deletion GoogleSignIn.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ The Google Sign-In SDK allows users to sign in with their Google account from th
:tag => s.version.to_s
}
ios_deployment_target = '9.0'
osx_deployment_target = '10.15'
s.ios.deployment_target = ios_deployment_target
s.osx.deployment_target = osx_deployment_target
s.prefix_header_file = false
s.source_files = [
'GoogleSignIn/Sources/**/*.[mh]',
Expand All @@ -29,6 +31,7 @@ The Google Sign-In SDK allows users to sign in with their Google account from th
'Security'
]
s.ios.framework = 'UIKit'
s.osx.framework = 'AppKit'
Comment thread
Alex-4-Git marked this conversation as resolved.
Resolved
s.dependency 'AppAuth', '~> 1.4'
s.dependency 'GTMAppAuth', '~> 1.0'
s.dependency 'GTMSessionFetcher/Core', '~> 1.1'
Expand All @@ -41,7 +44,10 @@ The Google Sign-In SDK allows users to sign in with their Google account from th
'DEFINES_MODULE' => 'YES'
}
s.test_spec 'unit' do |unit_tests|
unit_tests.platforms = {:ios => ios_deployment_target}
unit_tests.platforms = {
:ios => ios_deployment_target,
:osx => osx_deployment_target
}
unit_tests.source_files = [
'GoogleSignIn/Tests/Unit/**/*.[mh]',
]
Expand Down
47 changes: 43 additions & 4 deletions GoogleSignIn/Sources/GIDAuthentication.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
#import "GoogleSignIn/Sources/GIDAuthentication_Private.h"

#import "GoogleSignIn/Sources/GIDSignInPreferences.h"

#if TARGET_OS_IOS
#import "GoogleSignIn/Sources/GIDEMMErrorHandler.h"
#import "GoogleSignIn/Sources/GIDMDMPasscodeState.h"
#endif

#import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h"

#ifdef SWIFT_PACKAGE
Expand Down Expand Up @@ -53,6 +57,8 @@
// New UIDevice system name for iOS.
static NSString *const kNewIOSSystemName = @"iOS";

#if TARGET_OS_IOS

// The specialized GTMAppAuthFetcherAuthorization delegate that handles potential EMM error
// responses.
@interface GTMAppAuthFetcherAuthorizationEMMChainedDelegate : NSObject
Expand Down Expand Up @@ -143,6 +149,8 @@ - (void)authorizeRequest:(nullable NSMutableURLRequest *)request

@end

#endif

@implementation GIDAuthentication {
// A queue for pending authentication handlers so we don't fire multiple requests in parallel.
// Access to this ivar should be synchronized.
Expand Down Expand Up @@ -189,17 +197,24 @@ - (nullable NSDate *)idTokenExpirationDate {

#pragma mark - Private property accessors

#if TARGET_OS_IOS
- (NSString *)emmSupport {
return
_authState.lastAuthorizationResponse.request.additionalParameters[kEMMSupportParameterName];
}
#endif

#pragma mark - Public methods

- (id<GTMFetcherAuthorizationProtocol>)fetcherAuthorizer {
#if TARGET_OS_IOS
GTMAppAuthFetcherAuthorization *authorization = self.emmSupport ?
[[GTMAppAuthFetcherAuthorizationWithEMMSupport alloc] initWithAuthState:_authState] :
[[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:_authState];
#else // TARGET_OS_OSX or TARGET_OS_MACCATALYST
GTMAppAuthFetcherAuthorization *authorization =
[[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:_authState];
#endif
authorization.tokenRefreshDelegate = self;
return authorization;
}
Expand All @@ -221,10 +236,16 @@ - (void)doWithFreshTokens:(GIDAuthenticationAction)action {
}
}
// This is the first handler in the queue, a fetch is needed.
#if TARGET_OS_IOS
OIDTokenRequest *tokenRefreshRequest =
[_authState tokenRefreshRequestWithAdditionalParameters:
[GIDAuthentication updatedEMMParametersWithParameters:
_authState.lastTokenResponse.request.additionalParameters]];
[_authState tokenRefreshRequestWithAdditionalParameters:
[GIDAuthentication updatedEMMParametersWithParameters:
_authState.lastTokenResponse.request.additionalParameters]];
#else // TARGET_OS_OSX or TARGET_OS_MACCATALYST
OIDTokenRequest *tokenRefreshRequest =
[_authState tokenRefreshRequestWithAdditionalParameters:
_authState.lastTokenResponse.request.additionalParameters];
#endif
[OIDAuthorizationService performTokenRequest:tokenRefreshRequest
originalAuthorizationResponse:_authState.lastAuthorizationResponse
callback:^(OIDTokenResponse *_Nullable tokenResponse,
Expand All @@ -244,6 +265,7 @@ - (void)doWithFreshTokens:(GIDAuthenticationAction)action {
[self->_authState updateWithAuthorizationError:error];
}
}
#if TARGET_OS_IOS
[GIDAuthentication handleTokenFetchEMMError:error completion:^(NSError *_Nullable error) {
// Process the handler queue to call back.
NSArray *authenticationHandlerQueue;
Expand All @@ -257,11 +279,23 @@ - (void)doWithFreshTokens:(GIDAuthenticationAction)action {
});
}
}];
#else // TARGET_OS_OSX or TARGET_OS_MACCATALYST
NSArray *authenticationHandlerQueue;
@synchronized(self->_authenticationHandlerQueue) {
Comment thread
Alex-4-Git marked this conversation as resolved.
Resolved
authenticationHandlerQueue = [self->_authenticationHandlerQueue copy];
[self->_authenticationHandlerQueue removeAllObjects];
}
for (GIDAuthenticationAction action in authenticationHandlerQueue) {
dispatch_async(dispatch_get_main_queue(), ^{
action(error ? nil : self, error);
});
}
#endif
}];
}

#pragma mark - Private methods

#if TARGET_OS_IOS
+ (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters
emmSupport:(nullable NSString *)emmSupport
isPasscodeInfoRequired:(BOOL)isPasscodeInfoRequired {
Expand Down Expand Up @@ -309,13 +343,18 @@ + (void)handleTokenFetchEMMError:(nullable NSError *)error
completion(error);
}
}
#endif

#pragma mark - GTMAppAuthFetcherAuthorizationTokenRefreshDelegate

- (nullable NSDictionary *)additionalRefreshParameters:
(GTMAppAuthFetcherAuthorization *)authorization {
#if TARGET_OS_IOS
return [GIDAuthentication updatedEMMParametersWithParameters:
authorization.authState.lastTokenResponse.request.additionalParameters];
#else // TARGET_OS_MACCATALYST or TARGET_OS_OSX
return authorization.authState.lastTokenResponse.request.additionalParameters;
#endif
}

#pragma mark - NSSecureCoding
Expand Down
4 changes: 4 additions & 0 deletions GoogleSignIn/Sources/GIDAuthentication_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ NS_ASSUME_NONNULL_BEGIN
// A representation of the state of the OAuth session for this instance.
@property(nonatomic, readonly) OIDAuthState *authState;

#if TARGET_OS_IOS
// A string indicating support for Enterprise Mobility Management.
@property(nonatomic, readonly) NSString *emmSupport;
#endif

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

#if TARGET_OS_IOS
// Gets a new set of URL parameters that also contains EMM-related URL parameters if needed.
+ (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters
emmSupport:(nullable NSString *)emmSupport
Expand All @@ -48,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
// Handles potential EMM error from token fetch response.
+ (void)handleTokenFetchEMMError:(nullable NSError *)error
completion:(void (^)(NSError *_Nullable))completion;
#endif

@end

Expand Down
5 changes: 5 additions & 0 deletions GoogleSignIn/Sources/GIDEMMErrorHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <TargetConditionals.h>

#if TARGET_OS_IOS

#import <Foundation/Foundation.h>

Expand All @@ -35,3 +38,5 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

#endif
5 changes: 5 additions & 0 deletions GoogleSignIn/Sources/GIDEMMErrorHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// 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

#import "GoogleSignIn/Sources/GIDEMMErrorHandler.h"

Expand Down Expand Up @@ -283,3 +286,5 @@ - (NSString *)cancelString {
@end

NS_ASSUME_NONNULL_END

#endif
5 changes: 5 additions & 0 deletions GoogleSignIn/Sources/GIDMDMPasscodeCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <TargetConditionals.h>

#if TARGET_OS_IOS

#import <Foundation/Foundation.h>

Expand All @@ -39,3 +42,5 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

#endif
5 changes: 5 additions & 0 deletions GoogleSignIn/Sources/GIDMDMPasscodeCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// 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

#import "GoogleSignIn/Sources/GIDMDMPasscodeCache.h"

Expand Down Expand Up @@ -294,3 +297,5 @@ - (NSString *)info {
@end

NS_ASSUME_NONNULL_END

#endif
4 changes: 4 additions & 0 deletions GoogleSignIn/Sources/GIDMDMPasscodeState.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <TargetConditionals.h>

#if TARGET_OS_IOS

#import <Foundation/Foundation.h>

Expand Down Expand Up @@ -48,3 +51,4 @@ NS_ASSUME_NONNULL_BEGIN

NS_ASSUME_NONNULL_END

#endif
5 changes: 5 additions & 0 deletions GoogleSignIn/Sources/GIDMDMPasscodeState.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
// 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

#import "GoogleSignIn/Sources/GIDMDMPasscodeState.h"

Expand Down Expand Up @@ -48,3 +51,5 @@ + (instancetype)passcodeState {
@end

NS_ASSUME_NONNULL_END

#endif
5 changes: 5 additions & 0 deletions GoogleSignIn/Sources/GIDMDMPasscodeState_Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <TargetConditionals.h>

#if TARGET_OS_IOS

#import <Foundation/Foundation.h>

Expand All @@ -33,3 +36,5 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

#endif
Loading