Skip to content
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] Clean up pre-Pigeon code #6141

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/google_sign_in/google_sign_in_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 5.7.4

* Improves type handling in Objective-C code.
* Updates minimum iOS version to 12.0 and minimum Flutter version to 3.16.6.

## 5.7.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ - (BOOL)handleOpenURLs:(NSArray<NSURL *> *)urls {

- (void)initializeSignInWithParameters:(nonnull FSIInitParams *)params
error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
GIDConfiguration *configuration = [self configurationWithClientIdArgument:params.clientId
serverClientIdArgument:params.serverClientId
hostedDomainArgument:params.hostedDomain];
GIDConfiguration *configuration = [self configurationWithClientIdentifier:params.clientId
serverClientIdentifier:params.serverClientId
hostedDomain:params.hostedDomain];
self.requestedScopes = [NSSet setWithArray:params.scopes];
if (configuration != nil) {
self.configuration = configuration;
Expand Down Expand Up @@ -141,9 +141,9 @@ - (void)signInWithCompletion:(nonnull void (^)(FSIUserData *_Nullable,
// 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];
self.configuration = [self configurationWithClientIdentifier:nil
serverClientIdentifier:nil
hostedDomain:nil];
}
if (self.configuration) {
self.signIn.configuration = self.configuration;
Expand Down Expand Up @@ -270,30 +270,19 @@ - (void)addScopes:(NSArray<NSString *> *)scopes
#endif
}

/// @return @c nil if GoogleService-Info.plist not found and clientId is not provided.
- (GIDConfiguration *)configurationWithClientIdArgument:(id)clientIDArg
serverClientIdArgument:(id)serverClientIDArg
hostedDomainArgument:(id)hostedDomainArg {
NSString *clientID;
BOOL hasDynamicClientId = [clientIDArg isKindOfClass:[NSString class]];
if (hasDynamicClientId) {
clientID = clientIDArg;
} else if (self.googleServiceProperties) {
clientID = self.googleServiceProperties[kClientIdKey];
} else {
// We couldn't resolve a clientId, without which we cannot create a GIDConfiguration.
/// @return @c nil if GoogleService-Info.plist not found and runtimeClientIdentifier is not
/// provided.
- (GIDConfiguration *)configurationWithClientIdentifier:(NSString *)runtimeClientIdentifier
serverClientIdentifier:(NSString *)runtimeServerClientIdentifier
hostedDomain:(id)hostedDomain {
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
NSString *clientID = runtimeClientIdentifier ?: self.googleServiceProperties[kClientIdKey];
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need to check if self.googleServiceProperties is null before getting a key from it? Wouldn't it error/crash if it's null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope! foo[bar] is just a shorthand for [foo objectForKeyedSubscript:bar], so standard messaging rules (a message to nil returns zero'd memory, nil in this case) apply.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Notice that the previous serverClientID code was actually already relying on that, so this code wasn't even consistent about the overkill 🙂)

if (!clientID) {
// Creating a GIDConfiguration requires a client identifier.
return nil;
}
NSString *serverClientID =
runtimeServerClientIdentifier ?: self.googleServiceProperties[kServerClientIdKey];

BOOL hasDynamicServerClientId = [serverClientIDArg isKindOfClass:[NSString class]];
NSString *serverClientID = hasDynamicServerClientId
? serverClientIDArg
: self.googleServiceProperties[kServerClientIdKey];

NSString *hostedDomain = nil;
if (hostedDomainArg != [NSNull null]) {
hostedDomain = hostedDomainArg;
}
stuartmorgan marked this conversation as resolved.
Show resolved Hide resolved
return [[GIDConfiguration alloc] initWithClientID:clientID
serverClientID:serverClientID
hostedDomain:hostedDomain
Expand Down
2 changes: 1 addition & 1 deletion packages/google_sign_in/google_sign_in_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_sign_in_ios
description: iOS implementation of the google_sign_in plugin.
repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in_ios
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
version: 5.7.3
version: 5.7.4

environment:
sdk: ^3.2.3
Expand Down