GIDSignIn Class

GIDSignIn Class Reference

Overview

This class signs the user in with Google.

It also provides single sign-on via a capable Google app if one is installed.

For reference, please see "Google Sign-In for iOS" at https://developers.google.com/identity/sign-in/ios Here is sample code to use GIDSignIn:

  1. Get a reference to the GIDSignIn shared instance: GIDSignIn *signIn = [GIDSignIn 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 signIn:didSignInForUser:withError:.
  5. Call handleURL on the shared instance from application:openUrl:... in your app delegate.
  6. Call signIn on the shared instance;

Inherits NSObject.

Instance Method Summary

(BOOL) - handleURL:sourceApplication:annotation:
 This method should be called from your UIApplicationDelegate's application:openURL:sourceApplication:annotation. More...
 
(BOOL) - hasAuthInKeychain
 Checks whether the user has either currently signed in or has previous authentication saved in keychain. More...
 
(void) - signInSilently
 Attempts to sign in a previously authenticated user without interaction. More...
 
(void) - signIn
 Starts the sign-in process. More...
 
(void) - signOut
 Marks current user as being in the signed out state. More...
 
(void) - disconnect
 Disconnects the current user from the app and revokes previous authentication. More...
 

Class Method Summary

(GIDSignIn *) + sharedInstance
 Returns a shared GIDSignIn instance. More...
 

Property Summary

GIDGoogleUsercurrentUser
 The authentication object for the current user, or nil if there is currently no logged in user. More...
 
id< GIDSignInDelegatedelegate
 The object to be notified when authentication is finished. More...
 
id< GIDSignInUIDelegateuiDelegate
 The object to be notified when sign in dispatch selection is finished. More...
 
NSString * clientID
 The client ID of the app from the Google APIs console. Must set for sign-in to work. More...
 
NSArray * scopes
 The API scopes requested by the app in an array of NSStrings. More...
 
BOOL shouldFetchBasicProfile
 Whether or not to fetch basic profile data after signing in. More...
 
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". More...
 
NSString * loginHint
 The login hint to the authorization server, for example the user's ID, or email address, to be prefilled if possible. More...
 
NSString * serverClientID
 The client ID of the home web server. More...
 
NSString * openIDRealm
 The OpenID2 realm of the home web server. More...
 
NSString * hostedDomain
 The Google Apps domain to which users must belong to sign in. More...
 

Method Detail

+ (GIDSignIn *) sharedInstance

Returns a shared GIDSignIn instance.

- (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 GIDSignIn handled this URL.

- (BOOL) hasAuthInKeychain

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

- (void) signInSilently

Attempts to sign in a previously authenticated user without interaction.

The delegate will be called at the end of this process indicating success or failure.

- (void) signIn

Starts the sign-in process.

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 signInSilently method.

- (void) signOut

Marks current user as being in the signed out state.

- (void) disconnect

Disconnects the current user from the app and revokes previous authentication.

If the operation succeeds, the OAuth 2.0 token is also removed from keychain.

Property Detail

- (GIDGoogleUser*) currentUser
readnonatomicassign

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

- (id<GIDSignInDelegate>) delegate
readwritenonatomicweak

The object to be notified when authentication is finished.

- (id<GIDSignInUIDelegate>) uiDelegate
readwritenonatomicweak

The object to be notified when sign in dispatch selection is finished.

- (NSString*) clientID
readwritenonatomiccopy

The client ID of the app from the Google APIs console. Must set for sign-in to work.

- (NSArray*) scopes
readwritenonatomiccopy

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

The default value is @[].

This property is optional. If you set it, set it before calling signIn.

- (BOOL) shouldFetchBasicProfile
readwritenonatomicassign

Whether or not to fetch basic profile data after signing in.

The data is saved in the GIDGoogleUser.profileData object.

Setting the flag will add "email" and "profile" to scopes. Defaults to YES.

- (NSString*) language
readwritenonatomiccopy

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.

This property is optional. If you set it, set it before calling signIn.

- (NSString*) loginHint
readwritenonatomiccopy

The login hint to the authorization server, for example the user's ID, or email address, to be prefilled if possible.

This property is optional. If you set it, set it before calling signIn.

- (NSString*) serverClientID
readwritenonatomiccopy

The client ID of the home web server.

This will be returned as the audience property of the OpenID Connect ID token. For more info on the ID token: https://developers.google.com/identity/sign-in/ios/backend-auth

This property is optional. If you set it, set it before calling signIn.

- (NSString*) openIDRealm
readwritenonatomiccopy

The OpenID2 realm of the home web server.

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

This property is optional. If you set it, set it before calling signIn.

- (NSString*) hostedDomain
readwritenonatomiccopy

The Google Apps domain to which users must belong to sign in.

To verify, check GIDGoogleUser's hostedDomain property.

This property is optional. If you set it, set it before calling signIn.