GIDSignInInternalOptions.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
  30. NSError *_Nullable error))callback {
  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. callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
  38. NSError *_Nullable error))callback {
  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->_callback = callback;
  53. options->_scopes = [GIDScopes scopesWithBasicProfile:scopes];
  54. }
  55. return options;
  56. }
  57. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  58. + (instancetype)defaultOptionsWithConfiguration:(nullable GIDConfiguration *)configuration
  59. presentingViewController:(nullable UIViewController *)presentingViewController
  60. loginHint:(nullable NSString *)loginHint
  61. addScopesFlow:(BOOL)addScopesFlow
  62. callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
  63. NSError *_Nullable error))callback {
  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. callback:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
  70. NSError *_Nullable error))callback {
  71. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  72. GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:configuration
  73. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  74. presentingViewController:presentingViewController
  75. #elif TARGET_OS_OSX
  76. presentingWindow:presentingWindow
  77. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  78. loginHint:loginHint
  79. addScopesFlow:addScopesFlow
  80. scopes:@[]
  81. callback:callback];
  82. return options;
  83. }
  84. + (instancetype)silentOptionsWithCallback:(void (^)(GIDUserAuth *_Nullable userAuth,
  85. NSError *_Nullable error))callback {
  86. GIDSignInInternalOptions *options = [self defaultOptionsWithConfiguration:nil
  87. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  88. presentingViewController:nil
  89. #elif TARGET_OS_OSX
  90. presentingWindow:nil
  91. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  92. loginHint:nil
  93. addScopesFlow:NO
  94. callback:callback];
  95. if (options) {
  96. options->_interactive = NO;
  97. }
  98. return options;
  99. }
  100. - (instancetype)optionsWithExtraParameters:(NSDictionary *)extraParams
  101. forContinuation:(BOOL)continuation {
  102. GIDSignInInternalOptions *options = [[GIDSignInInternalOptions alloc] init];
  103. if (options) {
  104. options->_interactive = _interactive;
  105. options->_continuation = continuation;
  106. options->_addScopesFlow = _addScopesFlow;
  107. options->_configuration = _configuration;
  108. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  109. options->_presentingViewController = _presentingViewController;
  110. #elif TARGET_OS_OSX
  111. options->_presentingWindow = _presentingWindow;
  112. #endif // TARGET_OS_IOS || TARGET_OS_MACCATALYST
  113. options->_loginHint = _loginHint;
  114. options->_callback = _callback;
  115. options->_scopes = _scopes;
  116. options->_extraParams = [extraParams copy];
  117. }
  118. return options;
  119. }
  120. @end
  121. NS_ASSUME_NONNULL_END