美文网首页
Google登录获取auth code

Google登录获取auth code

作者: 啵啵_long_港 | 来源:发表于2018-11-14 18:07 被阅读50次

    Configure an iOS app project as described in Start Integrating.
    Find your server client ID on the Credentials page of the Google API Console. Your server client ID is a Web application
    type client named something like Web client (Auto-created for Google Sign-in).
    Define your app delegate’s application:didFinishLaunchingWithOptions: method as described above in Enable Sign-In, but for this implementation you will set the serverClientID property as shown below.

    - (BOOL)application:(UIApplication *)application
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
      [GIDSignIn sharedInstance].clientID = @"APP_CLIENT_ID";
      [GIDSignIn sharedInstance].serverClientID = @"SERVER_CLIENT_ID";
    
      // Additional scopes, if any
      // [GIDSignIn sharedInstance].scopes = @[ @"other_scope" ];
    
      return YES;
    }
    

    After the user is signed in, retrieve the one-time authorization code:

    - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user
        withError:(NSError *)error {
      // Perform any operations on signed in user here.
      // user.serverAuthCode now has a server authorization code!
    }
    

    对应链接地址:https://developers.google.cn/identity/sign-in/ios/offline-access
    注意事项:
    获取auth code需要设置serverClientID,serverClientID为Web client (Auto-created for Google Sign-in)对应的ClientID,
    设置完成以后,通过回调方法 - (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user里面的user的serverAuthCode字段获取;如果不设置serverClientID,获取的serverAuthCode将会是空值

    相关文章

      网友评论

          本文标题:Google登录获取auth code

          本文链接:https://www.haomeiwen.com/subject/ijajfqtx.html