Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[google_sign_in] Fix crash on iOS caused by null hostedDomain #2521

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions packages/google_sign_in/google_sign_in/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.5.3

* Prevent exceptions from crashing app on iOS.

## 4.5.2

* Update package:e2e reference to use the local version in the flutter/plugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
[GIDSignIn sharedInstance].clientID = plist[kClientIdKey];
[GIDSignIn sharedInstance].serverClientID = plist[kServerClientIdKey];
[GIDSignIn sharedInstance].scopes = call.arguments[@"scopes"];
[GIDSignIn sharedInstance].hostedDomain = call.arguments[@"hostedDomain"];
NSString *hostedDomain = call.arguments[@"hostedDomain"];
[GIDSignIn sharedInstance].hostedDomain =
hostedDomain != (id)[NSNull null] ? hostedDomain : @"";
result(nil);
} else {
result([FlutterError errorWithCode:@"missing-config"
Expand All @@ -102,7 +104,6 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
[[GIDSignIn sharedInstance] signIn];
} @catch (NSException *e) {
result([FlutterError errorWithCode:@"google_sign_in" message:e.reason details:e.name]);
[e raise];
}
}
} else if ([call.method isEqualToString:@"getTokens"]) {
Expand Down Expand Up @@ -240,9 +241,11 @@ - (void)signIn:(GIDSignIn *)signIn
#pragma mark - private methods

- (void)respondWithAccount:(id)account error:(NSError *)error {
FlutterResult result = _accountRequest;
_accountRequest = nil;
result(error != nil ? getFlutterError(error) : account);
dispatch_async(dispatch_get_main_queue(), ^{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why you added this? It doesn't look like the docs say this comes back on a different thread. Did you see this happening in production?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was more a stab in the dark at addressing someone else's crash (which I couldn't reproduce myself): flutter/flutter#44564 (comment) , and I had intended to revert it after learning that it didn't fix his problem.

I've since moved off my macincloud subscription where I created this PR, so when I get a chance I'll need to set this up in my new dev environment.

FlutterResult result = _accountRequest;
_accountRequest = nil;
result(error != nil ? getFlutterError(error) : account);
});
}

- (UIViewController *)topViewController {
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_sign_in
description: Flutter plugin for Google Sign-In, a secure authentication system
for signing in with a Google account on Android and iOS.
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
version: 4.5.2
version: 4.5.3

flutter:
plugin:
Expand Down