GIDSignInInternalOptions.m 6.7 KB

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