PageRenderTime 30ms CodeModel.GetById 2ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 0ms

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