GIDSignInInternalOptions.m 6.4 KB

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