GIDSignIn_Private.h 3.9 KB

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