Today's Menu  Portugal
journal and plan nutrition
GIDSignIn.h
Go to the documentation of this file.
1 /*
2  * GIDSignIn.h
3  * Google Sign-In iOS SDK
4  *
5  * Copyright 2012 Google Inc.
6  *
7  * Use of this SDK is subject to the Google APIs Terms of Service:
8  * https://developers.google.com/terms/
9  */
10 
11 #import <Foundation/Foundation.h>
12 #import <UIKit/UIKit.h>
13 
14 @class GIDGoogleUser;
15 @class GIDSignIn;
16 
17 // The error domain for NSErrors returned by the Google Identity SDK.
18 extern NSString *const kGIDSignInErrorDomain;
19 
20 // A list of potential error codes returned from the Google Identity SDK.
21 typedef NS_ENUM(NSInteger, GIDSignInErrorCode) {
22  // Indicates an unknown error has occured.
23  kGIDSignInErrorCodeUnknown = -1,
24  // Indicates a problem reading or writing to the application keychain.
25  kGIDSignInErrorCodeKeychain = -2,
26  // Indicates no appropriate applications are installed on the user's device which can handle
27  // sign-in. This code will only ever be returned if using webview and switching to browser have
28  // both been disabled.
29  kGIDSignInErrorCodeNoSignInHandlersInstalled = -3,
30  // Indicates there are no auth tokens in the keychain. This error code will be returned by
31  // signInSilently if the user has never signed in before with the given scopes, or if they have
32  // since signed out.
33  kGIDSignInErrorCodeHasNoAuthInKeychain = -4,
34  // Indicates the user canceled the sign in request.
35  kGIDSignInErrorCodeCanceled = -5,
36 };
37 
38 // A protocol implemented by the delegate of |GIDSignIn| to receive a refresh token or an error.
39 @protocol GIDSignInDelegate <NSObject>
40 
41 // The sign-in flow has finished and was successful if |error| is |nil|.
42 - (void)signIn:(GIDSignIn *)signIn
43  didSignInForUser:(GIDGoogleUser *)user
44  withError:(NSError *)error;
45 
46 @optional
47 
48 // Finished disconnecting |user| from the app successfully if |error| is |nil|.
49 - (void)signIn:(GIDSignIn *)signIn
50  didDisconnectWithUser:(GIDGoogleUser *)user
51  withError:(NSError *)error;
52 
53 @end
54 
55 // A protocol which may be implemented by consumers of |GIDSignIn| to be notified of when
56 // GIDSignIn has finished dispatching the sign-in request.
57 //
58 // This protocol is useful for developers who implement their own "Sign In with Google" button.
59 // Because there may be a brief delay between when the call to |signIn| is made, and when the
60 // app switch occurs, it is best practice to have the UI react to the user's input by displaying
61 // a spinner or other UI element. The |signInWillDispatch| method should be used to
62 // stop or hide the spinner.
63 @protocol GIDSignInUIDelegate <NSObject>
64 
65 @optional
66 
67 // The sign-in flow has finished selecting how to proceed, and the UI should no longer display
68 // a spinner or other "please wait" element.
69 - (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error;
70 
71 // If implemented, this method will be invoked when sign in needs to display a view controller.
72 // The view controller should be displayed modally (via UIViewController's |presentViewController|
73 // method, and not pushed unto a navigation controller's stack.
74 - (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController;
75 
76 // If implemented, this method will be invoked when sign in needs to dismiss a view controller.
77 // Typically, this should be implemented by calling |dismissViewController| on the passed
78 // view controller.
79 - (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController;
80 
81 @end
82 
83 // This class signs the user in with Google. It also provides single sign-on via a capable Google
84 // app if one is installed.
85 //
86 // For reference, please see "Google Sign-In for iOS" at
87 // https://developers.google.com/identity/sign-in/ios
88 // Here is sample code to use |GIDSignIn|:
89 // 1. Get a reference to the |GIDSignIn| shared instance:
90 // GIDSignIn *signIn = [GIDSignIn sharedInstance];
91 // 2. Set the OAuth 2.0 scopes you want to request:
92 // [signIn setScopes:[NSArray arrayWithObject:@"https://www.googleapis.com/auth/plus.login"]];
93 // 3. Call [signIn setDelegate:self];
94 // 4. Set up delegate method |signIn:didSignInForUser:withError:|.
95 // 5. Call |handleURL| on the shared instance from |application:openUrl:...| in your app delegate.
96 // 6. Call |signIn| on the shared instance;
97 @interface GIDSignIn : NSObject
98 
99 // The authentication object for the current user, or |nil| if there is currently no logged in user.
100 @property(nonatomic, readonly) GIDGoogleUser *currentUser;
101 
102 // The object to be notified when authentication is finished.
103 @property(nonatomic, weak) id<GIDSignInDelegate> delegate;
104 
105 // The object to be notified when sign in dispatch selection is finished.
106 @property(nonatomic, weak) id<GIDSignInUIDelegate> uiDelegate;
107 
108 // The client ID of the app from the Google APIs console. Must set for sign-in to work.
109 @property(nonatomic, copy) NSString *clientID;
110 
111 // The API scopes requested by the app in an array of |NSString|s. The default value is |@[]|.
112 //
113 // This property is optional. If you set it, set it before calling |signIn|.
114 @property(nonatomic, copy) NSArray *scopes;
115 
116 // Whether or not to fetch basic profile data after signing in. The data is saved in the
117 // |GIDGoogleUser.profileData| object.
118 //
119 // Setting the flag will add "email" and "profile" to scopes.
120 // Defaults to |YES|.
121 @property(nonatomic, assign) BOOL shouldFetchBasicProfile;
122 
123 // The language for sign-in, in the form of ISO 639-1 language code optionally followed by a dash
124 // and ISO 3166-1 alpha-2 region code, such as |@"it"| or |@"pt-PT"|. Only set if different from
125 // system default.
126 //
127 // This property is optional. If you set it, set it before calling |signIn|.
128 @property(nonatomic, copy) NSString *language;
129 
130 // The login hint to the authorization server, for example the user's ID, or email address,
131 // to be prefilled if possible.
132 //
133 // This property is optional. If you set it, set it before calling |signIn|.
134 @property(nonatomic, copy) NSString *loginHint;
135 
136 // The client ID of the home web server. This will be returned as the |audience| property of the
137 // OpenID Connect ID token. For more info on the ID token:
138 // https://developers.google.com/identity/sign-in/ios/backend-auth
139 //
140 // This property is optional. If you set it, set it before calling |signIn|.
141 @property(nonatomic, copy) NSString *serverClientID;
142 
143 // The OpenID2 realm of the home web server. This allows Google to include the user's OpenID
144 // Identifier in the OpenID Connect ID token.
145 //
146 // This property is optional. If you set it, set it before calling |signIn|.
147 @property(nonatomic, copy) NSString *openIDRealm;
148 
149 // The Google Apps domain to which users must belong to sign in. To verify, check |GIDGoogleUser|'s
150 // |hostedDomain| property.
151 //
152 // This property is optional. If you set it, set it before calling |signIn|.
153 @property(nonatomic, copy) NSString *hostedDomain;
154 
155 // Returns a shared |GIDSignIn| instance.
157 
158 // This method should be called from your |UIApplicationDelegate|'s
159 // |application:openURL:sourceApplication:annotation|. Returns |YES| if |GIDSignIn| handled this
160 // URL.
161 - (BOOL)handleURL:(NSURL *)url
162  sourceApplication:(NSString *)sourceApplication
163  annotation:(id)annotation;
164 
165 // Checks whether the user has either currently signed in or has previous authentication saved in
166 // keychain.
167 - (BOOL)hasAuthInKeychain;
168 
169 // Attempts to sign in a previously authenticated user without interaction. The delegate will be
170 // called at the end of this process indicating success or failure.
171 - (void)signInSilently;
172 
173 // Starts the sign-in process. The delegate will be called at the end of this process. Note that
174 // this method should not be called when the app is starting up, (e.g in
175 // application:didFinishLaunchingWithOptions:). Instead use the |signInSilently| method.
176 - (void)signIn;
177 
178 // Marks current user as being in the signed out state.
179 - (void)signOut;
180 
181 // Disconnects the current user from the app and revokes previous authentication. If the operation
182 // succeeds, the OAuth 2.0 token is also removed from keychain.
183 - (void)disconnect;
184 
185 @end
id< GIDSignInDelegate > delegate
Definition: GIDSignIn.h:103
NSString * clientID
Definition: GIDSignIn.h:109
void signOut()
NSString * openIDRealm
Definition: GIDSignIn.h:147
NSArray * scopes
Definition: GIDSignIn.h:114
NSString *const kGIDSignInErrorDomain
id< GIDSignInUIDelegate > uiDelegate
Definition: GIDSignIn.h:106
void signIn()
GIDGoogleUser * currentUser
Definition: GIDSignIn.h:100
NSString * hostedDomain
Definition: GIDSignIn.h:153
void disconnect()
void signInSilently()
GIDSignIn * sharedInstance()
NSString * loginHint
Definition: GIDSignIn.h:134
typedef NS_ENUM(NSInteger, GIDSignInErrorCode)
Definition: GIDSignIn.h:21
NSString * language
Definition: GIDSignIn.h:128
BOOL shouldFetchBasicProfile
Definition: GIDSignIn.h:121
BOOL hasAuthInKeychain()
NSString * serverClientID
Definition: GIDSignIn.h:141