GIDSignInInternalOptions.m 6.1 KB

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