Explorar o código

Merge branch 'refactorGSI' into pin-GIDProfileDataFetcher-new

pinlu %!s(int64=3) %!d(string=hai) anos
pai
achega
4920dfc1ba

+ 12 - 17
GoogleSignIn/Sources/GIDSignIn.m

@@ -76,11 +76,8 @@ NS_ASSUME_NONNULL_BEGIN
 // The name of the query parameter used for logging the restart of auth from EMM callback.
 static NSString *const kEMMRestartAuthParameter = @"emmres";
 
-// The URL template for the authorization endpoint.
-static NSString *const kAuthorizationURLTemplate = @"https://%@/o/oauth2/v2/auth";
-
-// The URL template for the token endpoint.
-static NSString *const kTokenURLTemplate = @"https://%@/token";
+// The URL template for the URL to get user info.
+static NSString *const kUserInfoURLTemplate = @"https://%@/oauth2/v3/userinfo";
 
 // The URL template for the URL to revoke the token.
 static NSString *const kRevokeTokenURLTemplate = @"https://%@/o/oauth2/revoke";
@@ -153,8 +150,7 @@ static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
   // set when a sign-in flow is begun via |signInWithOptions:| when the options passed don't
   // represent a sign in continuation.
   GIDSignInInternalOptions *_currentOptions;
-  // AppAuth configuration object.
-  OIDServiceConfiguration *_appAuthConfiguration;
+  
   // AppAuth external user-agent session state.
   id<OIDExternalUserAgentSession> _currentAuthorizationFlow;
   // Flag to indicate that the auth flow is restarting.
@@ -485,17 +481,10 @@ static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
       [_keychainHandler removeAllKeychainEntries];
     }
 
-    NSString *authorizationEnpointURL = [NSString stringWithFormat:kAuthorizationURLTemplate,
-        [GIDSignInPreferences googleAuthorizationServer]];
-    NSString *tokenEndpointURL = [NSString stringWithFormat:kTokenURLTemplate,
-        [GIDSignInPreferences googleTokenServer]];
-    _appAuthConfiguration = [[OIDServiceConfiguration alloc]
-        initWithAuthorizationEndpoint:[NSURL URLWithString:authorizationEnpointURL]
-                        tokenEndpoint:[NSURL URLWithString:tokenEndpointURL]];
-
 #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
     // Perform migration of auth state from old (before 5.0) versions of the SDK if needed.
-    [GIDAuthStateMigration migrateIfNeededWithTokenURL:_appAuthConfiguration.tokenEndpoint
+    NSURL *tokenEndpointURL = [GIDSignInPreferences tokenEndpointURL];
+    [GIDAuthStateMigration migrateIfNeededWithTokenURL:tokenEndpointURL
                                           callbackPath:kBrowserCallbackPath
                                           keychainName:kGTMAppAuthKeychainName
                                         isFreshInstall:isFreshInstall];
@@ -602,9 +591,15 @@ static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
 #endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
   additionalParameters[kSDKVersionLoggingParameter] = GIDVersion();
   additionalParameters[kEnvironmentLoggingParameter] = GIDEnvironment();
+  
+  NSURL *authorizationEndpointURL = [GIDSignInPreferences authorizationEndpointURL];
+  NSURL *tokenEndpointURL = [GIDSignInPreferences tokenEndpointURL];
+  OIDServiceConfiguration *appAuthConfiguration =
+      [[OIDServiceConfiguration alloc] initWithAuthorizationEndpoint:authorizationEndpointURL
+                                                       tokenEndpoint:tokenEndpointURL];
 
   OIDAuthorizationRequest *request =
-      [[OIDAuthorizationRequest alloc] initWithConfiguration:_appAuthConfiguration
+      [[OIDAuthorizationRequest alloc] initWithConfiguration:appAuthConfiguration
                                                     clientId:options.configuration.clientID
                                                       scopes:options.scopes
                                                  redirectURL:redirectURL

+ 6 - 0
GoogleSignIn/Sources/GIDSignInPreferences.h

@@ -28,9 +28,15 @@ NSString* GIDEnvironment(void);
 @interface GIDSignInPreferences : NSObject
 
 + (NSString *)googleAuthorizationServer;
+
 + (NSString *)googleTokenServer;
+
 + (NSString *)googleUserInfoServer;
 
++ (NSURL *)authorizationEndpointURL;
+
++ (NSURL *)tokenEndpointURL;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 18 - 0
GoogleSignIn/Sources/GIDSignInPreferences.m

@@ -34,6 +34,12 @@ static NSString *const kAppleEnvironmentMacOS = @"macos";
 static NSString *const kAppleEnvironmentMacOSIOSOnMac = @"macos-ios";
 static NSString *const kAppleEnvironmentMacOSMacCatalyst = @"macos-cat";
 
+// The URL template for the authorization endpoint.
+static NSString *const kAuthorizationURLTemplate = @"https://%@/o/oauth2/v2/auth";
+
+// The URL template for the token endpoint.
+static NSString *const kTokenURLTemplate = @"https://%@/token";
+
 #ifndef GID_SDK_VERSION
 #error "GID_SDK_VERSION is not defined: add -DGID_SDK_VERSION=x.x.x to the build invocation."
 #endif
@@ -94,6 +100,18 @@ NSString* GIDEnvironment(void) {
   return kUserInfoServer;
 }
 
++ (NSURL *)authorizationEndpointURL {
+  NSString *authorizationEnpointURL = [NSString stringWithFormat:kAuthorizationURLTemplate,
+      [self googleAuthorizationServer]];
+  return [NSURL URLWithString:authorizationEnpointURL];
+}
+
++ (NSURL *)tokenEndpointURL {
+  NSString *tokenEndpointURL = [NSString stringWithFormat:kTokenURLTemplate,
+      [self googleTokenServer]];
+  return [NSURL URLWithString:tokenEndpointURL];
+}
+
 @end
 
 NS_ASSUME_NONNULL_END