Skip to content

Commit 065077b

Browse files
authored
Move authorizationEndpointURL and tokenEndpointURL into GIDSignInPreferences. (#280)
1 parent 9187484 commit 065077b

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

GoogleSignIn/Sources/GIDSignIn.m

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@
7474
// The name of the query parameter used for logging the restart of auth from EMM callback.
7575
static NSString *const kEMMRestartAuthParameter = @"emmres";
7676

77-
// The URL template for the authorization endpoint.
78-
static NSString *const kAuthorizationURLTemplate = @"https://%@/o/oauth2/v2/auth";
79-
80-
// The URL template for the token endpoint.
81-
static NSString *const kTokenURLTemplate = @"https://%@/token";
82-
8377
// The URL template for the URL to get user info.
8478
static NSString *const kUserInfoURLTemplate = @"https://%@/oauth2/v3/userinfo";
8579

@@ -161,8 +155,7 @@ @implementation GIDSignIn {
161155
// set when a sign-in flow is begun via |signInWithOptions:| when the options passed don't
162156
// represent a sign in continuation.
163157
GIDSignInInternalOptions *_currentOptions;
164-
// AppAuth configuration object.
165-
OIDServiceConfiguration *_appAuthConfiguration;
158+
166159
// AppAuth external user-agent session state.
167160
id<OIDExternalUserAgentSession> _currentAuthorizationFlow;
168161
// Flag to indicate that the auth flow is restarting.
@@ -467,7 +460,7 @@ - (id)initPrivate {
467460
}
468461

469462
- (instancetype)initWithKeychainHandler:(id<GIDKeychainHandler>)keychainHandler
470-
httpFetcher:(id<GIDHTTPFetcher>)httpFetcher{
463+
httpFetcher:(id<GIDHTTPFetcher>)httpFetcher {
471464
self = [super init];
472465
if (self) {
473466
// Get the bundle of the current executable.
@@ -486,17 +479,10 @@ - (instancetype)initWithKeychainHandler:(id<GIDKeychainHandler>)keychainHandler
486479
[_keychainHandler removeAllKeychainEntries];
487480
}
488481

489-
NSString *authorizationEnpointURL = [NSString stringWithFormat:kAuthorizationURLTemplate,
490-
[GIDSignInPreferences googleAuthorizationServer]];
491-
NSString *tokenEndpointURL = [NSString stringWithFormat:kTokenURLTemplate,
492-
[GIDSignInPreferences googleTokenServer]];
493-
_appAuthConfiguration = [[OIDServiceConfiguration alloc]
494-
initWithAuthorizationEndpoint:[NSURL URLWithString:authorizationEnpointURL]
495-
tokenEndpoint:[NSURL URLWithString:tokenEndpointURL]];
496-
497482
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
498483
// Perform migration of auth state from old (before 5.0) versions of the SDK if needed.
499-
[GIDAuthStateMigration migrateIfNeededWithTokenURL:_appAuthConfiguration.tokenEndpoint
484+
NSURL *tokenEndpointURL = [GIDSignInPreferences tokenEndpointURL];
485+
[GIDAuthStateMigration migrateIfNeededWithTokenURL:tokenEndpointURL
500486
callbackPath:kBrowserCallbackPath
501487
keychainName:kGTMAppAuthKeychainName
502488
isFreshInstall:isFreshInstall];
@@ -602,9 +588,15 @@ - (void)authenticateInteractivelyWithOptions:(GIDSignInInternalOptions *)options
602588
#endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
603589
additionalParameters[kSDKVersionLoggingParameter] = GIDVersion();
604590
additionalParameters[kEnvironmentLoggingParameter] = GIDEnvironment();
591+
592+
NSURL *authorizationEndpointURL = [GIDSignInPreferences authorizationEndpointURL];
593+
NSURL *tokenEndpointURL = [GIDSignInPreferences tokenEndpointURL];
594+
OIDServiceConfiguration *appAuthConfiguration =
595+
[[OIDServiceConfiguration alloc] initWithAuthorizationEndpoint:authorizationEndpointURL
596+
tokenEndpoint:tokenEndpointURL];
605597

606598
OIDAuthorizationRequest *request =
607-
[[OIDAuthorizationRequest alloc] initWithConfiguration:_appAuthConfiguration
599+
[[OIDAuthorizationRequest alloc] initWithConfiguration:appAuthConfiguration
608600
clientId:options.configuration.clientID
609601
scopes:options.scopes
610602
redirectURL:redirectURL

GoogleSignIn/Sources/GIDSignInPreferences.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ NSString* GIDEnvironment(void);
2828
@interface GIDSignInPreferences : NSObject
2929

3030
+ (NSString *)googleAuthorizationServer;
31+
3132
+ (NSString *)googleTokenServer;
33+
3234
+ (NSString *)googleUserInfoServer;
3335

36+
+ (NSURL *)authorizationEndpointURL;
37+
38+
+ (NSURL *)tokenEndpointURL;
39+
3440
@end
3541

3642
NS_ASSUME_NONNULL_END

GoogleSignIn/Sources/GIDSignInPreferences.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
static NSString *const kAppleEnvironmentMacOSIOSOnMac = @"macos-ios";
3535
static NSString *const kAppleEnvironmentMacOSMacCatalyst = @"macos-cat";
3636

37+
// The URL template for the authorization endpoint.
38+
static NSString *const kAuthorizationURLTemplate = @"https://%@/o/oauth2/v2/auth";
39+
40+
// The URL template for the token endpoint.
41+
static NSString *const kTokenURLTemplate = @"https://%@/token";
42+
3743
#ifndef GID_SDK_VERSION
3844
#error "GID_SDK_VERSION is not defined: add -DGID_SDK_VERSION=x.x.x to the build invocation."
3945
#endif
@@ -94,6 +100,18 @@ + (NSString *)googleUserInfoServer {
94100
return kUserInfoServer;
95101
}
96102

103+
+ (NSURL *)authorizationEndpointURL {
104+
NSString *authorizationEnpointURL = [NSString stringWithFormat:kAuthorizationURLTemplate,
105+
[self googleAuthorizationServer]];
106+
return [NSURL URLWithString:authorizationEnpointURL];
107+
}
108+
109+
+ (NSURL *)tokenEndpointURL {
110+
NSString *tokenEndpointURL = [NSString stringWithFormat:kTokenURLTemplate,
111+
[self googleTokenServer]];
112+
return [NSURL URLWithString:tokenEndpointURL];
113+
}
114+
97115
@end
98116

99117
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)