Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 281
Add support for GTMAppAuth 5 on macOS#522
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d330203
update entitlements for sample app + docuemntation
camden-king 90a9f4d
add migration logic
camden-king 7c44268
add migration logic
camden-king 2d1e82f
add migration code
camden-king 634c7fe
fix tests for GIDAuthStateMigration
camden-king ec65658
remove unnessisary changes
camden-king 9ac80e9
changes to get ready for review
camden-king 99b0405
update test imports
camden-king 5daf3a4
fix alignment
camden-king 0154b3b
changes from review
camden-king 7a7483c
use seperate migration keys
camden-king 55b88cc
update tests
camden-king f4faadc
updates from review
camden-king 4dbaaf9
changes from review
camden-king edd8aae
Merge branch 'main' into camden-king/GTMAppAuth-v5-mac-support
brnnmrls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -26,8 +26,12 @@ | ||
| NS_ASSUME_NONNULL_BEGIN | ||
| // User preference key to detect whether or not the migration check has been performed. | ||
| static NSString *const kMigrationCheckPerformedKey = @"GID_MigrationCheckPerformed"; | ||
| // User preference key to detect whether or not the migration to GTMAppAuth has been performed. | ||
| static NSString *const kGTMAppAuthMigrationCheckPerformedKey = @"GID_MigrationCheckPerformed"; | ||
| // User preference key to detect whether or not the data protected migration has been performed. | ||
| static NSString *const kDataProtectedMigrationCheckPerformedKey = | ||
| @"GID_DataProtectedMigrationCheckPerformed"; | ||
| // Keychain account used to store additional state in SDKs previous to v5, including GPPSignIn. | ||
| static NSString *const kOldKeychainAccount = @"GooglePlus"; | ||
| @@ -63,32 +67,85 @@ - (void)migrateIfNeededWithTokenURL:(NSURL *)tokenURL | ||
| callbackPath:(NSString *)callbackPath | ||
| keychainName:(NSString *)keychainName | ||
| isFreshInstall:(BOOL)isFreshInstall { | ||
| // If this is a fresh install, take no action and mark the migration checks as having been | ||
| // performed. | ||
| if (isFreshInstall) { | ||
| NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| #if TARGET_OS_OSX || TARGET_OS_MACCATALYST | ||
| [defaults setBool:YES forKey:kDataProtectedMigrationCheckPerformedKey]; | ||
| #elif TARGET_OS_IOS | ||
| [defaults setBool:YES forKey:kGTMAppAuthMigrationCheckPerformedKey]; | ||
| #endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST | ||
| return; | ||
| } | ||
| #if TARGET_OS_OSX || TARGET_OS_MACCATALYST | ||
| [self performDataProtectedMigrationIfNeeded]; | ||
| #elif TARGET_OS_IOS | ||
| [self performGIDMigrationIfNeededWithTokenURL:tokenURL | ||
| callbackPath:callbackPath | ||
| keychainName:keychainName]; | ||
| #endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST | ||
| } | ||
| #if TARGET_OS_OSX || TARGET_OS_MACCATALYST | ||
| // Migrate from the fileBasedKeychain to dataProtectedKeychain with GTMAppAuth 5.0. | ||
| - (void)performDataProtectedMigrationIfNeeded { | ||
| // See if we've performed the migration check previously. | ||
| NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| if ([defaults boolForKey:kMigrationCheckPerformedKey]) { | ||
| if ([defaults boolForKey:kDataProtectedMigrationCheckPerformedKey]) { | ||
| return; | ||
| } | ||
| // If this is not a fresh install, attempt to migrate state. If this is a fresh install, take no | ||
| // action and go on to mark the migration check as having been performed. | ||
| if (!isFreshInstall) { | ||
| // Attempt migration | ||
| GTMAuthSession *authSession = | ||
| [self extractAuthSessionWithTokenURL:tokenURL callbackPath:callbackPath]; | ||
| // If migration was successful, save our migrated state to the keychain. | ||
| 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 (err) { | ||
| return; | ||
| }; | ||
| } | ||
| GTMKeychainAttribute *fileBasedKeychain = [GTMKeychainAttribute useFileBasedKeychain]; | ||
| NSSet *attributes = [NSSet setWithArray:@[fileBasedKeychain]]; | ||
| GTMKeychainStore *keychainStoreLegacy = | ||
| [[GTMKeychainStore alloc] initWithItemName:self.keychainStore.itemName | ||
| keychainAttributes:attributes]; | ||
brnnmrls marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| GTMAuthSession *authSession = [keychainStoreLegacy retrieveAuthSessionWithError:nil]; | ||
| // If migration was successful, save our migrated state to the keychain. | ||
| 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 (err) { | ||
| return; | ||
| }; | ||
| [keychainStoreLegacy removeAuthSessionWithError:nil]; | ||
| } | ||
| // Mark the migration check as having been performed. | ||
| [defaults setBool:YES forKey:kDataProtectedMigrationCheckPerformedKey]; | ||
| } | ||
| #elif TARGET_OS_IOS | ||
| // Migrate from GPPSignIn 1.x or GIDSignIn 1.0 - 4.x to the GTMAppAuth storage introduced in | ||
| // GIDSignIn 5.0. | ||
| - (void)performGIDMigrationIfNeededWithTokenURL:(NSURL *)tokenURL | ||
| callbackPath:(NSString *)callbackPath | ||
| keychainName:(NSString *)keychainName { | ||
| // See if we've performed the migration check previously. | ||
| NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; | ||
| if ([defaults boolForKey:kGTMAppAuthMigrationCheckPerformedKey]) { | ||
| return; | ||
| } | ||
| // Attempt migration | ||
| GTMAuthSession *authSession = | ||
| [self extractAuthSessionWithTokenURL:tokenURL callbackPath:callbackPath]; | ||
| // If migration was successful, save our migrated state to the keychain. | ||
| 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 (err) { | ||
| return; | ||
| }; | ||
| } | ||
| // Mark the migration check as having been performed. | ||
| [defaults setBool:YES forKey:kMigrationCheckPerformedKey]; | ||
| [defaults setBool:YES forKey:kGTMAppAuthMigrationCheckPerformedKey]; | ||
| } | ||
| // Returns a |GTMAuthSession| object containing any old auth state or |nil| if none | ||
| @@ -189,6 +246,7 @@ + (nullable NSString *)passwordForService:(NSString *)service { | ||
| NSString *password = [[NSString alloc] initWithData:passwordData encoding:NSUTF8StringEncoding]; | ||
| return password; | ||
| } | ||
| #endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST | ||
| @end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -47,15 +47,15 @@ If you would like to see a Swift example, take a look at | ||
| Google Sign-In allows your users to sign-in to your native macOS app using their Google account | ||
| and default browser. When building for macOS, the `signInWithConfiguration:` and `addScopes:` | ||
| methods take a `presentingWindow:` parameter in place of `presentingViewController:`. Note that | ||
| in order for your macOS app to store credientials via the Keychain on macOS, you will need to | ||
| [sign your app](https://developer.apple.com/support/code-signing/). | ||
| in order for your macOS app to store credentials via the Keychain on macOS, you will need to add | ||
| `$(AppIdentifierPrefix)$(CFBundleIdentifier)` to its keychain access group. | ||
| ### Mac Catalyst | ||
| Google Sign-In also supports iOS apps that are built for macOS via | ||
| [Mac Catalyst](https://developer.apple.com/mac-catalyst/). In order for your Mac Catalyst app | ||
| to store credientials via the Keychain on macOS, you will need to | ||
| [sign your app](https://developer.apple.com/support/code-signing/). | ||
| to store credentials via the Keychain on macOS, you will need to add | ||
camden-king marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| `$(AppIdentifierPrefix)$(CFBundleIdentifier)` to its keychain access group. | ||
| ## Using the Google Sign-In Button | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.