GIDSignInInternalOptions.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/GIDSignInInternalOptions.h"
  15. #if __has_include(<UIKit/UIKit.h>)
  16. #import <UIKit/UIKit.h>
  17. #elif __has_include(<AppKit/AppKit.h>)
  18. #import <AppKit/AppKit.h>
  19. #endif
  20. #import "GoogleSignIn/Sources/GIDScopes.h"
  21. NS_ASSUME_NONNULL_BEGIN
  22. @implementation GIDSignInInternalOptions
  23. #if TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  24. + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
  25. presentingViewController:(nullable UIViewController *)presentingViewController
  26. loginHint:(nullable NSString *)loginHint
  27. addScopesFlow:(BOOL)addScopesFlow
  28. accountDetailsToVerify:(NSArray<GIDVerifiableAccountDetail *> *)accountDetailsToVerify
  29. verifyCompletion:(nullable GIDVerifyCompletion)completion{
  30. GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
  31. if (options) {
  32. options->_interactive = YES;
  33. options->_continuation = NO; // Not relevant to VwG flow.
  34. options->_addScopesFlow = addScopesFlow;
  35. options->_configuration = configuration;
  36. options->_presentingViewController = presentingViewController;
  37. options->_loginHint = loginHint;
  38. options->_accountDetailsToVerify = accountDetailsToVerify;
  39. options->_verifyCompletion = completion;
  40. }
  41. return options;
  42. }
  43. #endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
  44. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  45. + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
  46. presentingViewController:(nullable UIViewController *)presentingViewController
  47. loginHint:(nullable NSString *)loginHint
  48. addScopesFlow:(BOOL)addScopesFlow
  49. scopes:(nullable NSArray *)scopes
  50. nonce:(nullable NSString *)nonce
  51. completion:(nullable GIDSignInCompletion)completion {
  52. #elif TARGET_OS_OSX
  53. + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
  54. presentingWindow:(nullable NSWindow *)presentingWindow
  55. loginHint:(nullable NSString *)loginHint
  56. addScopesFlow:(BOOL)addScopesFlow
  57. scopes:(nullable NSArray *)scopes
  58. nonce:(nullable NSString *)nonce
  59. completion:(nullable GIDSignInCompletion)completion {
  60. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  61. GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
  62. if (options) {
  63. options->_interactive = YES;
  64. options->_continuation = NO;
  65. options->_addScopesFlow = addScopesFlow;
  66. options->_configuration = configuration;
  67. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  68. options->_presentingViewController = presentingViewController;
  69. #elif TARGET_OS_OSX
  70. options->_presentingWindow = presentingWindow;
  71. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  72. options->_loginHint = loginHint;
  73. options->_completion = completion;
  74. options->_scopes = [GIDScopes scopesWithBasicProfile:scopes];
  75. options->_nonce = nonce;
  76. }
  77. return options;
  78. }
  79. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  80. + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
  81. presentingViewController:(nullable UIViewController *)presentingViewController
  82. loginHint:(nullable NSString *)loginHint
  83. addScopesFlow:(BOOL)addScopesFlow
  84. completion:(nullable GIDSignInCompletion)completion {
  85. #elif TARGET_OS_OSX
  86. + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
  87. presentingWindow:(nullable NSWindow *)presentingWindow
  88. loginHint:(nullable NSString *)loginHint
  89. addScopesFlow:(BOOL)addScopesFlow
  90. completion:(nullable GIDSignInCompletion)completion {
  91. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  92. GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:configuration
  93. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  94. presentingViewController:presentingViewController
  95. #elif TARGET_OS_OSX
  96. presentingWindow:presentingWindow
  97. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  98. loginHint:loginHint
  99. addScopesFlow:addScopesFlow
  100. scopes:@[]
  101. nonce:nil
  102. completion:completion];
  103. return options;
  104. }
  105. + (instancetype)silentOptionsWithCompletion:(GIDSignInCompletion)completion {
  106. GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:nil
  107. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  108. presentingViewController:nil
  109. #elif TARGET_OS_OSX
  110. presentingWindow:nil
  111. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  112. loginHint:nil
  113. addScopesFlow:NO
  114. completion:completion];
  115. if (options) {
  116. options->_interactive = NO;
  117. }
  118. return options;
  119. }
  120. - (instancetype)optionsWithExtraParameters:(NSDictionary *)extraParams
  121. forContinuation:(BOOL)continuation {
  122. GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
  123. if (options) {
  124. options->_interactive = _interactive;
  125. options->_continuation = continuation;
  126. options->_addScopesFlow = _addScopesFlow;
  127. options->_configuration = _configuration;
  128. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  129. options->_presentingViewController = _presentingViewController;
  130. #elif TARGET_OS_OSX
  131. options->_presentingWindow = _presentingWindow;
  132. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  133. options->_loginHint = _loginHint;
  134. options->_completion = _completion;
  135. options->_scopes = _scopes;
  136. options->_extraParams = [extraParams copy];
  137. }
  138. return options;
  139. }
  140. @end
  141. NS_ASSUME_NONNULL_END