BBGMultiAccountManager
 All Classes Files Functions Variables Enumerator Properties Defines
GMultiAccountManager/GMultiAccountManager/GTMOAuth2SignIn.h
Go to the documentation of this file.
00001 /* Copyright (c) 2011 Google Inc.
00002  *
00003  * Licensed under the Apache License, Version 2.0 (the "License");
00004  * you may not use this file except in compliance with the License.
00005  * You may obtain a copy of the License at
00006  *
00007  *     http://www.apache.org/licenses/LICENSE-2.0
00008  *
00009  * Unless required by applicable law or agreed to in writing, software
00010  * distributed under the License is distributed on an "AS IS" BASIS,
00011  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012  * See the License for the specific language governing permissions and
00013  * limitations under the License.
00014  */
00015 
00016 //
00017 // This sign-in object opens and closes the web view window as needed for
00018 // users to sign in. For signing in to Google, it also obtains
00019 // the authenticated user's email address.
00020 //
00021 // Typically, this will be managed for the application by
00022 // GTMOAuth2ViewControllerTouch or GTMOAuth2WindowController, so this
00023 // class's interface is interesting only if
00024 // you are creating your own window controller for sign-in.
00025 //
00026 //
00027 // Delegate methods implemented by the window controller
00028 //
00029 // The window controller implements two methods for use by the sign-in object,
00030 // the webRequestSelector and the finishedSelector:
00031 //
00032 // webRequestSelector has a signature matching
00033 //   - (void)signIn:(GTMOAuth2SignIn *)signIn displayRequest:(NSURLRequest *)request
00034 //
00035 // The web request selector will be invoked with a request to be displayed, or
00036 // nil to close the window when the final callback request has been encountered.
00037 //
00038 //
00039 // finishedSelector has a signature matching
00040 //  - (void)signin:(GTMOAuth2SignIn *)signin finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
00041 //
00042 // The finished selector will be invoked when sign-in has completed, except
00043 // when explicitly canceled by calling cancelSigningIn
00044 //
00045 
00046 #if GTM_INCLUDE_OAUTH2 || !GDATA_REQUIRE_SERVICE_INCLUDES
00047 
00048 #import <Foundation/Foundation.h>
00049 #import <SystemConfiguration/SystemConfiguration.h>
00050 
00051 // GTMHTTPFetcher brings in GTLDefines/GDataDefines
00052 #import "GTMHTTPFetcher.h"
00053 
00054 #import "GTMOAuth2Authentication.h"
00055 
00056 @interface GTMOAuth2SignIn : NSObject {
00057  @private
00058   GTMOAuth2Authentication *auth_;
00059 
00060   // the endpoint for displaying the sign-in page
00061   NSURL *authorizationURL_;
00062   NSDictionary *additionalAuthorizationParameters_;
00063 
00064   id delegate_;
00065   SEL webRequestSelector_;
00066   SEL finishedSelector_;
00067 
00068   BOOL hasHandledCallback_;
00069 
00070   GTMHTTPFetcher *pendingFetcher_;
00071 
00072 #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
00073   BOOL shouldFetchGoogleUserEmail_;
00074   BOOL shouldFetchGoogleUserProfile_;
00075   NSDictionary *userProfile_;
00076 #endif
00077 
00078   SCNetworkReachabilityRef reachabilityRef_;
00079   NSTimer *networkLossTimer_;
00080   NSTimeInterval networkLossTimeoutInterval_;
00081   BOOL hasNotifiedNetworkLoss_;
00082 
00083   id userData_;
00084 }
00085 
00086 @property (nonatomic, retain) GTMOAuth2Authentication *authentication;
00087 
00088 @property (nonatomic, retain) NSURL *authorizationURL;
00089 @property (nonatomic, retain) NSDictionary *additionalAuthorizationParameters;
00090 
00091 // The delegate is released when signing in finishes or is cancelled
00092 @property (nonatomic, retain) id delegate;
00093 @property (nonatomic, assign) SEL webRequestSelector;
00094 @property (nonatomic, assign) SEL finishedSelector;
00095 
00096 @property (nonatomic, retain) id userData;
00097 
00098 // By default, signing in to Google will fetch the user's email, but will not
00099 // fetch the user's profile.
00100 //
00101 // The email is saved in the auth object.
00102 // The profile is available immediately after sign-in.
00103 #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
00104 @property (nonatomic, assign) BOOL shouldFetchGoogleUserEmail;
00105 @property (nonatomic, assign) BOOL shouldFetchGoogleUserProfile;
00106 @property (nonatomic, retain, readonly) NSDictionary *userProfile;
00107 #endif
00108 
00109 // The default timeout for an unreachable network during display of the
00110 // sign-in page is 30 seconds; set this to 0 to have no timeout
00111 @property (nonatomic, assign) NSTimeInterval networkLossTimeoutInterval;
00112 
00113 // The delegate is retained until sign-in has completed or been canceled
00114 //
00115 // designated initializer
00116 - (id)initWithAuthentication:(GTMOAuth2Authentication *)auth
00117             authorizationURL:(NSURL *)authorizationURL
00118                     delegate:(id)delegate
00119           webRequestSelector:(SEL)webRequestSelector
00120             finishedSelector:(SEL)finishedSelector;
00121 
00122 // A default authentication object for signing in to Google services
00123 #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
00124 + (GTMOAuth2Authentication *)standardGoogleAuthenticationForScope:(NSString *)scope
00125                                                          clientID:(NSString *)clientID
00126                                                      clientSecret:(NSString *)clientSecret;
00127 #endif
00128 
00129 #pragma mark Methods used by the Window Controller
00130 
00131 // Start the sequence of fetches and sign-in window display for sign-in
00132 - (BOOL)startSigningIn;
00133 
00134 // Stop any pending fetches, and close the window (but don't call the
00135 // delegate's finishedSelector)
00136 - (void)cancelSigningIn;
00137 
00138 // Window controllers must tell the sign-in object about any redirect
00139 // requested by the web view, and any changes in the webview window title
00140 //
00141 // If these return YES then the event was handled by the
00142 // sign-in object (typically by closing the window) and should be ignored by
00143 // the window controller's web view
00144 
00145 - (BOOL)requestRedirectedToRequest:(NSURLRequest *)redirectedRequest;
00146 - (BOOL)titleChanged:(NSString *)title;
00147 - (BOOL)cookiesChanged:(NSHTTPCookieStorage *)cookieStorage;
00148 - (BOOL)loadFailedWithError:(NSError *)error;
00149 
00150 // Window controllers must tell the sign-in object if the window was closed
00151 // prematurely by the user (but not by the sign-in object); this calls the
00152 // delegate's finishedSelector
00153 - (void)windowWasClosed;
00154 
00155 #pragma mark -
00156 
00157 // Revocation of an authorized token from Google
00158 #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
00159 + (void)revokeTokenForGoogleAuthentication:(GTMOAuth2Authentication *)auth;
00160 #endif
00161 
00162 #pragma mark -
00163 
00164 // Standard authentication values
00165 + (NSString *)nativeClientRedirectURI;
00166 #if !GTM_OAUTH2_SKIP_GOOGLE_SUPPORT
00167 + (NSURL *)googleAuthorizationURL;
00168 + (NSURL *)googleTokenURL;
00169 + (NSURL *)googleUserInfoURL;
00170 #endif
00171 
00172 @end
00173 
00174 #endif // #if GTM_INCLUDE_OAUTH2 || !GDATA_REQUIRE_SERVICE_INCLUDES