Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
528e534
Initial setup for GTMAA error handling
mdmathias Mar 1, 2023
0600090
Set the authorizer on the fetcher
mdmathias Mar 1, 2023
e25d044
Add the error handling delegate on the authorization
mdmathias Mar 1, 2023
aea7ec0
Add some support for testing emm support
mdmathias Mar 4, 2023
99b73d2
Do not expose method creating fetcher with an error as unneeded
mdmathias Mar 4, 2023
193ea42
Add test for testing EMM error handling flow with GTMAppAuth
mdmathias Mar 8, 2023
0eb2f1f
Add doc comments to GIDEMMSupport
mdmathias Mar 8, 2023
bd8325e
Fix GIDAuthStateMigrationTest
mdmathias Mar 22, 2023
4e2ee95
Fix most of GIDSignInTests
mdmathias Mar 23, 2023
b9d9b8f
Fix GIDSignInTest
mdmathias Mar 24, 2023
96c8c3b
Some cocoapods import fixes
mdmathias Mar 28, 2023
55aeb46
Do not forward declare protocol conformance
mdmathias Mar 28, 2023
614111f
Bump dependencies for AppAuth-iOS and GTMAppAuth
mdmathias Apr 11, 2023
c024c52
Update sample apps
mdmathias Apr 12, 2023
4febcdb
Use frameworks with static linkage in Swift sample
mdmathias Apr 12, 2023
52cef30
Remove use_libraries and use_static_frameworks flags from pod lib lint
mdmathias Apr 12, 2023
e113cdb
Add swift version
mdmathias Apr 12, 2023
a8aa402
Clean up imports
mdmathias Apr 12, 2023
d4df1fc
Fix typos and alignment issues from PR feedback
mdmathias Apr 13, 2023
c04dc0c
Set require app host to true in GoogleSignInSwiftSupport podspec
mdmathias Apr 13, 2023
434ec5a
Update EMM support test to be more clear
mdmathias Apr 13, 2023
61daac5
Remove unused init override in GIDAuthStateMigration
mdmathias Apr 13, 2023
23bbea2
Add back init in GIDAuthStateMigration.m to remove warning
mdmathias Apr 13, 2023
10677ae
Move extractAuthorizationWithTokenURL from GIDAuthStateMigration.h to…
mdmathias Apr 13, 2023
74f01ee
Add typedef to NS_ENUM
mdmathias Apr 13, 2023
bbe1557
Fix version numbers for deps in podspec and package
mdmathias Apr 13, 2023
26d8f57
Remove reference to fake fetcher error property
mdmathias Apr 20, 2023
61a08bd
Remove GIDTestWorker
mdmathias Apr 20, 2023
a87b934
Rename authState to failingAuthState in EMM error handling test
mdmathias Apr 20, 2023
38641b7
Update GIDEMMSupport to more clearly handle the updated error
mdmathias Apr 20, 2023
1a1041d
Update GIDEMMSupport to use new update error delegate method
mdmathias Apr 28, 2023
b16fbb8
Remove duplicated constants
mdmathias Apr 28, 2023
cce884e
Use new EMM error handling delegate method name
mdmathias May 4, 2023
ca7f78f
Depend upon main GTMAppAuth branch
mdmathias May 5, 2023
10b6b60
Update GIDEMMSupportTest to swizzle a key window and alert controller
mdmathias May 10, 2023
b940af4
Depend upon GTMAppAuth 4.0.0
mdmathias May 16, 2023
2dab4df
Stub expected method on keychainStore in GIDSignInTest
mdmathias May 16, 2023
e862376
Rename authorization -> authSession
mdmathias May 16, 2023
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
5 changes: 2 additions & 3 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
os: [macos-12]
podspec: [GoogleSignIn.podspec, GoogleSignInSwiftSupport.podspec]
flag: [
"",
"--use-libraries",
"",
"--use-static-frameworks"
]
include:
Expand All @@ -33,7 +32,7 @@ jobs:
- name: Lint podspec using local source
run: |
pod lib lint ${{ matrix.podspec }} --verbose \
${{ matrix.includePodspecFlag }} ${{ matrix.flag }}
${{ matrix.includePodspecFlag }} ${{ matrix.flag }}

