Przeglądaj źródła

Move configuration creation methods to GIDConfiguration from GIDSignIn.

brianna 1 rok temu
rodzic
commit
58969855df

+ 35 - 0
GoogleSignIn/Sources/GIDConfiguration.m

@@ -26,6 +26,12 @@ static NSString *const kHostedDomainKey = @"hostedDomain";
 // The key for the openIDRealm property to be used with NSSecureCoding.
 static NSString *const kOpenIDRealmKey = @"openIDRealm";
 
+// Info.plist config keys
+static NSString *const kConfigClientIDKey = @"GIDClientID";
+static NSString *const kConfigServerClientIDKey = @"GIDServerClientID";
+static NSString *const kConfigHostedDomainKey = @"GIDHostedDomain";
+static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
+
 NS_ASSUME_NONNULL_BEGIN
 
 @implementation GIDConfiguration
@@ -59,6 +65,35 @@ NS_ASSUME_NONNULL_BEGIN
   return self;
 }
 
+// Try to retrieve a configuration value from an |NSBundle|'s Info.plist for a given key.
++ (nullable NSString *)configValueFromBundle:(NSBundle *)bundle forKey:(NSString *)key {
+  NSString *value;
+  id configValue = [bundle objectForInfoDictionaryKey:key];
+  if ([configValue isKindOfClass:[NSString class]]) {
+    value = configValue;
+  }
+  return value;
+}
+
++ (nullable instancetype)configurationFromBundle:(NSBundle *)bundle {
+  // Retrieve any valid config parameters from the bundle's Info.plist.
+  NSString *clientID = [self configValueFromBundle:bundle forKey:kConfigClientIDKey];
+  NSString *serverClientID = [self configValueFromBundle:bundle
+                                                  forKey:kConfigServerClientIDKey];
+  NSString *hostedDomain = [self configValueFromBundle:bundle forKey:kConfigHostedDomainKey];
+  NSString *openIDRealm = [self configValueFromBundle:bundle forKey:kConfigOpenIDRealmKey];
+
+  // If we have at least a client ID, try to construct a configuration.
+  if (clientID) {
+    return [[self alloc] initWithClientID:clientID
+                           serverClientID:serverClientID
+                             hostedDomain:hostedDomain
+                              openIDRealm:openIDRealm];
+  }
+
+  return nil;
+}
+
 // Extend NSObject's default description for easier debugging.
 - (NSString *)description {
   return [NSString stringWithFormat:

+ 1 - 33
GoogleSignIn/Sources/GIDSignIn.m

@@ -458,7 +458,7 @@ static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
 
     // If we have a bundle, try to set the active configuration from the bundle's Info.plist.
     if (bundle) {
-      _configuration = [GIDSignIn configurationFromBundle:bundle];
+      _configuration = [GIDConfiguration configurationFromBundle:bundle];
     }
 
     // Check to see if the 3P app is being run for the first time after a fresh install.
@@ -1019,38 +1019,6 @@ static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
             imageURL:[NSURL URLWithString:idToken.claims[kBasicProfilePictureKey]]];
 }
 
-// Try to retrieve a configuration value from an |NSBundle|'s Info.plist for a given key.
-+ (nullable NSString *)configValueFromBundle:(NSBundle *)bundle forKey:(NSString *)key {
-  NSString *value;
-  id configValue = [bundle objectForInfoDictionaryKey:key];
-  if ([configValue isKindOfClass:[NSString class]]) {
-    value = configValue;
-  }
-  return value;
-}
-
-// Try to generate a |GIDConfiguration| from an |NSBundle|'s Info.plist.
-+ (nullable GIDConfiguration *)configurationFromBundle:(NSBundle *)bundle {
-  GIDConfiguration *configuration;
-
-  // Retrieve any valid config parameters from the bundle's Info.plist.
-  NSString *clientID = [GIDSignIn configValueFromBundle:bundle forKey:kConfigClientIDKey];
-  NSString *serverClientID = [GIDSignIn configValueFromBundle:bundle
-                                                       forKey:kConfigServerClientIDKey];
-  NSString *hostedDomain = [GIDSignIn configValueFromBundle:bundle forKey:kConfigHostedDomainKey];
-  NSString *openIDRealm = [GIDSignIn configValueFromBundle:bundle forKey:kConfigOpenIDRealmKey];
-    
-  // If we have at least a client ID, try to construct a configuration.
-  if (clientID) {
-    configuration = [[GIDConfiguration alloc] initWithClientID:clientID
-                                                 serverClientID:serverClientID
-                                                   hostedDomain:hostedDomain
-                                                    openIDRealm:openIDRealm];
-  }
-  
-  return configuration;
-}
-
 @end
 
 NS_ASSUME_NONNULL_END

+ 5 - 0
GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h

@@ -71,6 +71,11 @@ NS_ASSUME_NONNULL_BEGIN
                     hostedDomain:(nullable NSString *)hostedDomain
                      openIDRealm:(nullable NSString *)openIDRealm NS_DESIGNATED_INITIALIZER;
 
+/// Try to generate a |GIDConfiguration| from an |NSBundle|'s Info.plist.
+///
+/// @param bundle The bundle to generate a configuration value.
++ (nullable instancetype)configurationFromBundle:(NSBundle *)bundle;                     
+
 @end
 
 NS_ASSUME_NONNULL_END