GIDSignIn.m 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h"
  15. #import "GoogleSignIn/Sources/GIDSignIn_Private.h"
  16. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
  17. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDGoogleUser.h"
  18. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDProfileData.h"
  19. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDUserAuth.h"
  20. #import "GoogleSignIn/Sources/GIDEMMSupport.h"
  21. #import "GoogleSignIn/Sources/GIDKeychainHandler/API/GIDKeychainHandler.h"
  22. #import "GoogleSignIn/Sources/GIDKeychainHandler/Implementations/GIDKeychainHandler.h"
  23. #import "GoogleSignIn/Sources/GIDSignInInternalOptions.h"
  24. #import "GoogleSignIn/Sources/GIDSignInPreferences.h"
  25. #import "GoogleSignIn/Sources/GIDCallbackQueue.h"
  26. #import "GoogleSignIn/Sources/GIDScopes.h"
  27. #import "GoogleSignIn/Sources/GIDSignInCallbackSchemes.h"
  28. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  29. #import "GoogleSignIn/Sources/GIDAuthStateMigration.h"
  30. #import "GoogleSignIn/Sources/GIDEMMErrorHandler.h"
  31. #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  32. #import "GoogleSignIn/Sources/GIDGoogleUser_Private.h"
  33. #import "GoogleSignIn/Sources/GIDProfileData_Private.h"
  34. #import "GoogleSignIn/Sources/GIDUserAuth_Private.h"
  35. #ifdef SWIFT_PACKAGE
  36. @import AppAuth;
  37. @import GTMAppAuth;
  38. @import GTMSessionFetcherCore;
  39. #else
  40. #import <AppAuth/OIDAuthState.h>
  41. #import <AppAuth/OIDAuthorizationRequest.h>
  42. #import <AppAuth/OIDAuthorizationResponse.h>
  43. #import <AppAuth/OIDAuthorizationService.h>
  44. #import <AppAuth/OIDError.h>
  45. #import <AppAuth/OIDExternalUserAgentSession.h>
  46. #import <AppAuth/OIDIDToken.h>
  47. #import <AppAuth/OIDResponseTypes.h>
  48. #import <AppAuth/OIDServiceConfiguration.h>
  49. #import <AppAuth/OIDTokenRequest.h>
  50. #import <AppAuth/OIDTokenResponse.h>
  51. #import <AppAuth/OIDURLQueryComponent.h>
  52. #import <GTMAppAuth/GTMAppAuthFetcherAuthorization+Keychain.h>
  53. #import <GTMAppAuth/GTMAppAuthFetcherAuthorization.h>
  54. #import <GTMSessionFetcher/GTMSessionFetcher.h>
  55. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  56. #import <AppAuth/OIDAuthorizationService+IOS.h>
  57. #elif TARGET_OS_OSX
  58. #import <AppAuth/OIDAuthorizationService+Mac.h>
  59. #endif
  60. #endif
  61. NS_ASSUME_NONNULL_BEGIN
  62. // The name of the query parameter used for logging the restart of auth from EMM callback.
  63. static NSString *const kEMMRestartAuthParameter = @"emmres";
  64. // The URL template for the authorization endpoint.
  65. static NSString *const kAuthorizationURLTemplate = @"https://%@/o/oauth2/v2/auth";
  66. // The URL template for the token endpoint.
  67. static NSString *const kTokenURLTemplate = @"https://%@/token";
  68. // The URL template for the URL to get user info.
  69. static NSString *const kUserInfoURLTemplate = @"https://%@/oauth2/v3/userinfo?access_token=%@";
  70. // The URL template for the URL to revoke the token.
  71. static NSString *const kRevokeTokenURLTemplate = @"https://%@/o/oauth2/revoke?token=%@";
  72. // Expected path in the URL scheme to be handled.
  73. static NSString *const kBrowserCallbackPath = @"/oauth2callback";
  74. // Expected path for EMM callback.
  75. static NSString *const kEMMCallbackPath = @"/emmcallback";
  76. // The EMM support version
  77. static NSString *const kEMMVersion = @"1";
  78. // The error code for Google Identity.
  79. NSErrorDomain const kGIDSignInErrorDomain = @"com.google.GIDSignIn";
  80. // Keychain constants for saving state in the authentication flow.
  81. static NSString *const kGTMAppAuthKeychainName = @"auth";
  82. // Basic profile (Fat ID Token / userinfo endpoint) keys
  83. static NSString *const kBasicProfileEmailKey = @"email";
  84. static NSString *const kBasicProfilePictureKey = @"picture";
  85. static NSString *const kBasicProfileNameKey = @"name";
  86. static NSString *const kBasicProfileGivenNameKey = @"given_name";
  87. static NSString *const kBasicProfileFamilyNameKey = @"family_name";
  88. // Parameters in the callback URL coming back from browser.
  89. static NSString *const kAuthorizationCodeKeyName = @"code";
  90. static NSString *const kOAuth2ErrorKeyName = @"error";
  91. static NSString *const kOAuth2AccessDenied = @"access_denied";
  92. static NSString *const kEMMPasscodeInfoRequiredKeyName = @"emm_passcode_info_required";
  93. // Error string for unavailable keychain.
  94. static NSString *const kKeychainError = @"keychain error";
  95. // Error string for user cancelations.
  96. static NSString *const kUserCanceledError = @"The user canceled the sign-in flow.";
  97. // User preference key to detect fresh install of the app.
  98. static NSString *const kAppHasRunBeforeKey = @"GID_AppHasRunBefore";
  99. // Maximum retry interval in seconds for the fetcher.
  100. static const NSTimeInterval kFetcherMaxRetryInterval = 15.0;
  101. // The delay before the new sign-in flow can be presented after the existing one is cancelled.
  102. static const NSTimeInterval kPresentationDelayAfterCancel = 1.0;
  103. // Parameters for the auth and token exchange endpoints.
  104. static NSString *const kAudienceParameter = @"audience";
  105. // See b/11669751 .
  106. static NSString *const kOpenIDRealmParameter = @"openid.realm";
  107. static NSString *const kIncludeGrantedScopesParameter = @"include_granted_scopes";
  108. static NSString *const kLoginHintParameter = @"login_hint";
  109. static NSString *const kHostedDomainParameter = @"hd";
  110. // Minimum time to expiration for a restored access token.
  111. static const NSTimeInterval kMinimumRestoredAccessTokenTimeToExpire = 600.0;
  112. // Info.plist config keys
  113. static NSString *const kConfigClientIDKey = @"GIDClientID";
  114. static NSString *const kConfigServerClientIDKey = @"GIDServerClientID";
  115. static NSString *const kConfigHostedDomainKey = @"GIDHostedDomain";
  116. static NSString *const kConfigOpenIDRealmKey = @"GIDOpenIDRealm";
  117. // The callback queue used for authentication flow.
  118. @interface GIDAuthFlow : GIDCallbackQueue
  119. @property(nonatomic, strong, nullable) OIDAuthState *authState;
  120. @property(nonatomic, strong, nullable) NSError *error;
  121. @property(nonatomic, copy, nullable) NSString *emmSupport;
  122. @property(nonatomic, nullable) GIDProfileData *profileData;
  123. @end
  124. @implementation GIDAuthFlow
  125. @end
  126. @implementation GIDSignIn {
  127. // This value is used when sign-in flows are resumed via the handling of a URL. Its value is
  128. // set when a sign-in flow is begun via |signInWithOptions:| when the options passed don't
  129. // represent a sign in continuation.
  130. GIDSignInInternalOptions *_currentOptions;
  131. // AppAuth configuration object.
  132. OIDServiceConfiguration *_appAuthConfiguration;
  133. // AppAuth external user-agent session state.
  134. id<OIDExternalUserAgentSession> _currentAuthorizationFlow;
  135. // Flag to indicate that the auth flow is restarting.
  136. BOOL _restarting;
  137. id<GIDKeychainHandler> _keychainHandler;
  138. }
  139. #pragma mark - Public methods
  140. // Handles the custom scheme URL opened by SFSafariViewController or the Device Policy App.
  141. //
  142. // For SFSafariViewController invoked via AppAuth, this method is used on iOS 10.
  143. // For the Device Policy App (EMM flow) this method is used on all iOS versions.
  144. - (BOOL)handleURL:(NSURL *)url {
  145. // Check if the callback path matches the expected one for a URL from Safari/Chrome/SafariVC.
  146. if ([url.path isEqual:kBrowserCallbackPath]) {
  147. if ([_currentAuthorizationFlow resumeExternalUserAgentFlowWithURL:url]) {
  148. _currentAuthorizationFlow = nil;
  149. return YES;
  150. }
  151. return NO;
  152. }
  153. // Check if the callback path matches the expected one for a URL from Google Device Policy app.
  154. if ([url.path isEqual:kEMMCallbackPath]) {
  155. return [self handleDevicePolicyAppURL:url];
  156. }
  157. return NO;
  158. }
  159. - (BOOL)hasPreviousSignIn {
  160. if ([_currentUser.authState isAuthorized]) {
  161. return YES;
  162. }
  163. OIDAuthState *authState = [_keychainHandler loadAuthState];
  164. return [authState isAuthorized];
  165. }
  166. - (void)restorePreviousSignInWithCompletion:(nullable void (^)(GIDGoogleUser *_Nullable user,
  167. NSError *_Nullable error))completion {
  168. [self signInWithOptions:[GIDSignInInternalOptions silentOptionsWithCompletion:
  169. ^(GIDUserAuth *userAuth, NSError *error) {
  170. if (userAuth) {
  171. completion(userAuth.user, nil);
  172. } else {
  173. completion(nil, error);
  174. }
  175. }]];
  176. }
  177. - (BOOL)restorePreviousSignInNoRefresh {
  178. if (_currentUser) {
  179. return YES;
  180. }
  181. // Try retrieving an authorization object from the keychain.
  182. OIDAuthState *authState = [_keychainHandler loadAuthState];
  183. if (!authState) {
  184. return NO;
  185. }
  186. // Restore current user without refreshing the access token.
  187. OIDIDToken *idToken =
  188. [[OIDIDToken alloc] initWithIDTokenString:authState.lastTokenResponse.idToken];
  189. GIDProfileData *profileData = [self profileDataWithIDToken:idToken];
  190. GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:authState profileData:profileData];
  191. self.currentUser = user;
  192. return YES;
  193. }
  194. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  195. - (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
  196. hint:(nullable NSString *)hint
  197. completion:(nullable GIDUserAuthCompletion)completion {
  198. GIDSignInInternalOptions *options =
  199. [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
  200. presentingViewController:presentingViewController
  201. loginHint:hint
  202. addScopesFlow:NO
  203. completion:completion];
  204. [self signInWithOptions:options];
  205. }
  206. - (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
  207. hint:(nullable NSString *)hint
  208. additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
  209. completion:(nullable GIDUserAuthCompletion)completion {
  210. GIDSignInInternalOptions *options =
  211. [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
  212. presentingViewController:presentingViewController
  213. loginHint:hint
  214. addScopesFlow:NO
  215. scopes:additionalScopes
  216. completion:completion];
  217. [self signInWithOptions:options];
  218. }
  219. - (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
  220. completion:(nullable GIDUserAuthCompletion)completion {
  221. [self signInWithPresentingViewController:presentingViewController
  222. hint:nil
  223. completion:completion];
  224. }
  225. - (void)addScopes:(NSArray<NSString *> *)scopes
  226. presentingViewController:(UIViewController *)presentingViewController
  227. completion:(nullable GIDUserAuthCompletion)completion {
  228. GIDConfiguration *configuration = self.currentUser.configuration;
  229. GIDSignInInternalOptions *options =
  230. [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
  231. presentingViewController:presentingViewController
  232. loginHint:self.currentUser.profile.email
  233. addScopesFlow:YES
  234. completion:completion];
  235. NSSet<NSString *> *requestedScopes = [NSSet setWithArray:scopes];
  236. NSMutableSet<NSString *> *grantedScopes =
  237. [NSMutableSet setWithArray:self.currentUser.grantedScopes];
  238. // Check to see if all requested scopes have already been granted.
  239. if ([requestedScopes isSubsetOfSet:grantedScopes]) {
  240. // All requested scopes have already been granted, notify callback of failure.
  241. NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
  242. code:kGIDSignInErrorCodeScopesAlreadyGranted
  243. userInfo:nil];
  244. if (completion) {
  245. dispatch_async(dispatch_get_main_queue(), ^{
  246. completion(nil, error);
  247. });
  248. }
  249. return;
  250. }
  251. // Use the union of granted and requested scopes.
  252. [grantedScopes unionSet:requestedScopes];
  253. options.scopes = [grantedScopes allObjects];
  254. [self signInWithOptions:options];
  255. }
  256. #elif TARGET_OS_OSX
  257. - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
  258. hint:(nullable NSString *)hint
  259. completion:(nullable GIDUserAuthCompletion)completion {
  260. GIDSignInInternalOptions *options =
  261. [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
  262. presentingWindow:presentingWindow
  263. loginHint:hint
  264. addScopesFlow:NO
  265. completion:completion];
  266. [self signInWithOptions:options];
  267. }
  268. - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
  269. completion:(nullable GIDUserAuthCompletion)completion {
  270. [self signInWithPresentingWindow:presentingWindow
  271. hint:nil
  272. completion:completion];
  273. }
  274. - (void)signInWithPresentingWindow:(NSWindow *)presentingWindow
  275. hint:(nullable NSString *)hint
  276. additionalScopes:(nullable NSArray<NSString *> *)additionalScopes
  277. completion:(nullable GIDUserAuthCompletion)completion {
  278. GIDSignInInternalOptions *options =
  279. [GIDSignInInternalOptions defaultOptionsWithConfiguration:_configuration
  280. presentingWindow:presentingWindow
  281. loginHint:hint
  282. addScopesFlow:NO
  283. scopes:additionalScopes
  284. completion:completion];
  285. [self signInWithOptions:options];
  286. }
  287. - (void)addScopes:(NSArray<NSString *> *)scopes
  288. presentingWindow:(NSWindow *)presentingWindow
  289. completion:(nullable GIDUserAuthCompletion)completion {
  290. GIDConfiguration *configuration = self.currentUser.configuration;
  291. GIDSignInInternalOptions *options =
  292. [GIDSignInInternalOptions defaultOptionsWithConfiguration:configuration
  293. presentingWindow:presentingWindow
  294. loginHint:self.currentUser.profile.email
  295. addScopesFlow:YES
  296. completion:completion];
  297. NSSet<NSString *> *requestedScopes = [NSSet setWithArray:scopes];
  298. NSMutableSet<NSString *> *grantedScopes =
  299. [NSMutableSet setWithArray:self.currentUser.grantedScopes];
  300. // Check to see if all requested scopes have already been granted.
  301. if ([requestedScopes isSubsetOfSet:grantedScopes]) {
  302. // All requested scopes have already been granted, notify callback of failure.
  303. NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
  304. code:kGIDSignInErrorCodeScopesAlreadyGranted
  305. userInfo:nil];
  306. if (completion) {
  307. dispatch_async(dispatch_get_main_queue(), ^{
  308. completion(nil, error);
  309. });
  310. }
  311. return;
  312. }
  313. // Use the union of granted and requested scopes.
  314. [grantedScopes unionSet:requestedScopes];
  315. options.scopes = [grantedScopes allObjects];
  316. [self signInWithOptions:options];
  317. }
  318. #endif // TARGET_OS_OSX
  319. - (void)signOut {
  320. // Clear the current user if there is one.
  321. if (_currentUser) {
  322. self.currentUser = nil;
  323. }
  324. // Remove all state from the keychain.
  325. [_keychainHandler removeAllKeychainEntries];
  326. }
  327. - (void)disconnectWithCompletion:(nullable GIDDisconnectCompletion)completion {
  328. OIDAuthState *authState = _currentUser.authState;
  329. if (!authState) {
  330. // Even the user is not signed in right now, we still need to remove any token saved in the
  331. // keychain.
  332. authState = [_keychainHandler loadAuthState];
  333. }
  334. // Either access or refresh token would work, but we won't have access token if the auth is
  335. // retrieved from keychain.
  336. NSString *token = authState.lastTokenResponse.accessToken;
  337. if (!token) {
  338. token = authState.lastTokenResponse.refreshToken;
  339. }
  340. if (!token) {
  341. [self signOut];
  342. // Nothing to do here, consider the operation successful.
  343. if (completion) {
  344. dispatch_async(dispatch_get_main_queue(), ^{
  345. completion(nil);
  346. });
  347. }
  348. return;
  349. }
  350. NSString *revokeURLString = [NSString stringWithFormat:kRevokeTokenURLTemplate,
  351. [GIDSignInPreferences googleAuthorizationServer], token];
  352. // Append logging parameter
  353. revokeURLString = [NSString stringWithFormat:@"%@&%@=%@&%@=%@",
  354. revokeURLString,
  355. kSDKVersionLoggingParameter,
  356. GIDVersion(),
  357. kEnvironmentLoggingParameter,
  358. GIDEnvironment()];
  359. NSURL *revokeURL = [NSURL URLWithString:revokeURLString];
  360. [self startFetchURL:revokeURL
  361. fromAuthState:authState
  362. withComment:@"GIDSignIn: revoke tokens"
  363. withCompletionHandler:^(NSData *data, NSError *error) {
  364. // Revoking an already revoked token seems always successful, which helps us here.
  365. if (!error) {
  366. [self signOut];
  367. }
  368. if (completion) {
  369. dispatch_async(dispatch_get_main_queue(), ^{
  370. completion(error);
  371. });
  372. }
  373. }];
  374. }
  375. #pragma mark - Custom getters and setters
  376. + (GIDSignIn *)sharedInstance {
  377. static dispatch_once_t once;
  378. static GIDSignIn *sharedInstance;
  379. dispatch_once(&once, ^{
  380. sharedInstance = [[self alloc] initPrivate];
  381. });
  382. return sharedInstance;
  383. }
  384. #pragma mark - Private methods
  385. - (id)initPrivate {
  386. GIDKeychainHandler *keychainHandler = [[GIDKeychainHandler alloc] init];
  387. return [self initWithKeychainHandler:keychainHandler];
  388. }
  389. - (instancetype)initWithKeychainHandler:(id<GIDKeychainHandler>)keychainHandler {
  390. self = [super init];
  391. if (self) {
  392. // Get the bundle of the current executable.
  393. NSBundle *bundle = NSBundle.mainBundle;
  394. // If we have a bundle, try to set the active configuration from the bundle's Info.plist.
  395. if (bundle) {
  396. _configuration = [GIDSignIn configurationFromBundle:bundle];
  397. }
  398. // Check to see if the 3P app is being run for the first time after a fresh install.
  399. BOOL isFreshInstall = [self isFreshInstall];
  400. // If this is a fresh install, ensure that any pre-existing keychain data is purged.
  401. if (isFreshInstall) {
  402. [_keychainHandler removeAllKeychainEntries];
  403. }
  404. NSString *authorizationEnpointURL = [NSString stringWithFormat:kAuthorizationURLTemplate,
  405. [GIDSignInPreferences googleAuthorizationServer]];
  406. NSString *tokenEndpointURL = [NSString stringWithFormat:kTokenURLTemplate,
  407. [GIDSignInPreferences googleTokenServer]];
  408. _appAuthConfiguration = [[OIDServiceConfiguration alloc]
  409. initWithAuthorizationEndpoint:[NSURL URLWithString:authorizationEnpointURL]
  410. tokenEndpoint:[NSURL URLWithString:tokenEndpointURL]];
  411. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  412. // Perform migration of auth state from old (before 5.0) versions of the SDK if needed.
  413. [GIDAuthStateMigration migrateIfNeededWithTokenURL:_appAuthConfiguration.tokenEndpoint
  414. callbackPath:kBrowserCallbackPath
  415. keychainName:kGTMAppAuthKeychainName
  416. isFreshInstall:isFreshInstall];
  417. #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  418. _keychainHandler = keychainHandler;
  419. }
  420. return self;
  421. }
  422. // Does sanity check for parameters and then authenticates if necessary.
  423. - (void)signInWithOptions:(GIDSignInInternalOptions *)options {
  424. // Options for continuation are not the options we want to cache. The purpose of caching the
  425. // options in the first place is to provide continuation flows with a starting place from which to
  426. // derive suitable options for the continuation!
  427. if (!options.continuation) {
  428. _currentOptions = options;
  429. }
  430. if (options.interactive) {
  431. // Ensure that a configuration has been provided.
  432. if (!_configuration) {
  433. // NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
  434. [NSException raise:NSInvalidArgumentException
  435. format:@"No active configuration. Make sure GIDClientID is set in Info.plist."];
  436. return;
  437. }
  438. // Explicitly throw exception for missing client ID here. This must come before
  439. // scheme check because schemes rely on reverse client IDs.
  440. [self assertValidParameters];
  441. [self assertValidPresentingViewController];
  442. // If the application does not support the required URL schemes tell the developer so.
  443. GIDSignInCallbackSchemes *schemes =
  444. [[GIDSignInCallbackSchemes alloc] initWithClientIdentifier:options.configuration.clientID];
  445. NSArray<NSString *> *unsupportedSchemes = [schemes unsupportedSchemes];
  446. if (unsupportedSchemes.count != 0) {
  447. // NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
  448. [NSException raise:NSInvalidArgumentException
  449. format:@"Your app is missing support for the following URL schemes: %@",
  450. [unsupportedSchemes componentsJoinedByString:@", "]];
  451. }
  452. }
  453. // If this is a non-interactive flow, use cached authentication if possible.
  454. if (!options.interactive && _currentUser) {
  455. [_currentUser refreshTokensIfNeededWithCompletion:^(GIDGoogleUser *unused, NSError *error) {
  456. if (error) {
  457. [self authenticateWithOptions:options];
  458. } else {
  459. if (options.completion) {
  460. self->_currentOptions = nil;
  461. dispatch_async(dispatch_get_main_queue(), ^{
  462. GIDUserAuth *userAuth = [[GIDUserAuth alloc] initWithGoogleUser:self->_currentUser serverAuthCode:nil];
  463. options.completion(userAuth, nil);
  464. });
  465. }
  466. }
  467. }];
  468. } else {
  469. [self authenticateWithOptions:options];
  470. }
  471. }
  472. #pragma mark - Authentication flow
  473. - (void)authenticateInteractivelyWithOptions:(GIDSignInInternalOptions *)options {
  474. GIDSignInCallbackSchemes *schemes =
  475. [[GIDSignInCallbackSchemes alloc] initWithClientIdentifier:options.configuration.clientID];
  476. NSURL *redirectURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@:%@",
  477. [schemes clientIdentifierScheme],
  478. kBrowserCallbackPath]];
  479. NSString *emmSupport;
  480. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  481. emmSupport = [[self class] isOperatingSystemAtLeast9] ? kEMMVersion : nil;
  482. #elif TARGET_OS_MACCATALYST || TARGET_OS_OSX
  483. emmSupport = nil;
  484. #endif // TARGET_OS_MACCATALYST || TARGET_OS_OSX
  485. NSMutableDictionary<NSString *, NSString *> *additionalParameters = [@{} mutableCopy];
  486. additionalParameters[kIncludeGrantedScopesParameter] = @"true";
  487. if (options.configuration.serverClientID) {
  488. additionalParameters[kAudienceParameter] = options.configuration.serverClientID;
  489. }
  490. if (options.loginHint) {
  491. additionalParameters[kLoginHintParameter] = options.loginHint;
  492. }
  493. if (options.configuration.hostedDomain) {
  494. additionalParameters[kHostedDomainParameter] = options.configuration.hostedDomain;
  495. }
  496. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  497. [additionalParameters addEntriesFromDictionary:
  498. [GIDEMMSupport parametersWithParameters:options.extraParams
  499. emmSupport:emmSupport
  500. isPasscodeInfoRequired:NO]];
  501. #elif TARGET_OS_OSX || TARGET_OS_MACCATALYST
  502. [additionalParameters addEntriesFromDictionary:options.extraParams];
  503. #endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
  504. additionalParameters[kSDKVersionLoggingParameter] = GIDVersion();
  505. additionalParameters[kEnvironmentLoggingParameter] = GIDEnvironment();
  506. OIDAuthorizationRequest *request =
  507. [[OIDAuthorizationRequest alloc] initWithConfiguration:_appAuthConfiguration
  508. clientId:options.configuration.clientID
  509. scopes:options.scopes
  510. redirectURL:redirectURL
  511. responseType:OIDResponseTypeCode
  512. additionalParameters:additionalParameters];
  513. _currentAuthorizationFlow = [OIDAuthorizationService
  514. presentAuthorizationRequest:request
  515. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  516. presentingViewController:options.presentingViewController
  517. #elif TARGET_OS_OSX
  518. presentingWindow:options.presentingWindow
  519. #endif // TARGET_OS_OSX
  520. callback:^(OIDAuthorizationResponse *_Nullable authorizationResponse,
  521. NSError *_Nullable error) {
  522. [self processAuthorizationResponse:authorizationResponse
  523. error:error
  524. emmSupport:emmSupport];
  525. }];
  526. }
  527. - (void)processAuthorizationResponse:(OIDAuthorizationResponse *)authorizationResponse
  528. error:(NSError *)error
  529. emmSupport:(NSString *)emmSupport{
  530. if (_restarting) {
  531. // The auth flow is restarting, so the work here would be performed in the next round.
  532. _restarting = NO;
  533. return;
  534. }
  535. GIDAuthFlow *authFlow = [[GIDAuthFlow alloc] init];
  536. authFlow.emmSupport = emmSupport;
  537. if (authorizationResponse) {
  538. if (authorizationResponse.authorizationCode.length) {
  539. authFlow.authState = [[OIDAuthState alloc]
  540. initWithAuthorizationResponse:authorizationResponse];
  541. // perform auth code exchange
  542. [self maybeFetchToken:authFlow];
  543. } else {
  544. // There was a failure, convert to appropriate error code.
  545. NSString *errorString;
  546. GIDSignInErrorCode errorCode = kGIDSignInErrorCodeUnknown;
  547. NSDictionary<NSString *, NSObject *> *params = authorizationResponse.additionalParameters;
  548. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  549. if (authFlow.emmSupport) {
  550. [authFlow wait];
  551. BOOL isEMMError = [[GIDEMMErrorHandler sharedInstance]
  552. handleErrorFromResponse:params
  553. completion:^{
  554. [authFlow next];
  555. }];
  556. if (isEMMError) {
  557. errorCode = kGIDSignInErrorCodeEMM;
  558. }
  559. }
  560. #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  561. errorString = (NSString *)params[kOAuth2ErrorKeyName];
  562. if ([errorString isEqualToString:kOAuth2AccessDenied]) {
  563. errorCode = kGIDSignInErrorCodeCanceled;
  564. }
  565. authFlow.error = [self errorWithString:errorString code:errorCode];
  566. }
  567. } else {
  568. NSString *errorString = [error localizedDescription];
  569. GIDSignInErrorCode errorCode = kGIDSignInErrorCodeUnknown;
  570. if (error.code == OIDErrorCodeUserCanceledAuthorizationFlow) {
  571. // The user has canceled the flow at the iOS modal dialog.
  572. errorString = kUserCanceledError;
  573. errorCode = kGIDSignInErrorCodeCanceled;
  574. }
  575. authFlow.error = [self errorWithString:errorString code:errorCode];
  576. }
  577. [self addDecodeIdTokenCallback:authFlow];
  578. [self addSaveAuthCallback:authFlow];
  579. [self addCompletionCallback:authFlow];
  580. }
  581. // Perform authentication with the provided options.
  582. - (void)authenticateWithOptions:(GIDSignInInternalOptions *)options {
  583. // If this is an interactive flow, we're not going to try to restore any saved auth state.
  584. if (options.interactive) {
  585. [self authenticateInteractivelyWithOptions:options];
  586. return;
  587. }
  588. // Try retrieving an authorization object from the keychain.
  589. OIDAuthState *authState = [_keychainHandler loadAuthState];
  590. if (![authState isAuthorized]) {
  591. // No valid auth in keychain, per documentation/spec, notify callback of failure.
  592. NSError *error = [NSError errorWithDomain:kGIDSignInErrorDomain
  593. code:kGIDSignInErrorCodeHasNoAuthInKeychain
  594. userInfo:nil];
  595. if (options.completion) {
  596. _currentOptions = nil;
  597. dispatch_async(dispatch_get_main_queue(), ^{
  598. options.completion(nil, error);
  599. });
  600. }
  601. return;
  602. }
  603. // Complete the auth flow using saved auth in keychain.
  604. GIDAuthFlow *authFlow = [[GIDAuthFlow alloc] init];
  605. authFlow.authState = authState;
  606. [self maybeFetchToken:authFlow];
  607. [self addDecodeIdTokenCallback:authFlow];
  608. [self addSaveAuthCallback:authFlow];
  609. [self addCompletionCallback:authFlow];
  610. }
  611. // Fetches the access token if necessary as part of the auth flow.
  612. - (void)maybeFetchToken:(GIDAuthFlow *)authFlow {
  613. OIDAuthState *authState = authFlow.authState;
  614. // Do nothing if we have an auth flow error or a restored access token that isn't near expiration.
  615. if (authFlow.error ||
  616. (authState.lastTokenResponse.accessToken &&
  617. [authState.lastTokenResponse.accessTokenExpirationDate timeIntervalSinceNow] >
  618. kMinimumRestoredAccessTokenTimeToExpire)) {
  619. return;
  620. }
  621. NSMutableDictionary<NSString *, NSString *> *additionalParameters = [@{} mutableCopy];
  622. if (_currentOptions.configuration.serverClientID) {
  623. additionalParameters[kAudienceParameter] = _currentOptions.configuration.serverClientID;
  624. }
  625. if (_currentOptions.configuration.openIDRealm) {
  626. additionalParameters[kOpenIDRealmParameter] = _currentOptions.configuration.openIDRealm;
  627. }
  628. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  629. NSDictionary<NSString *, NSObject *> *params =
  630. authState.lastAuthorizationResponse.additionalParameters;
  631. NSString *passcodeInfoRequired = (NSString *)params[kEMMPasscodeInfoRequiredKeyName];
  632. [additionalParameters addEntriesFromDictionary:
  633. [GIDEMMSupport parametersWithParameters:@{}
  634. emmSupport:authFlow.emmSupport
  635. isPasscodeInfoRequired:passcodeInfoRequired.length > 0]];
  636. #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  637. additionalParameters[kSDKVersionLoggingParameter] = GIDVersion();
  638. additionalParameters[kEnvironmentLoggingParameter] = GIDEnvironment();
  639. OIDTokenRequest *tokenRequest;
  640. if (!authState.lastTokenResponse.accessToken &&
  641. authState.lastAuthorizationResponse.authorizationCode) {
  642. tokenRequest = [authState.lastAuthorizationResponse
  643. tokenExchangeRequestWithAdditionalParameters:additionalParameters];
  644. } else {
  645. [additionalParameters
  646. addEntriesFromDictionary:authState.lastTokenResponse.request.additionalParameters];
  647. tokenRequest = [authState tokenRefreshRequestWithAdditionalParameters:additionalParameters];
  648. }
  649. [authFlow wait];
  650. [OIDAuthorizationService
  651. performTokenRequest:tokenRequest
  652. callback:^(OIDTokenResponse *_Nullable tokenResponse,
  653. NSError *_Nullable error) {
  654. [authState updateWithTokenResponse:tokenResponse error:error];
  655. authFlow.error = error;
  656. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  657. if (authFlow.emmSupport) {
  658. [GIDEMMSupport handleTokenFetchEMMError:error completion:^(NSError *error) {
  659. authFlow.error = error;
  660. [authFlow next];
  661. }];
  662. } else {
  663. [authFlow next];
  664. }
  665. #elif TARGET_OS_OSX || TARGET_OS_MACCATALYST
  666. [authFlow next];
  667. #endif // TARGET_OS_OSX || TARGET_OS_MACCATALYST
  668. }];
  669. }
  670. // Adds a callback to the auth flow to save the auth object to |self| and the keychain as well.
  671. - (void)addSaveAuthCallback:(GIDAuthFlow *)authFlow {
  672. __weak GIDAuthFlow *weakAuthFlow = authFlow;
  673. [authFlow addCallback:^() {
  674. GIDAuthFlow *handlerAuthFlow = weakAuthFlow;
  675. OIDAuthState *authState = handlerAuthFlow.authState;
  676. if (authState && !handlerAuthFlow.error) {
  677. if (![self->_keychainHandler saveAuthState:authState]) {
  678. handlerAuthFlow.error = [self errorWithString:kKeychainError
  679. code:kGIDSignInErrorCodeKeychain];
  680. return;
  681. }
  682. if (self->_currentOptions.addScopesFlow) {
  683. [self->_currentUser updateWithTokenResponse:authState.lastTokenResponse
  684. authorizationResponse:authState.lastAuthorizationResponse
  685. profileData:handlerAuthFlow.profileData];
  686. } else {
  687. GIDGoogleUser *user = [[GIDGoogleUser alloc] initWithAuthState:authState
  688. profileData:handlerAuthFlow.profileData];
  689. self.currentUser = user;
  690. }
  691. }
  692. }];
  693. }
  694. // Adds a callback to the auth flow to extract user data from the ID token where available and
  695. // make a userinfo request if necessary.
  696. - (void)addDecodeIdTokenCallback:(GIDAuthFlow *)authFlow {
  697. __weak GIDAuthFlow *weakAuthFlow = authFlow;
  698. [authFlow addCallback:^() {
  699. GIDAuthFlow *handlerAuthFlow = weakAuthFlow;
  700. OIDAuthState *authState = handlerAuthFlow.authState;
  701. if (!authState || handlerAuthFlow.error) {
  702. return;
  703. }
  704. OIDIDToken *idToken =
  705. [[OIDIDToken alloc] initWithIDTokenString: authState.lastTokenResponse.idToken];
  706. // If the profile data are present in the ID token, use them.
  707. if (idToken) {
  708. handlerAuthFlow.profileData = [self profileDataWithIDToken:idToken];
  709. }
  710. // If we can't retrieve profile data from the ID token, make a userInfo request to fetch them.
  711. if (!handlerAuthFlow.profileData) {
  712. [handlerAuthFlow wait];
  713. NSURL *infoURL = [NSURL URLWithString:
  714. [NSString stringWithFormat:kUserInfoURLTemplate,
  715. [GIDSignInPreferences googleUserInfoServer],
  716. authState.lastTokenResponse.accessToken]];
  717. [self startFetchURL:infoURL
  718. fromAuthState:authState
  719. withComment:@"GIDSignIn: fetch basic profile info"
  720. withCompletionHandler:^(NSData *data, NSError *error) {
  721. if (data && !error) {
  722. NSError *jsonDeserializationError;
  723. NSDictionary<NSString *, NSString *> *profileDict =
  724. [NSJSONSerialization JSONObjectWithData:data
  725. options:NSJSONReadingMutableContainers
  726. error:&jsonDeserializationError];
  727. if (profileDict) {
  728. handlerAuthFlow.profileData = [[GIDProfileData alloc]
  729. initWithEmail:idToken.claims[kBasicProfileEmailKey]
  730. name:profileDict[kBasicProfileNameKey]
  731. givenName:profileDict[kBasicProfileGivenNameKey]
  732. familyName:profileDict[kBasicProfileFamilyNameKey]
  733. imageURL:[NSURL URLWithString:profileDict[kBasicProfilePictureKey]]];
  734. }
  735. }
  736. if (error) {
  737. handlerAuthFlow.error = error;
  738. }
  739. [handlerAuthFlow next];
  740. }];
  741. }
  742. }];
  743. }
  744. // Adds a callback to the auth flow to complete the flow by calling the sign-in callback.
  745. - (void)addCompletionCallback:(GIDAuthFlow *)authFlow {
  746. __weak GIDAuthFlow *weakAuthFlow = authFlow;
  747. [authFlow addCallback:^() {
  748. GIDAuthFlow *handlerAuthFlow = weakAuthFlow;
  749. if (self->_currentOptions.completion) {
  750. GIDUserAuthCompletion completion = self->_currentOptions.completion;
  751. self->_currentOptions = nil;
  752. dispatch_async(dispatch_get_main_queue(), ^{
  753. if (handlerAuthFlow.error) {
  754. completion(nil, handlerAuthFlow.error);
  755. } else {
  756. OIDAuthState *authState = handlerAuthFlow.authState;
  757. NSString *_Nullable serverAuthCode =
  758. [authState.lastTokenResponse.additionalParameters[@"server_code"] copy];
  759. GIDUserAuth *userAuth = [[GIDUserAuth alloc] initWithGoogleUser:self->_currentUser
  760. serverAuthCode:serverAuthCode];
  761. completion(userAuth, nil);
  762. }
  763. });
  764. }
  765. }];
  766. }
  767. - (void)startFetchURL:(NSURL *)URL
  768. fromAuthState:(OIDAuthState *)authState
  769. withComment:(NSString *)comment
  770. withCompletionHandler:(void (^)(NSData *, NSError *))handler {
  771. NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
  772. GTMSessionFetcher *fetcher;
  773. GTMAppAuthFetcherAuthorization *authorization =
  774. [[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:authState];
  775. id<GTMSessionFetcherServiceProtocol> fetcherService = authorization.fetcherService;
  776. if (fetcherService) {
  777. fetcher = [fetcherService fetcherWithRequest:request];
  778. } else {
  779. fetcher = [GTMSessionFetcher fetcherWithRequest:request];
  780. }
  781. fetcher.retryEnabled = YES;
  782. fetcher.maxRetryInterval = kFetcherMaxRetryInterval;
  783. fetcher.comment = comment;
  784. [fetcher beginFetchWithCompletionHandler:handler];
  785. }
  786. // Parse incoming URL from the Google Device Policy app.
  787. - (BOOL)handleDevicePolicyAppURL:(NSURL *)url {
  788. OIDURLQueryComponent *queryComponent = [[OIDURLQueryComponent alloc] initWithURL:url];
  789. NSDictionary<NSString *, NSObject<NSCopying> *> *params = queryComponent.dictionaryValue;
  790. NSObject<NSCopying> *actionParam = params[@"action"];
  791. NSString *actionString =
  792. [actionParam isKindOfClass:[NSString class]] ? (NSString *)actionParam : nil;
  793. if (![@"restart_auth" isEqualToString:actionString]) {
  794. return NO;
  795. }
  796. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  797. if (!_currentOptions.presentingViewController) {
  798. return NO;
  799. }
  800. #elif TARGET_OS_OSX
  801. if (!_currentOptions.presentingWindow) {
  802. return NO;
  803. }
  804. #endif // TARGET_OS_OSX
  805. if (!_currentAuthorizationFlow) {
  806. return NO;
  807. }
  808. _restarting = YES;
  809. [_currentAuthorizationFlow cancel];
  810. _currentAuthorizationFlow = nil;
  811. _restarting = NO;
  812. NSDictionary<NSString *, NSString *> *extraParameters = @{ kEMMRestartAuthParameter : @"1" };
  813. // In iOS 13 the presentation of ASWebAuthenticationSession needs an anchor window,
  814. // so we need to wait until the previous presentation is completely gone to ensure the right
  815. // anchor window is used here.
  816. dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
  817. (int64_t)(kPresentationDelayAfterCancel * NSEC_PER_SEC)),
  818. dispatch_get_main_queue(), ^{
  819. [self signInWithOptions:[self->_currentOptions optionsWithExtraParameters:extraParameters
  820. forContinuation:YES]];
  821. });
  822. return YES;
  823. }
  824. #pragma mark - Helpers
  825. - (NSError *)errorWithString:(NSString *)errorString code:(GIDSignInErrorCode)code {
  826. if (errorString == nil) {
  827. errorString = @"Unknown error";
  828. }
  829. NSDictionary<NSString *, NSString *> *errorDict = @{ NSLocalizedDescriptionKey : errorString };
  830. return [NSError errorWithDomain:kGIDSignInErrorDomain
  831. code:code
  832. userInfo:errorDict];
  833. }
  834. + (BOOL)isOperatingSystemAtLeast9 {
  835. NSProcessInfo *processInfo = [NSProcessInfo processInfo];
  836. return [processInfo respondsToSelector:@selector(isOperatingSystemAtLeastVersion:)] &&
  837. [processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){.majorVersion = 9}];
  838. }
  839. // Asserts the parameters being valid.
  840. - (void)assertValidParameters {
  841. if (![_currentOptions.configuration.clientID length]) {
  842. // NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
  843. [NSException raise:NSInvalidArgumentException
  844. format:@"You must specify |clientID| in |GIDConfiguration|"];
  845. }
  846. }
  847. // Assert that the presenting view controller has been set.
  848. - (void)assertValidPresentingViewController {
  849. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  850. if (!_currentOptions.presentingViewController)
  851. #elif TARGET_OS_OSX
  852. if (!_currentOptions.presentingWindow)
  853. #endif // TARGET_OS_OSX
  854. {
  855. // NOLINTNEXTLINE(google-objc-avoid-throwing-exception)
  856. [NSException raise:NSInvalidArgumentException
  857. format:@"|presentingViewController| must be set."];
  858. }
  859. }
  860. // Checks whether or not this is the first time the app runs.
  861. - (BOOL)isFreshInstall {
  862. NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
  863. if ([defaults boolForKey:kAppHasRunBeforeKey]) {
  864. return NO;
  865. }
  866. [defaults setBool:YES forKey:kAppHasRunBeforeKey];
  867. return YES;
  868. }
  869. // Generates user profile from OIDIDToken.
  870. - (GIDProfileData *)profileDataWithIDToken:(OIDIDToken *)idToken {
  871. if (!idToken ||
  872. !idToken.claims[kBasicProfilePictureKey] ||
  873. !idToken.claims[kBasicProfileNameKey] ||
  874. !idToken.claims[kBasicProfileGivenNameKey] ||
  875. !idToken.claims[kBasicProfileFamilyNameKey]) {
  876. return nil;
  877. }
  878. return [[GIDProfileData alloc]
  879. initWithEmail:idToken.claims[kBasicProfileEmailKey]
  880. name:idToken.claims[kBasicProfileNameKey]
  881. givenName:idToken.claims[kBasicProfileGivenNameKey]
  882. familyName:idToken.claims[kBasicProfileFamilyNameKey]
  883. imageURL:[NSURL URLWithString:idToken.claims[kBasicProfilePictureKey]]];
  884. }
  885. // Try to retrieve a configuration value from an |NSBundle|'s Info.plist for a given key.
  886. + (nullable NSString *)configValueFromBundle:(NSBundle *)bundle forKey:(NSString *)key {
  887. NSString *value;
  888. id configValue = [bundle objectForInfoDictionaryKey:key];
  889. if ([configValue isKindOfClass:[NSString class]]) {
  890. value = configValue;
  891. }
  892. return value;
  893. }
  894. // Try to generate a |GIDConfiguration| from an |NSBundle|'s Info.plist.
  895. + (nullable GIDConfiguration *)configurationFromBundle:(NSBundle *)bundle {
  896. GIDConfiguration *configuration;
  897. // Retrieve any valid config parameters from the bundle's Info.plist.
  898. NSString *clientID = [GIDSignIn configValueFromBundle:bundle forKey:kConfigClientIDKey];
  899. NSString *serverClientID = [GIDSignIn configValueFromBundle:bundle
  900. forKey:kConfigServerClientIDKey];
  901. NSString *hostedDomain = [GIDSignIn configValueFromBundle:bundle forKey:kConfigHostedDomainKey];
  902. NSString *openIDRealm = [GIDSignIn configValueFromBundle:bundle forKey:kConfigOpenIDRealmKey];
  903. // If we have at least a client ID, try to construct a configuration.
  904. if (clientID) {
  905. configuration = [[GIDConfiguration alloc] initWithClientID:clientID
  906. serverClientID:serverClientID
  907. hostedDomain:hostedDomain
  908. openIDRealm:openIDRealm];
  909. }
  910. return configuration;
  911. }
  912. @end
  913. NS_ASSUME_NONNULL_END