-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[google_sign_in_ios] Upgrade GoogleSignIn iOS SDK to 7.0 #5240
Changes from 2 commits
067f3fe
bb30b60
815fd8f
177f2f6
57a2b31
798fc19
04fe8a7
f66c4cb
f366a3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 5.6.5 | ||
|
||
* Upgrades GoogleSignIn iOS SDK to 7.0. | ||
|
||
## 5.6.4 | ||
|
||
* Converts platform communication to Pigeon. | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,10 +47,6 @@ | |
|
||
@interface FLTGoogleSignInPlugin () | ||
|
||
// Configuration wrapping Google Cloud Console, Google Apps, OpenID, | ||
// and other initialization metadata. | ||
@property(strong) GIDConfiguration *configuration; | ||
|
||
// Permissions requested during at sign in "init" method call | ||
// unioned with scopes requested later with incremental authorization | ||
// "requestScopes" method call. | ||
|
@@ -116,18 +112,14 @@ - (void)initializeSignInWithParameters:(nonnull FSIInitParams *)params | |
if (configuration != nil) { | ||
self.requestedScopes = [NSSet setWithArray:params.scopes]; | ||
self.configuration = configuration; | ||
} else { | ||
*error = [FlutterError errorWithCode:@"missing-config" | ||
message:@"GoogleService-Info.plist file not found and clientId " | ||
@"was not provided programmatically." | ||
details:nil]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Google Sign In SDK now gets the configuration settings within the SDK itself from the Info.plist and that's now the preferred way to do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, we should put an updated version of https://pub.dev/packages/google_sign_in#ios-integration into this package's README, and then update the main package README to point to that for iOS integration details. That's the pattern we are increasingly using for non-trivial setup docs in federated plugins (due to issues like this, where the setup steps actually depend on the version of the sub-package you are using). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI I moved |
||
} | ||
} | ||
|
||
- (void)signInSilentlyWithCompletion:(nonnull void (^)(FSIUserData *_Nullable, | ||
FlutterError *_Nullable))completion { | ||
[self.signIn restorePreviousSignInWithCallback:^(GIDGoogleUser *user, NSError *error) { | ||
[self didSignInForUser:user withCompletion:completion error:error]; | ||
[self.signIn restorePreviousSignInWithCompletion:^(GIDGoogleUser *_Nullable user, | ||
NSError *_Nullable error) { | ||
[self didSignInForUser:user serverAuthCode:nil withCompletion:completion error:error]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may notice here I set However, I think the new way where it doesn't include the |
||
}]; | ||
} | ||
|
||
|
@@ -139,19 +131,36 @@ - (nullable NSNumber *)isSignedInWithError: | |
- (void)signInWithCompletion:(nonnull void (^)(FSIUserData *_Nullable, | ||
FlutterError *_Nullable))completion { | ||
@try { | ||
GIDConfiguration *configuration = self.configuration | ||
?: [self configurationWithClientIdArgument:nil | ||
serverClientIdArgument:nil | ||
hostedDomainArgument:nil]; | ||
[self.signIn signInWithConfiguration:configuration | ||
presentingViewController:[self topViewController] | ||
hint:nil | ||
additionalScopes:self.requestedScopes.allObjects | ||
callback:^(GIDGoogleUser *user, NSError *error) { | ||
[self didSignInForUser:user | ||
withCompletion:completion | ||
error:error]; | ||
}]; | ||
// If the configuration settings are passed from the Dart API, use those. | ||
// Otherwise, use settings from the GoogleService-Info.plist if available. | ||
// If neither are available, do not set the configuration - GIDSignIn will automatically use | ||
// settings from the Info.plist (which is the recommended method). | ||
if (!self.configuration && self.googleServiceProperties) { | ||
self.configuration = [self configurationWithClientIdArgument:nil | ||
serverClientIdArgument:nil | ||
hostedDomainArgument:nil]; | ||
} | ||
if (self.configuration) { | ||
self.signIn.configuration = self.configuration; | ||
} | ||
|
||
[self.signIn signInWithPresentingViewController:[self topViewController] | ||
hint:nil | ||
additionalScopes:self.requestedScopes.allObjects | ||
completion:^(GIDSignInResult *_Nullable signInResult, | ||
NSError *_Nullable error) { | ||
GIDGoogleUser *user; | ||
NSString *serverAuthCode; | ||
if (signInResult) { | ||
user = signInResult.user; | ||
serverAuthCode = signInResult.serverAuthCode; | ||
} | ||
|
||
[self didSignInForUser:user | ||
serverAuthCode:serverAuthCode | ||
withCompletion:completion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the |
||
error:error]; | ||
}]; | ||
} @catch (NSException *e) { | ||
completion(nil, [FlutterError errorWithCode:@"google_sign_in" message:e.reason details:e.name]); | ||
[e raise]; | ||
|
@@ -161,13 +170,13 @@ - (void)signInWithCompletion:(nonnull void (^)(FSIUserData *_Nullable, | |
- (void)getAccessTokenWithCompletion:(nonnull void (^)(FSITokenData *_Nullable, | ||
FlutterError *_Nullable))completion { | ||
GIDGoogleUser *currentUser = self.signIn.currentUser; | ||
GIDAuthentication *auth = currentUser.authentication; | ||
[auth doWithFreshTokens:^void(GIDAuthentication *authentication, NSError *error) { | ||
[currentUser refreshTokensIfNeededWithCompletion:^(GIDGoogleUser *_Nullable user, | ||
NSError *_Nullable error) { | ||
if (error) { | ||
completion(nil, getFlutterError(error)); | ||
} else { | ||
completion([FSITokenData makeWithIdToken:authentication.idToken | ||
accessToken:authentication.accessToken], | ||
completion([FSITokenData makeWithIdToken:user.idToken.tokenString | ||
accessToken:user.accessToken.tokenString], | ||
nil); | ||
} | ||
}]; | ||
|
@@ -177,7 +186,7 @@ - (void)signOutWithError:(FlutterError *_Nullable *_Nonnull)error; | |
{ [self.signIn signOut]; } | ||
|
||
- (void)disconnectWithCompletion:(nonnull void (^)(FlutterError *_Nullable))completion { | ||
[self.signIn disconnectWithCallback:^(NSError *error) { | ||
[self.signIn disconnectWithCompletion:^(NSError *_Nullable error) { | ||
// TODO(stuartmorgan): This preserves the pre-Pigeon-migration behavior, but it's unclear why | ||
// 'error' is being ignored here. | ||
completion(nil); | ||
|
@@ -190,31 +199,38 @@ - (void)requestScopes:(nonnull NSArray<NSString *> *)scopes | |
NSSet<NSString *> *requestedScopes = self.requestedScopes; | ||
|
||
@try { | ||
[self.signIn addScopes:requestedScopes.allObjects | ||
GIDGoogleUser *currentUser = self.signIn.currentUser; | ||
if (currentUser == nil) { | ||
completion(nil, [FlutterError errorWithCode:@"sign_in_required" | ||
message:@"No account to grant scopes." | ||
details:nil]); | ||
} | ||
[currentUser addScopes:requestedScopes.allObjects | ||
presentingViewController:[self topViewController] | ||
callback:^(GIDGoogleUser *addedScopeUser, NSError *addedScopeError) { | ||
BOOL granted = NO; | ||
FlutterError *error = nil; | ||
if ([addedScopeError.domain isEqualToString:kGIDSignInErrorDomain] && | ||
addedScopeError.code == kGIDSignInErrorCodeNoCurrentUser) { | ||
error = [FlutterError errorWithCode:@"sign_in_required" | ||
message:@"No account to grant scopes." | ||
details:nil]; | ||
} else if ([addedScopeError.domain | ||
isEqualToString:kGIDSignInErrorDomain] && | ||
addedScopeError.code == | ||
kGIDSignInErrorCodeScopesAlreadyGranted) { | ||
// Scopes already granted, report success. | ||
granted = YES; | ||
} else if (addedScopeUser == nil) { | ||
granted = NO; | ||
} else { | ||
NSSet<NSString *> *grantedScopes = | ||
[NSSet setWithArray:addedScopeUser.grantedScopes]; | ||
granted = [requestedScopes isSubsetOfSet:grantedScopes]; | ||
} | ||
completion(error == nil ? @(granted) : nil, error); | ||
}]; | ||
completion:^(GIDSignInResult *_Nullable signInResult, | ||
NSError *_Nullable addedScopeError) { | ||
BOOL granted = NO; | ||
FlutterError *error = nil; | ||
|
||
if ([addedScopeError.domain isEqualToString:kGIDSignInErrorDomain] && | ||
addedScopeError.code == kGIDSignInErrorCodeMismatchWithCurrentUser) { | ||
error = | ||
[FlutterError errorWithCode:@"request_scopes" | ||
vashworth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
message:@"There is an operation on a previous " | ||
@"user. Try signing in again." | ||
details:nil]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, they removed |
||
} else if ([addedScopeError.domain isEqualToString:kGIDSignInErrorDomain] && | ||
addedScopeError.code == | ||
kGIDSignInErrorCodeScopesAlreadyGranted) { | ||
// Scopes already granted, report success. | ||
granted = YES; | ||
} else if (signInResult.user) { | ||
NSSet<NSString *> *grantedScopes = | ||
[NSSet setWithArray:signInResult.user.grantedScopes]; | ||
granted = [requestedScopes isSubsetOfSet:grantedScopes]; | ||
} | ||
completion(error == nil ? @(granted) : nil, error); | ||
}]; | ||
} @catch (NSException *e) { | ||
completion(nil, [FlutterError errorWithCode:@"request_scopes" message:e.reason details:e.name]); | ||
} | ||
|
@@ -265,6 +281,7 @@ - (GIDConfiguration *)configurationWithClientIdArgument:(id)clientIDArg | |
} | ||
|
||
- (void)didSignInForUser:(GIDGoogleUser *)user | ||
serverAuthCode:(NSString *_Nullable)serverAuthCode | ||
withCompletion:(nonnull void (^)(FSIUserData *_Nullable, | ||
FlutterError *_Nullable))completion | ||
error:(NSError *)error { | ||
|
@@ -281,7 +298,7 @@ - (void)didSignInForUser:(GIDGoogleUser *)user | |
email:user.profile.email | ||
userId:user.userID | ||
photoUrl:[photoUrl absoluteString] | ||
serverAuthCode:user.serverAuthCode], | ||
serverAuthCode:serverAuthCode], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you audited the new API against the Dart types to see if we want any more changes here? The current situation is that we have optional types on various return objects ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
nil); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this?