spm-build-test:
runs-on: ${{ matrix.os }}
Expand Down
5 changes: 3 additions & 2 deletions GoogleSignIn.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +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
}
s.swift_version = '4.0'
ios_deployment_target = '10.0'
osx_deployment_target = '10.15'
s.ios.deployment_target = ios_deployment_target
Expand All @@ -32,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', '< 3.0'
s.dependency 'AppAuth', '~> 1.6'
s.dependency 'GTMAppAuth', '~> 4.0'
s.dependency 'GTMSessionFetcher/Core', '>= 1.1', '< 4.0'
s.resource_bundle = {
'GoogleSignIn' => ['GoogleSignIn/Sources/{Resources,Strings}/*']
Expand Down
129 changes: 0 additions & 129 deletions GoogleSignIn/Sources/GIDAppAuthFetcherAuthorizationWithEMMSupport.m

This file was deleted.

14 changes: 10 additions & 4 deletions GoogleSignIn/Sources/GIDAuthStateMigration.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@

#import <Foundation/Foundation.h>

@class GTMKeychainStore;
@class GTMAuthSession;

NS_ASSUME_NONNULL_BEGIN

// A class providing migration support for auth state saved by older versions of the SDK.
/// A class providing migration support for auth state saved by older versions of the SDK.
@interface GIDAuthStateMigration : NSObject

// Perform a one-time migration for auth state saved by GPPSignIn 1.x or GIDSignIn 1.0 - 4.x to the
// GTMAppAuth storage introduced in GIDSignIn 5.0.
+ (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
/// Creates an instance of this migration type with the keychain storage wrapper it will use.
- (instancetype)initWithKeychainStore:(GTMKeychainStore *)keychainStore NS_DESIGNATED_INITIALIZER;

/// Perform a one-time migration for auth state saved by GPPSignIn 1.x or GIDSignIn 1.0 - 4.x to the
/// GTMAppAuth storage introduced in GIDSignIn 5.0.
- (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
callbackPath:(NSString *)callbackPath
keychainName:(NSString *)keychainName
isFreshInstall:(BOOL)isFreshInstall;
Expand Down
68 changes: 45 additions & 23 deletions GoogleSignIn/Sources/GIDAuthStateMigration.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

#import "GoogleSignIn/Sources/GIDSignInCallbackSchemes.h"

@import GTMAppAuth;

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

NS_ASSUME_NONNULL_BEGIN
Expand All @@ -39,9 +38,28 @@
// Keychain service name used to store the last used fingerprint value.
static NSString *const kFingerprintService = @"fingerprint";

@interface GIDAuthStateMigration ()

@property (nonatomic, strong) GTMKeychainStore *keychainStore;

@end

@implementation GIDAuthStateMigration

+ (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
- (instancetype)initWithKeychainStore:(GTMKeychainStore *)keychainStore {
self = [super init];
if (self) {
_keychainStore = keychainStore;
}
return self;
}

- (instancetype)init {
GTMKeychainStore *keychainStore = [[GTMKeychainStore alloc] initWithItemName:@"auth"];
return [self initWithKeychainStore:keychainStore];
}

- (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
callbackPath:(NSString *)callbackPath
keychainName:(NSString *)keychainName
isFreshInstall:(BOOL)isFreshInstall {
Expand All @@ -55,14 +73,15 @@ + (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
// action and go on to mark the migration check as having been performed.
if (!isFreshInstall) {
// Attempt migration
GTMAppAuthFetcherAuthorization *authorization =
[self extractAuthorizationWithTokenURL:tokenURL callbackPath:callbackPath];
GTMAuthSession *authSession =
[self extractAuthSessionWithTokenURL:tokenURL callbackPath:callbackPath];

// If migration was successful, save our migrated state to the keychain.
if (authorization) {
if (authSession) {
NSError *err;
[self.keychainStore saveAuthSession:authSession error:&err];
// If we're unable to save to the keychain, return without marking migration performed.
if (![GTMAppAuthFetcherAuthorization saveAuthorization:authorization
toKeychainForName:keychainName]) {
if (err) {
return;
};
}
Expand All @@ -72,19 +91,21 @@ + (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
[defaults setBool:YES forKey:kMigrationCheckPerformedKey];
}

// Returns a |GTMAppAuthFetcherAuthorization| object containing any old auth state or |nil| if none
// Returns a |GTMAuthSession| object containing any old auth state or |nil| if none
// was found or the migration failed.
+ (nullable GTMAppAuthFetcherAuthorization *)
extractAuthorizationWithTokenURL:(NSURL *)tokenURL callbackPath:(NSString *)callbackPath {
- (nullable GTMAuthSession *)extractAuthSessionWithTokenURL:(NSURL *)tokenURL
callbackPath:(NSString *)callbackPath {
// Retrieve the last used fingerprint.
NSString *fingerprint = [GIDAuthStateMigration passwordForService:kFingerprintService];
if (!fingerprint) {
return nil;
}

// Retrieve the GTMOAuth2 persistence string.
NSString *GTMOAuth2PersistenceString = [GTMKeychain passwordFromKeychainForName:fingerprint];
if (!GTMOAuth2PersistenceString) {
NSError *passwordError;
NSString *GTMOAuth2PersistenceString =
[self.keychainStore.keychainHelper passwordForService:fingerprint error:&passwordError];
if (passwordError) {
return nil;
}

Expand Down Expand Up @@ -126,16 +147,17 @@ + (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL
additionalTokenRequestParameters];
}

// Use |GTMOAuth2KeychainCompatibility| to generate a |GTMAppAuthFetcherAuthorization| from the
// Use |GTMOAuth2Compatibility| to generate a |GTMAuthSession| from the
// persistence string, redirect URI, client ID, and token endpoint URL.
GTMAppAuthFetcherAuthorization *authorization = [GTMOAuth2KeychainCompatibility
authorizeFromPersistenceString:persistenceString
tokenURL:tokenURL
redirectURI:redirectURI
clientID:clientID
clientSecret:nil];

return authorization;
GTMAuthSession *authSession =
[GTMOAuth2Compatibility authSessionForPersistenceString:persistenceString
tokenURL:tokenURL
redirectURI:redirectURI
clientID:clientID
clientSecret:nil
error:nil];

return authSession;
}

// Returns the password string for a given service string stored by an old version of the SDK or
Expand Down
14 changes: 9 additions & 5 deletions GoogleSignIn/Sources/GIDEMMSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@

#import <Foundation/Foundation.h>

@import GTMAppAuth;

NS_ASSUME_NONNULL_BEGIN

// A class to support EMM (Enterprise Mobility Management).
@interface GIDEMMSupport : NSObject
/// A class to support EMM (Enterprise Mobility Management).
@interface GIDEMMSupport : NSObject<GTMAuthSessionDelegate>

- (instancetype)init NS_DESIGNATED_INITIALIZER;

// Handles potential EMM error from token fetch response.
/// Handles potential EMM error from token fetch response.
+ (void)handleTokenFetchEMMError:(nullable NSError *)error
completion:(void (^)(NSError *_Nullable))completion;

// Gets a new set of URL parameters that contains updated EMM-related URL parameters if needed.
/// Gets a new set of URL parameters that contains updated EMM-related URL parameters if needed.
+ (NSDictionary *)updatedEMMParametersWithParameters:(NSDictionary *)parameters;

// Gets a new set of URL parameters that also contains EMM-related URL parameters if needed.
/// Gets a new set of URL parameters that also contains EMM-related URL parameters if needed.
+ (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters
emmSupport:(nullable NSString *)emmSupport
isPasscodeInfoRequired:(BOOL)isPasscodeInfoRequired;
Expand Down
34 changes: 34 additions & 0 deletions GoogleSignIn/Sources/GIDEMMSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,26 @@
// New UIDevice system name for iOS.
static NSString *const kNewIOSSystemName = @"iOS";

// The error key in the server response.
static NSString *const kErrorKey = @"error";

// Optional separator between error prefix and the payload.
static NSString *const kErrorPayloadSeparator = @":";

// A list for recognized error codes.
typedef NS_ENUM(NSInteger, ErrorCode) {
ErrorCodeNone = 0,
ErrorCodeDeviceNotCompliant,
ErrorCodeScreenlockRequired,
ErrorCodeAppVerificationRequired,
};

@implementation GIDEMMSupport

- (instancetype)init {
return [super init];
}

+ (void)handleTokenFetchEMMError:(nullable NSError *)error
completion:(void (^)(NSError *_Nullable))completion {
NSDictionary *errorJSON = error.userInfo[OIDOAuthErrorResponseErrorKey];
Expand Down Expand Up @@ -94,6 +112,22 @@ + (NSDictionary *)parametersWithParameters:(NSDictionary *)parameters
return allParameters;
}

#pragma mark - GTMAuthSessionDelegate

- (nullable NSDictionary<NSString *,NSString *> *)
additionalTokenRefreshParametersForAuthSession:(GTMAuthSession *)authSession {
return [GIDEMMSupport updatedEMMParametersWithParameters:
authSession.authState.lastTokenResponse.additionalParameters];
}

- (void)updateErrorForAuthSession:(GTMAuthSession *)authSession
originalError:(NSError *)originalError
completion:(void (^)(NSError * _Nullable))completion {
[GIDEMMSupport handleTokenFetchEMMError:originalError completion:^(NSError *_Nullable error) {
completion(error);
}];
}

@end

NS_ASSUME_NONNULL_END
Expand Down
Loading