GIDSignIn_Private.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright 2021 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <TargetConditionals.h>
  17. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDSignIn.h"
  18. #if __has_include(<UIKit/UIKit.h>)
  19. #import <UIKit/UIKit.h>
  20. #elif __has_include(<AppKit/AppKit.h>)
  21. #import <AppKit/AppKit.h>
  22. #endif
  23. @class GIDGoogleUser;
  24. @class GIDSignInInternalOptions;
  25. @protocol GIDAuthorizationFlowProcessor;
  26. @protocol GIDHTTPFetcher;
  27. @protocol GIDKeychainHandler;
  28. @protocol GIDProfileDataFetcher;
  29. NS_ASSUME_NONNULL_BEGIN
  30. /// The EMM support version.
  31. extern NSString *const kEMMVersion;
  32. /// Represents a completion block that takes a `GIDSignInResult` on success or an error if the
  33. /// operation was unsuccessful.
  34. typedef void (^GIDSignInCompletion)(GIDSignInResult *_Nullable signInResult,
  35. NSError *_Nullable error);
  36. /// Represents a completion block that takes an error if the operation was unsuccessful.
  37. typedef void (^GIDDisconnectCompletion)(NSError *_Nullable error);
  38. // Private |GIDSignIn| methods that are used internally in this SDK and other Google SDKs.
  39. @interface GIDSignIn ()
  40. /// Redeclare |currentUser| as readwrite for internal use.
  41. @property(nonatomic, readwrite, nullable) GIDGoogleUser *currentUser;
  42. /// Private initializer for |GIDSignIn|.
  43. - (instancetype)initPrivate;
  44. /// The designated initializer.
  45. - (instancetype)initWithKeychainHandler:(id<GIDKeychainHandler>)keychainHandler
  46. httpFetcher:(id<GIDHTTPFetcher>)HTTPFetcher
  47. profileDataFetcher:(id<GIDProfileDataFetcher>)profileDataFetcher
  48. authorizationFlowProcessor:
  49. (id<GIDAuthorizationFlowProcessor>)authorizationFlowProcessor
  50. NS_DESIGNATED_INITIALIZER;
  51. /// Authenticates with extra options.
  52. - (void)signInWithOptions:(GIDSignInInternalOptions *)options;
  53. /// Restores a previously authenticated user from the keychain synchronously without refreshing
  54. /// the access token or making a userinfo request.
  55. ///
  56. /// The currentUser.profile will be nil unless the profile data can be extracted from the ID token.
  57. ///
  58. /// @return NO if there is no user restored from the keychain.
  59. - (BOOL)restorePreviousSignInNoRefresh;
  60. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  61. /// Starts an interactive consent flow on iOS to add scopes to the current user's grants.
  62. ///
  63. /// The completion will be called at the end of this process. If successful, a `GIDSignInResult`
  64. /// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
  65. ///
  66. /// @param scopes The scopes to ask the user to consent to.
  67. /// @param presentingViewController The view controller used to present `SFSafariViewController` on
  68. /// iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on
  69. /// iOS 13+.
  70. /// @param completion The block that is called on completion. This block will be called asynchronously
  71. /// on the main queue.
  72. - (void)addScopes:(NSArray<NSString *> *)scopes
  73. presentingViewController:(UIViewController *)presentingViewController
  74. completion:(nullable GIDSignInCompletion)completion
  75. NS_EXTENSION_UNAVAILABLE("The add scopes flow is not supported in App Extensions.");
  76. #elif TARGET_OS_OSX
  77. /// Starts an interactive consent flow on macOS to add scopes to the current user's grants.
  78. ///
  79. /// The completion will be called at the end of this process. If successful, a `GIDSignInResult`
  80. /// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
  81. ///
  82. /// @param scopes An array of scopes to ask the user to consent to.
  83. /// @param presentingWindow The window used to supply `presentationContextProvider` for
  84. /// `ASWebAuthenticationSession`.
  85. /// @param completion The block that is called on completion. This block will be called asynchronously
  86. /// on the main queue.
  87. - (void)addScopes:(NSArray<NSString *> *)scopes
  88. presentingWindow:(NSWindow *)presentingWindow
  89. completion:(nullable GIDSignInCompletion)completion;
  90. #endif
  91. @end
  92. NS_ASSUME_NONNULL_END