Google+ Platform for iOS

GPPSignIn Class Reference


Overview

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"]];
  3. Call [signIn setDelegate:self];
  4. Set up delegate method finishedWithAuth:error:.
  5. Call handleURL on the shared instance from application:openUrl:... in your app delegate.
  6. Call [signIn authenticate];

Public Member Functions

(BOOL) - hasAuthInKeychain
 Checks whether the user has either currently signed in or has previous authentication saved in keychain.
(BOOL) - trySilentAuthentication
 Attempts to authenticate silently without user interaction.
(void) - authenticate
 Starts the authentication process.
(BOOL) - handleURL:sourceApplication:annotation:
 This method should be called from your UIApplicationDelegate's application:openURL:sourceApplication:annotation.
(void) - signOut
 Removes the OAuth 2.0 token from the keychain.
(void) - disconnect
 Disconnects the user from the app and revokes previous authentication.
(GTLServicePlus *) - plusService
 Gets a service object authenticated as the current user.

Static Public Member Functions

(GPPSignIn *) + sharedInstance
 Returns a shared GPPSignIn instance.

Properties

GTMOAuth2Authentication * authentication
 The authentication object for the current user, or nil if there is currently no logged in user.
NSString * idToken
 A JSON Web Token identifying the user.
NSString * userID
 The Google user ID.
NSString * userEmail
 The Google user's email.
GTLPlusPerson * googlePlusUser
 The Google+ user profile.
id< GPPSignInDelegatedelegate
 The object to be notified when authentication is finished.
NSString * clientID
 All properties below are optional parameters.
NSString * homeServerClientID
 The client ID of the home web server.
NSString * openIDRealm
 The OpenID2 realm of the home web server.
NSArray * scopes
 The API scopes requested by the app in an array of NSStrings.
BOOL attemptSSO
 Whether or not to attempt Single-Sign-On when signing in.
NSString * language
 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".
NSString * keychainName
 Name of the keychain to save the sign-in state.
NSArray * actions
 An NSString array of moment types used by your app.
BOOL shouldFetchGoogleUserEmail
 Whether or not to fetch user email after signing in.
BOOL shouldFetchGoogleUserID
 Whether or not to fetch user ID after signing in.
BOOL shouldFetchGooglePlusUser
 Whether or not to fetch Google+ user profile after signing in.
BOOL useClientIDForURLScheme
 Whether or not the SDK will use the reversed client ID instead of the app's bundle ID as the URL scheme, NO by default.

Member Function Documentation

Returns a shared GPPSignIn instance.

Checks whether the user has either currently signed in or has previous authentication saved in keychain.

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. Note that if the previous authentication was revoked by the user, this method still returns YES but finishedWithAuth:error: callback will indicate that authentication has failed.

- (void) authenticate

Starts the authentication process.

Set attemptSSO to try single sign-on. 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. Note that this method should not be called when the app is starting up, (e.g in application:didFinishLaunchingWithOptions:). Instead use the trySilentAuthentication method.

- (BOOL) handleURL: (NSURL *)  url
sourceApplication: (NSString *)  sourceApplication
annotation: (id)  annotation 

This method should be called from your UIApplicationDelegate's application:openURL:sourceApplication:annotation.

Returns YES if GPPSignIn handled this URL. Also see handleURL:sourceApplication:annotation: in GPPURLHandler.

- (void) signOut

Removes the OAuth 2.0 token from the keychain.

- (void) disconnect

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.

- (GTLServicePlus *) plusService

Gets a service object authenticated as the current user.

The service object can execute queries, for example, to get list of people that is visible to this app. The user must be signed in for this method to work.


Property Documentation

- (GTMOAuth2Authentication*) authentication [read, assign]

The authentication object for the current user, or nil if there is currently no logged in user.

- (NSString*) idToken [read, assign]

A JSON Web Token identifying the user.

Send this token to your server to authenticate the user on the server. For more information on JWTs, see http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-05

- (NSString*) userID [read, assign]

The Google user ID.

It is only available if shouldFetchGoogleUserID is set and either trySilentAuthentication or authenticate has been completed successfully.

- (NSString*) userEmail [read, assign]

The Google user's email.

It is only available if shouldFetchGoogleUserEmail is set and either trySilentAuthentication or authenticate has been completed successfully.

- (GTLPlusPerson*) googlePlusUser [read, assign]

The Google+ user profile.

It is only available if shouldFetchGooglePlusUser is set and either trySilentAuthentication or authenticate has been completed successfully.

- (id<GPPSignInDelegate>) delegate [read, write, assign]

The object to be notified when authentication is finished.

- (NSString*) clientID [read, write, copy]

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.

- (NSString*) homeServerClientID [read, write, copy]

The client ID of the home web server.

This will be returned as the audience property of the JWT ID token. For more info on the ID token: https://developers.google.com/accounts/docs/OAuth2Login#obtainuserinfo

- (NSString*) openIDRealm [read, write, copy]

The OpenID2 realm of the home web server.

This allows Google to include the user's OpenID Identifier in the JWT ID token.

- (NSArray*) scopes [read, write, copy]

The API scopes requested by the app in an array of NSStrings.

The default value is @[@"https://www.googleapis.com/auth/plus.login"].

- (BOOL) attemptSSO [read, write, assign]

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.

- (NSString*) language [read, write, copy]

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.

- (NSString*) keychainName [read, write, copy]

Name of the keychain to save the sign-in state.

Only set if a custom name needs to be used.

- (NSArray*) actions [read, write, copy]

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.

- (BOOL) shouldFetchGoogleUserEmail [read, write, assign]

Whether or not to fetch user email after signing in.

The email is saved in the GTMOAuth2Authentication object. Note that using this flag automatically adds "https://www.googleapis.com/auth/userinfo.email" scope to the request.

- (BOOL) shouldFetchGoogleUserID [read, write, assign]

Whether or not to fetch user ID after signing in.

The ID can be retrieved by googleUserID after user has been authenticated. Note that using this flag automatically adds "https://www.googleapis.com/auth/userinfo.profile" scope to the request if a scope that provides user ID is not already present.

- (BOOL) shouldFetchGooglePlusUser [read, write, assign]

Whether or not to fetch Google+ user profile after signing in.

The user profile object can be retrieved by googlePlusUser after user has been authenticated. Note that using this flag automatically adds "https://www.googleapis.com/auth/plus.me" scope to the request if needed.

- (BOOL) useClientIDForURLScheme [read, write, assign]

Whether or not the SDK will use the reversed client ID instead of the app's bundle ID as the URL scheme, NO by default.

If the flag is YES, in addition to register the bundle ID for the URL schemes it handles, e.g. "com.MyDomain.MyApp://", the app also needs to register the dot-reversed clientID for URL scheme, e.g. "com.googleusercontent.apps.1234567890-asdfghjkl://".

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.