GIDSignIn_Private.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. NS_ASSUME_NONNULL_BEGIN
  24. @class GIDGoogleUser;
  25. @class GIDSignInInternalOptions;
  26. /// Represents a completion block that takes a `GIDUserAuth` on success or an error if the operation
  27. /// was unsuccessful.
  28. typedef void (^GIDUserAuthCompletion)(GIDUserAuth *_Nullable userAuth, NSError *_Nullable error);
  29. // Private |GIDSignIn| methods that are used internally in this SDK and other Google SDKs.
  30. @interface GIDSignIn ()
  31. /// Redeclare |currentUser| as readwrite for internal use.
  32. @property(nonatomic, readwrite, nullable) GIDGoogleUser *currentUser;
  33. /// Private initializer for |GIDSignIn|.
  34. - (instancetype)initPrivate;
  35. /// Authenticates with extra options.
  36. - (void)signInWithOptions:(GIDSignInInternalOptions *)options;
  37. /// Restores a previously authenticated user from the keychain synchronously without refreshing
  38. /// the access token or making a userinfo request.
  39. ///
  40. /// The currentUser.profile will be nil unless the profile data can be extracted from the ID token.
  41. ///
  42. /// @return NO if there is no user restored from the keychain.
  43. - (BOOL)restorePreviousSignInNoRefresh;
  44. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  45. /// Starts an interactive consent flow on iOS to add scopes to the user's grants.
  46. ///
  47. /// The completion will be called at the end of this process. If successful, a `GIDUserAuth`
  48. /// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
  49. ///
  50. /// @param scopes The scopes to ask the user to consent to.
  51. /// @param presentingViewController The view controller used to present `SFSafariViewContoller` on
  52. /// iOS 9 and 10 and to supply `presentationContextProvider` for `ASWebAuthenticationSession` on
  53. /// iOS 13+.
  54. /// @param completion The block that is called on completion. This block will be called asynchronously
  55. /// on the main queue.
  56. - (void)addScopes:(NSArray<NSString *> *)scopes
  57. presentingViewController:(UIViewController *)presentingViewController
  58. completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
  59. NSError *_Nullable error))completion
  60. NS_EXTENSION_UNAVAILABLE("The add scopes flow is not supported in App Extensions.");
  61. #elif TARGET_OS_OSX
  62. /// Starts an interactive consent flow on macOS to add scopes to the user's grants
  63. ///
  64. /// The completion will be called at the end of this process. If successful, a `GIDUserAuth`
  65. /// instance will be returned reflecting the new scopes and saved sign-in state will be updated.
  66. ///
  67. /// @param scopes An array of scopes to ask the user to consent to.
  68. /// @param presentingWindow The window used to supply `presentationContextProvider` for
  69. /// `ASWebAuthenticationSession`.
  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. presentingWindow:(NSWindow *)presentingWindow
  74. completion:(nullable void (^)(GIDUserAuth *_Nullable userAuth,
  75. NSError *_Nullable error))completion;
  76. #endif
  77. @end
  78. NS_ASSUME_NONNULL_END