Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
174 lines (140 sloc) 5.95 KB
/* Copyright (c) 2011 Google Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
// This sign-in object opens and closes the web view window as needed for
// users to sign in. For signing in to Google, it also obtains
// the authenticated user's email address.
// Typically, this will be managed for the application by
// GTMOAuth2ViewControllerTouch or GTMOAuth2WindowController, so this
// class's interface is interesting only if
// you are creating your own window controller for sign-in.
// Delegate methods implemented by the window controller
// The window controller implements two methods for use by the sign-in object,
// the webRequestSelector and the finishedSelector:
// webRequestSelector has a signature matching
// - (void)signIn:(GTMOAuth2SignIn *)signIn displayRequest:(NSURLRequest *)request
// The web request selector will be invoked with a request to be displayed, or
// nil to close the window when the final callback request has been encountered.
// finishedSelector has a signature matching
// - (void)signin:(GTMOAuth2SignIn *)signin finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error
// The finished selector will be invoked when sign-in has completed, except
// when explicitly canceled by calling cancelSigningIn
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
// GTMHTTPFetcher brings in GTLDefines/GDataDefines
#import "GTMHTTPFetcher.h"
#import "GTMOAuth2Authentication.h"
@interface GTMOAuth2SignIn : NSObject {
GTMOAuth2Authentication *auth_;
// the endpoint for displaying the sign-in page
NSURL *authorizationURL_;
NSDictionary *additionalAuthorizationParameters_;
id delegate_;
SEL webRequestSelector_;
SEL finishedSelector_;
BOOL hasHandledCallback_;
GTMHTTPFetcher *pendingFetcher_;
BOOL shouldFetchGoogleUserEmail_;
BOOL shouldFetchGoogleUserProfile_;
NSDictionary *userProfile_;
SCNetworkReachabilityRef reachabilityRef_;
NSTimer *networkLossTimer_;
NSTimeInterval networkLossTimeoutInterval_;
BOOL hasNotifiedNetworkLoss_;
id userData_;
@property (nonatomic, retain) GTMOAuth2Authentication *authentication;
@property (nonatomic, retain) NSURL *authorizationURL;
@property (nonatomic, retain) NSDictionary *additionalAuthorizationParameters;
// The delegate is released when signing in finishes or is cancelled
@property (nonatomic, retain) id delegate;
@property (nonatomic, assign) SEL webRequestSelector;
@property (nonatomic, assign) SEL finishedSelector;
@property (nonatomic, retain) id userData;
// By default, signing in to Google will fetch the user's email, but will not
// fetch the user's profile.
// The email is saved in the auth object.
// The profile is available immediately after sign-in.
@property (nonatomic, assign) BOOL shouldFetchGoogleUserEmail;
@property (nonatomic, assign) BOOL shouldFetchGoogleUserProfile;
@property (nonatomic, retain, readonly) NSDictionary *userProfile;
// The default timeout for an unreachable network during display of the
// sign-in page is 30 seconds; set this to 0 to have no timeout
@property (nonatomic, assign) NSTimeInterval networkLossTimeoutInterval;
// The delegate is retained until sign-in has completed or been canceled
// designated initializer
- (id)initWithAuthentication:(GTMOAuth2Authentication *)auth
authorizationURL:(NSURL *)authorizationURL
// A default authentication object for signing in to Google services
+ (GTMOAuth2Authentication *)standardGoogleAuthenticationForScope:(NSString *)scope
clientID:(NSString *)clientID
clientSecret:(NSString *)clientSecret;
#pragma mark Methods used by the Window Controller
// Start the sequence of fetches and sign-in window display for sign-in
- (BOOL)startSigningIn;
// Stop any pending fetches, and close the window (but don't call the
// delegate's finishedSelector)
- (void)cancelSigningIn;
// Window controllers must tell the sign-in object about any redirect
// requested by the web view, and any changes in the webview window title
// If these return YES then the event was handled by the
// sign-in object (typically by closing the window) and should be ignored by
// the window controller's web view
- (BOOL)requestRedirectedToRequest:(NSURLRequest *)redirectedRequest;
- (BOOL)titleChanged:(NSString *)title;
- (BOOL)cookiesChanged:(NSHTTPCookieStorage *)cookieStorage;
- (BOOL)loadFailedWithError:(NSError *)error;
// Window controllers must tell the sign-in object if the window was closed
// prematurely by the user (but not by the sign-in object); this calls the
// delegate's finishedSelector
- (void)windowWasClosed;
#pragma mark -
// Revocation of an authorized token from Google
+ (void)revokeTokenForGoogleAuthentication:(GTMOAuth2Authentication *)auth;
#pragma mark -
// Standard authentication values
+ (NSString *)nativeClientRedirectURI;
+ (NSURL *)googleAuthorizationURL;
+ (NSURL *)googleTokenURL;
Jump to Line
Something went wrong with that request. Please try again.