简体   繁体   English

Google Play服务身份验证(oauth 2.0)

[英]Google play service authentication (oauth 2.0)

I wish to authenticate users of my android application whith the oauth2 protocole, so as to the user don't need to create a login and password for my app. 我希望使用oauth2 protocole验证我的Android应用程序的用户,以便用户不需要为我的应用程序创建登录名和密码。

To do that, I follow the following tutorial : http://android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html 为此,我遵循以下教程: http//android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html

I've import the google play service sdk sample (in AndroidSDK\\extras\\google\\google_play_services\\samples\\auth), and I have change the scope value. 我导入了google play服务sdk示例(在AndroidSDK \\ extras \\ google \\ google_play_services \\ samples \\ auth中),我更改了范围值。

However, I don't manage to get authentication token... While I've correctly configure my google console API. 但是,我无法获得身份验证令牌...虽然我已正确配置我的谷歌控制台API。

Here is the function calling getToken method : 这是调用getToken方法的函数:

  protected String fetchToken() throws IOException {
      try {
          return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
      } catch (GooglePlayServicesAvailabilityException playEx) {
          // GooglePlayServices.apk is either old, disabled, or not present.
          mActivity.showErrorDialog(playEx.getConnectionStatusCode());
      } catch (UserRecoverableAuthException userRecoverableException) {
          // Unable to authenticate, but the user can fix this.
          // Forward the user to the appropriate activity.
          mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
      } catch (GoogleAuthException fatalException) {
          onError("Unrecoverable error " + fatalException.getMessage(), fatalException);
      } 
      return null;
  }

And here is my scope : audience:server:client_id:MY_CLIENT_ID.apps.googleusercontent.com 这是我的范围: audience:server:client_id:MY_CLIENT_ID.apps.googleusercontent.com

When I try that, I get the following exceptions : 当我尝试时,我得到以下例外:

08-16 17:22:08.471: E/TokenInfoTask(16546): Exception: 
08-16 17:22:08.471: E/TokenInfoTask(16546): com.google.android.gms.auth.GoogleAuthException: Unknown
08-16 17:22:08.471: E/TokenInfoTask(16546):     at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)

You should be using Google+ Sign-In, which Google released in February, because this will get you cross-client authorization and access to more data that you can use to personalize your app. 您应该使用Google 2月份发布的Google+登录,因为这样可以获得跨客户端授权并访问您可用于个性化应用的更多数据。 Behind the scenes, this authorization library uses OAuth 2 to connect to Google services. 在幕后,此授权库使用OAuth 2连接到Google服务。

Some resources to get you started: 一些资源可以帮助您入门:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM