Advertisement
Guest User

Untitled

a guest
May 15th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 occurred.
  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.   // Indicates an Enterprise Mobility Management related error has occurred.
  37.   kGIDSignInErrorCodeEMM = -6,
  38. };
  39.  
  40. // A protocol implemented by the delegate of |GIDSignIn| to receive a refresh token or an error.
  41. @protocol GIDSignInDelegate <NSObject>
  42.  
  43. // The sign-in flow has finished and was successful if |error| is |nil|.
  44. - (void)signIn:(GIDSignIn *)signIn
  45.     didSignInForUser:(GIDGoogleUser *)user
  46.            withError:(NSError *)error;
  47.  
  48. @optional
  49.  
  50. // Finished disconnecting |user| from the app successfully if |error| is |nil|.
  51. - (void)signIn:(GIDSignIn *)signIn
  52.     didDisconnectWithUser:(GIDGoogleUser *)user
  53.                 withError:(NSError *)error;
  54.  
  55. @end
  56.  
  57. // A protocol which may be implemented by consumers of |GIDSignIn| to be notified of when
  58. // GIDSignIn has finished dispatching the sign-in request.
  59. //
  60. // This protocol is useful for developers who implement their own "Sign In with Google" button.
  61. // Because there may be a brief delay between when the call to |signIn| is made, and when the
  62. // app switch occurs, it is best practice to have the UI react to the user's input by displaying
  63. // a spinner or other UI element. The |signInWillDispatch| method should be used to
  64. // stop or hide the spinner.
  65. @protocol GIDSignInUIDelegate <NSObject>
  66.  
  67. @optional
  68.  
  69. // The sign-in flow has finished selecting how to proceed, and the UI should no longer display
  70. // a spinner or other "please wait" element.
  71. - (void)signInWillDispatch:(GIDSignIn *)signIn error:(NSError *)error;
  72.  
  73. // If implemented, this method will be invoked when sign in needs to display a view controller.
  74. // The view controller should be displayed modally (via UIViewController's |presentViewController|
  75. // method, and not pushed unto a navigation controller's stack.
  76. - (void)signIn:(GIDSignIn *)signIn presentViewController:(UIViewController *)viewController;
  77.  
  78. // If implemented, this method will be invoked when sign in needs to dismiss a view controller.
  79. // Typically, this should be implemented by calling |dismissViewController| on the passed
  80. // view controller.
  81. - (void)signIn:(GIDSignIn *)signIn dismissViewController:(UIViewController *)viewController;
  82.  
  83. @end
  84.  
  85. // This class signs the user in with Google. It also provides single sign-on via a capable Google
  86. // app if one is installed.
  87. //
  88. // For reference, please see "Google Sign-In for iOS" at
  89. // https://developers.google.com/identity/sign-in/ios
  90. // Here is sample code to use |GIDSignIn|:
  91. // 1. Get a reference to the |GIDSignIn| shared instance:
  92. //    GIDSignIn *signIn = [GIDSignIn sharedInstance];
  93. // 2. Set the OAuth 2.0 scopes you want to request:
  94. //    [signIn setScopes:[NSArray arrayWithObject:@"https://www.googleapis.com/auth/plus.login"]];
  95. // 3. Call [signIn setDelegate:self];
  96. // 4. Set up delegate method |signIn:didSignInForUser:withError:|.
  97. // 5. Call |handleURL| on the shared instance from |application:openUrl:...| in your app delegate.
  98. // 6. Call |signIn| on the shared instance;
  99. @interface GIDSignIn : NSObject
  100.  
  101. // The authentication object for the current user, or |nil| if there is currently no logged in user.
  102. @property(nonatomic, readonly) GIDGoogleUser *currentUser;
  103.  
  104. // The object to be notified when authentication is finished.
  105. @property(nonatomic, weak) id<GIDSignInDelegate> delegate;
  106.  
  107. // The object to be notified when sign in dispatch selection is finished.
  108. @property(nonatomic, weak) id<GIDSignInUIDelegate> uiDelegate;
  109.  
  110. // The client ID of the app from the Google APIs console.  Must set for sign-in to work.
  111. @property(nonatomic, copy) NSString *clientID;
  112.  
  113. // The API scopes requested by the app in an array of |NSString|s.  The default value is |@[]|.
  114. //
  115. // This property is optional. If you set it, set it before calling |signIn|.
  116. @property(nonatomic, copy) NSArray *scopes;
  117.  
  118. // Whether or not to fetch basic profile data after signing in. The data is saved in the
  119. // |GIDGoogleUser.profileData| object.
  120. //
  121. // Setting the flag will add "email" and "profile" to scopes.
  122. // Defaults to |YES|.
  123. @property(nonatomic, assign) BOOL shouldFetchBasicProfile;
  124.  
  125. // The language for sign-in, in the form of ISO 639-1 language code optionally followed by a dash
  126. // and ISO 3166-1 alpha-2 region code, such as |@"it"| or |@"pt-PT"|. Only set if different from
  127. // system default.
  128. //
  129. // This property is optional. If you set it, set it before calling |signIn|.
  130. @property(nonatomic, copy) NSString *language;
  131.  
  132. // The login hint to the authorization server, for example the user's ID, or email address,
  133. // to be prefilled if possible.
  134. //
  135. // This property is optional. If you set it, set it before calling |signIn|.
  136. @property(nonatomic, copy) NSString *loginHint;
  137.  
  138. // The client ID of the home web server.  This will be returned as the |audience| property of the
  139. // OpenID Connect ID token.  For more info on the ID token:
  140. // https://developers.google.com/identity/sign-in/ios/backend-auth
  141. //
  142. // This property is optional. If you set it, set it before calling |signIn|.
  143. @property(nonatomic, copy) NSString *serverClientID;
  144.  
  145. // The OpenID2 realm of the home web server. This allows Google to include the user's OpenID
  146. // Identifier in the OpenID Connect ID token.
  147. //
  148. // This property is optional. If you set it, set it before calling |signIn|.
  149. @property(nonatomic, copy) NSString *openIDRealm;
  150.  
  151. // The Google Apps domain to which users must belong to sign in.  To verify, check |GIDGoogleUser|'s
  152. // |hostedDomain| property.
  153. //
  154. // This property is optional. If you set it, set it before calling |signIn|.
  155. @property(nonatomic, copy) NSString *hostedDomain;
  156.  
  157. // Returns a shared |GIDSignIn| instance.
  158. + (GIDSignIn *)sharedInstance;
  159.  
  160. // This method should be called from your |UIApplicationDelegate|'s
  161. // |application:openURL:sourceApplication:annotation|.  Returns |YES| if |GIDSignIn| handled this
  162. // URL.
  163. - (BOOL)handleURL:(NSURL *)url
  164.     sourceApplication:(NSString *)sourceApplication
  165.            annotation:(id)annotation;
  166.  
  167. // Checks whether the user has either currently signed in or has previous authentication saved in
  168. // keychain.
  169. - (BOOL)hasAuthInKeychain;
  170.  
  171. // Attempts to sign in a previously authenticated user without interaction.  The delegate will be
  172. // called at the end of this process indicating success or failure.
  173. - (void)signInSilently;
  174.  
  175. // Starts the sign-in process.  The delegate will be called at the end of this process.  Note that
  176. // this method should not be called when the app is starting up, (e.g in
  177. // application:didFinishLaunchingWithOptions:). Instead use the |signInSilently| method.
  178. - (void)signIn;
  179.  
  180. // Marks current user as being in the signed out state.
  181. - (void)signOut;
  182.  
  183. // Disconnects the current user from the app and revokes previous authentication. If the operation
  184. // succeeds, the OAuth 2.0 token is also removed from keychain.
  185. - (void)disconnect;
  186.  
  187. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement