/core/externals/update-engine/externals/gdata-objectivec-client/Source/OAuth2/GTMOAuth2SignIn.h

http://macfuse.googlecode.com/ · C++ Header · 187 lines · 72 code · 35 blank · 80 comment · 1 complexity · e8f307d79877f48b6e5a8fb89a5c4aa8 MD5 · raw file

  1. /* Copyright (c) 2011 Google Inc.
  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. */
  15. //
  16. // This sign-in object opens and closes the web view window as needed for
  17. // users to sign in. For signing in to Google, it also obtains
  18. // the authenticated user's email address.
  19. //
  20. // Typically, this will be managed for the application by
  21. // GTMOAuth2ViewControllerTouch or GTMOAuth2WindowController, so this
  22. // class's interface is interesting only if
  23. // you are creating your own window controller for sign-in.
  24. //
  25. //
  26. // Delegate methods implemented by the window controller
  27. //
  28. // The window controller implements two methods for use by the sign-in object,
  29. // the webRequestSelector and the finishedSelector:
  30. //
  31. // webRequestSelector has a signature matching
  32. // - (void)signIn:(GTMOAuth2SignIn *)signIn displayRequest:(NSURLRequest *)request
  33. //
  34. // The web request selector will be invoked with a request to be displayed, or
  35. // nil to close the window when the final callback request has been encountered.
  36. //
  37. //
  38. // finishedSelector has a signature matching
  39. // - (void)signin:(GTMOAuth2SignIn *)signin finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
  40. //
  41. // The finished selector will be invoked when sign-in has completed, except
  42. // when explicitly canceled by calling cancelSigningIn
  43. //
  44. #if GTM_INCLUDE_OAUTH2 || !GDATA_REQUIRE_SERVICE_INCLUDES
  45. #import <Foundation/Foundation.h>
  46. #import <SystemConfiguration/SystemConfiguration.h>
  47. // GTMHTTPFetcher brings in GTLDefines/GDataDefines
  48. #import "GTMHTTPFetcher.h"
  49. #import "GTMOAuth2Authentication.h"
  50. @interface GTMOAuth2SignIn : NSObject {
  51. @private
  52. GTMOAuth2Authentication *auth_;
  53. // the endpoint for displaying the sign-in page
  54. NSURL *authorizationURL_;
  55. NSDictionary *additionalAuthorizationParameters_;
  56. id delegate_;
  57. SEL webRequestSelector_;
  58. SEL finishedSelector_;
  59. BOOL hasHandledCallback_;
  60. GTMHTTPFetcher *pendingFetcher_;
  61. #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
  62. BOOL shouldFetchGoogleUserEmail_;
  63. BOOL shouldFetchGoogleUserProfile_;
  64. NSDictionary *userProfile_;
  65. #endif
  66. SCNetworkReachabilityRef reachabilityRef_;
  67. NSTimer *networkLossTimer_;
  68. NSTimeInterval networkLossTimeoutInterval_;
  69. BOOL hasNotifiedNetworkLoss_;
  70. id userData_;
  71. }
  72. @property (nonatomic, retain) GTMOAuth2Authentication *authentication;
  73. @property (nonatomic, retain) NSURL *authorizationURL;
  74. @property (nonatomic, retain) NSDictionary *additionalAuthorizationParameters;
  75. // The delegate is released when signing in finishes or is cancelled
  76. @property (nonatomic, retain) id delegate;
  77. @property (nonatomic, assign) SEL webRequestSelector;
  78. @property (nonatomic, assign) SEL finishedSelector;
  79. @property (nonatomic, retain) id userData;
  80. // By default, signing in to Google will fetch the user's email, but will not
  81. // fetch the user's profile.
  82. //
  83. // The email is saved in the auth object.
  84. // The profile is available immediately after sign-in.
  85. #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
  86. @property (nonatomic, assign) BOOL shouldFetchGoogleUserEmail;
  87. @property (nonatomic, assign) BOOL shouldFetchGoogleUserProfile;
  88. @property (nonatomic, retain, readonly) NSDictionary *userProfile;
  89. #endif
  90. // The default timeout for an unreachable network during display of the
  91. // sign-in page is 30 seconds; set this to 0 to have no timeout
  92. @property (nonatomic, assign) NSTimeInterval networkLossTimeoutInterval;
  93. // The delegate is retained until sign-in has completed or been canceled
  94. //
  95. // designated initializer
  96. - (id)initWithAuthentication:(GTMOAuth2Authentication *)auth
  97. authorizationURL:(NSURL *)authorizationURL
  98. delegate:(id)delegate
  99. webRequestSelector:(SEL)webRequestSelector
  100. finishedSelector:(SEL)finishedSelector;
  101. // A default authentication object for signing in to Google services
  102. #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
  103. + (GTMOAuth2Authentication *)standardGoogleAuthenticationForScope:(NSString *)scope
  104. clientID:(NSString *)clientID
  105. clientSecret:(NSString *)clientSecret;
  106. #endif
  107. #pragma mark Methods used by the Window Controller
  108. // Start the sequence of fetches and sign-in window display for sign-in
  109. - (BOOL)startSigningIn;
  110. // Stop any pending fetches, and close the window (but don't call the
  111. // delegate's finishedSelector)
  112. - (void)cancelSigningIn;
  113. // Window controllers must tell the sign-in object about any redirect
  114. // requested by the web view, and any changes in the webview window title
  115. //
  116. // If these return YES then the event was handled by the
  117. // sign-in object (typically by closing the window) and should be ignored by
  118. // the window controller's web view
  119. - (BOOL)requestRedirectedToRequest:(NSURLRequest *)redirectedRequest;
  120. - (BOOL)titleChanged:(NSString *)title;
  121. - (BOOL)cookiesChanged:(NSHTTPCookieStorage *)cookieStorage;
  122. - (BOOL)loadFailedWithError:(NSError *)error;
  123. // Window controllers must tell the sign-in object if the window was closed
  124. // prematurely by the user (but not by the sign-in object); this calls the
  125. // delegate's finishedSelector
  126. - (void)windowWasClosed;
  127. // Start the sequences for signing in with an authorization code. The
  128. // authentication must contain an authorization code, otherwise the process
  129. // will fail.
  130. - (void)authCodeObtained;
  131. #pragma mark -
  132. #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
  133. // Revocation of an authorized token from Google
  134. + (void)revokeTokenForGoogleAuthentication:(GTMOAuth2Authentication *)auth;
  135. // Create a fetcher for obtaining the user's Google email address or profile,
  136. // according to the current auth scopes.
  137. //
  138. // The auth object must have been created with appropriate scopes.
  139. //
  140. // The fetcher's response data can be parsed with NSJSONSerialization.
  141. + (GTMHTTPFetcher *)userInfoFetcherWithAuth:(GTMOAuth2Authentication *)auth;
  142. #endif
  143. #pragma mark -
  144. // Standard authentication values
  145. + (NSString *)nativeClientRedirectURI;
  146. #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
  147. + (NSURL *)googleAuthorizationURL;
  148. + (NSURL *)googleTokenURL;
  149. + (NSURL *)googleUserInfoURL;
  150. #endif
  151. @end
  152. #endif // #if GTM_INCLUDE_OAUTH2 || !GDATA_REQUIRE_SERVICE_INCLUDES