GIDSignIn.m 43 KB

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