2012-08-25 10:38:29 +00:00
|
|
|
//
|
2013-01-31 21:22:37 +00:00
|
|
|
// GPPSignIn.h
|
2012-08-25 10:38:29 +00:00
|
|
|
// Google+ iOS SDK
|
|
|
|
//
|
|
|
|
// Copyright 2012 Google Inc.
|
|
|
|
//
|
2013-04-27 21:14:05 +00:00
|
|
|
// Use of this SDK is subject to the Google+ Platform Terms of Service:
|
2012-08-25 10:38:29 +00:00
|
|
|
// https://developers.google.com/+/terms
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
|
|
|
@class GTMOAuth2Authentication;
|
|
|
|
@class GTMOAuth2ViewControllerTouch;
|
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// A protocol implemented by the client of |GPPSignIn| to receive a refresh
|
|
|
|
// token or an error.
|
2013-01-31 21:22:37 +00:00
|
|
|
@protocol GPPSignInDelegate
|
2012-08-25 10:38:29 +00:00
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// The authorization has finished and is successful if |error| is |nil|.
|
2012-08-25 10:38:29 +00:00
|
|
|
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
|
|
|
|
error:(NSError *)error;
|
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// Finished disconnecting user from the app.
|
|
|
|
// The operation was successful if |error| is |nil|.
|
|
|
|
@optional
|
|
|
|
- (void)didDisconnectWithError:(NSError *)error;
|
|
|
|
|
2012-08-25 10:38:29 +00:00
|
|
|
@end
|
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// This class signs the user in with Google. It provides single sign-on
|
|
|
|
// via the Google+ app (if installed), Chrome for iOS (if installed), or Mobile
|
|
|
|
// Safari.
|
|
|
|
//
|
|
|
|
// For reference, please see "Google+ Sign-In for iOS" at
|
|
|
|
// https://developers.google.com/+/mobile/ios/sign-in .
|
|
|
|
// Here is sample code to use |GPPSignIn|:
|
|
|
|
// 1) Get a reference to the |GPPSignIn| shared instance:
|
|
|
|
// GPPSignIn *signIn = [GPPSignIn sharedInstance];
|
|
|
|
// 2) Set the OAuth 2.0 scopes you want to request:
|
|
|
|
// [signIn setScopes:[NSArray arrayWithObject:
|
|
|
|
// @"https://www.googleapis.com/auth/plus.login"]];
|
|
|
|
// 2) Call [signIn setDelegate:self];
|
|
|
|
// 3) Set up delegate method |finishedWithAuth:error:|.
|
|
|
|
// 4) Call |handleURL| on the shared instance from |application:openUrl:...|
|
|
|
|
// in your app delegate.
|
|
|
|
// 5) Call [signIn authenticate];
|
2013-01-31 21:22:37 +00:00
|
|
|
@interface GPPSignIn : NSObject
|
2012-08-25 10:38:29 +00:00
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// The authentication object for the current user, or |nil| if there is
|
|
|
|
// currently no logged in user.
|
|
|
|
@property (nonatomic, readonly) GTMOAuth2Authentication *authentication;
|
|
|
|
|
|
|
|
// The Google user ID. It is only available if |shouldFetchGoogleUserID| is set
|
|
|
|
// and either |trySilentAuthentication| or |authenticate| has been completed
|
|
|
|
// successfully.
|
|
|
|
@property (nonatomic, readonly) NSString *userID;
|
|
|
|
|
|
|
|
// The Google user's email. It is only available if |shouldFetchGoogleUserEmail|
|
|
|
|
// is set and either |trySilentAuthentication| or |authenticate| has been
|
|
|
|
// completed successfully.
|
|
|
|
@property (nonatomic, readonly) NSString *userEmail;
|
|
|
|
|
2012-08-25 10:38:29 +00:00
|
|
|
// The object to be notified when authentication is finished.
|
2013-01-31 21:22:37 +00:00
|
|
|
@property (nonatomic, assign) id<GPPSignInDelegate> delegate;
|
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// All properties below are optional parameters. If they need to be set, set
|
|
|
|
// before calling |authenticate|.
|
|
|
|
|
|
|
|
// The client ID of the app from the Google APIs console.
|
|
|
|
// Must set for sign-in to work.
|
|
|
|
@property (nonatomic, copy) NSString *clientID;
|
|
|
|
|
|
|
|
// The API scopes requested by the app in an array of |NSString|s.
|
|
|
|
// The default value is |@[@"https://www.googleapis.com/auth/plus.login"]|.
|
|
|
|
@property (nonatomic, copy) NSArray *scopes;
|
|
|
|
|
|
|
|
// Whether or not to attempt Single-Sign-On when signing in.
|
|
|
|
// If |attemptSSO| is true, the sign-in button tries to authenticate with the
|
|
|
|
// Google+ application if it is installed. If false, it always uses Google+ via
|
|
|
|
// Chrome for iOS, if installed, or Mobile Safari for authentication.
|
|
|
|
// The default value is |YES|.
|
|
|
|
@property (nonatomic, assign) BOOL attemptSSO;
|
|
|
|
|
|
|
|
// The language for sign-in, in the form of ISO 639-1 language code
|
|
|
|
// optionally followed by a dash and ISO 3166-1 alpha-2 region code,
|
|
|
|
// such as |@"it"| or |@"pt-PT"|.
|
|
|
|
// Only set if different from system default.
|
|
|
|
@property (nonatomic, copy) NSString *language;
|
|
|
|
|
|
|
|
// Name of the keychain to save the sign-in state.
|
|
|
|
// Only set if a custom name needs to be used.
|
|
|
|
@property (nonatomic, copy) NSString *keychainName;
|
|
|
|
|
|
|
|
// An |NSString| array of moment types used by your app. Use values from the
|
|
|
|
// full list at
|
|
|
|
// https://developers.google.com/+/api/moment-types .
|
|
|
|
// such as "http://schemas.google.com/AddActivity".
|
|
|
|
// This property is required only for writing moments, with
|
|
|
|
// "https://www.googleapis.com/auth/plus.login" as a scope.
|
|
|
|
@property (nonatomic, copy) NSArray *actions;
|
|
|
|
|
2013-01-31 21:22:37 +00:00
|
|
|
// Whether or not to fetch user email after signing in. The email is saved in
|
2013-04-27 21:14:05 +00:00
|
|
|
// the |GTMOAuth2Authentication| object. Note that using this flag automatically
|
|
|
|
// adds "https://www.googleapis.com/auth/userinfo.email" scope to the request.
|
2013-01-31 21:22:37 +00:00
|
|
|
@property (nonatomic, assign) BOOL shouldFetchGoogleUserEmail;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// Whether or not to fetch user ID after signing in. The ID can be retrieved
|
|
|
|
// by |googleUserID| after user has been authenticated.
|
|
|
|
// Note, a scope, such as "https://www.googleapis.com/auth/plus.login" or
|
|
|
|
// "https://www.googleapis.com/auth/plus.me", that provides user ID must be
|
|
|
|
// included in |scopes| for this flag to work.
|
|
|
|
@property (nonatomic, assign) BOOL shouldFetchGoogleUserID;
|
|
|
|
|
|
|
|
// Returns a shared |GPPSignIn| instance.
|
|
|
|
+ (GPPSignIn *)sharedInstance;
|
|
|
|
|
|
|
|
// Checks whether the user has either currently signed in or has previous
|
|
|
|
// authentication saved in keychain.
|
|
|
|
- (BOOL)hasAuthInKeychain;
|
|
|
|
|
|
|
|
// Attempts to authenticate silently without user interaction.
|
|
|
|
// Returns |YES| and calls the delegate if the user has either currently signed
|
|
|
|
// in or has previous authentication saved in keychain.
|
|
|
|
- (BOOL)trySilentAuthentication;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
|
|
|
// Starts the authentication process. Set |attemptSSO| to try single sign-on.
|
2013-04-27 21:14:05 +00:00
|
|
|
// If |attemptSSO| is true, try to authenticate with the Google+ app, if
|
|
|
|
// installed. If false, always use Google+ via Chrome or Mobile Safari for
|
|
|
|
// authentication. The delegate will be called at the end of this process.
|
|
|
|
- (void)authenticate;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
|
|
|
// This method should be called from your |UIApplicationDelegate|'s
|
|
|
|
// |application:openURL:sourceApplication:annotation|. Returns |YES| if
|
2013-01-31 21:22:37 +00:00
|
|
|
// |GPPSignIn| handled this URL.
|
2013-04-27 21:14:05 +00:00
|
|
|
// Also see |handleURL:sourceApplication:annotation:| in |GPPURLHandler|.
|
2012-08-25 10:38:29 +00:00
|
|
|
- (BOOL)handleURL:(NSURL *)url
|
|
|
|
sourceApplication:(NSString *)sourceApplication
|
|
|
|
annotation:(id)annotation;
|
|
|
|
|
|
|
|
// Removes the OAuth 2.0 token from the keychain.
|
|
|
|
- (void)signOut;
|
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// Disconnects the user from the app and revokes previous authentication.
|
|
|
|
// If the operation succeeds, the OAuth 2.0 token is also removed from keychain.
|
|
|
|
// The token is needed to disconnect so do not call |signOut| if |disconnect| is
|
|
|
|
// to be called.
|
|
|
|
- (void)disconnect;
|
|
|
|
|
2012-08-25 10:38:29 +00:00
|
|
|
@end
|