GIDSignInInternalOptions.m 5.8 KB

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