简体   繁体   English

带有 Google+ API 的 Android 应用程序:客户端 ID 还是 Android ID?

[英]Android app with Google+ API: Client ID or Android ID?

I'm trying to develop an application that makes use of some basic Google+ Apis.我正在尝试开发一个使用一些基本的 Google+ API 的应用程序。 The app request a token from Google that then upload on my server and my server check for its validation with Google.该应用程序从 Google 请求令牌,然后将其上传到我的服务器上,我的服务器检查其与 Google 的验证。 What I don't understand (I'm a bit confused) is what's the difference between Client ID for Web application and Client ID for Android application in Google Developers Console.我不明白(我有点困惑)是 Google Developers Console 中 Web 应用程序的客户端 ID 和 Android 应用程序的客户端 ID 之间的区别是什么。 I've tried both of them on the Android app and both work (successfully obtained a token).我已经在 Android 应用程序上尝试了它们,并且都可以工作(成功获得令牌)。 Obviously, when using the Web Client ID, my SCOPE that I pass using GoogleAuthUtil.getToken() is different from the one using Android Client ID.显然,在使用 Web 客户端 ID 时,我使用GoogleAuthUtil.getToken()传递的 SCOPE 与使用 Android 客户端 ID 的范围不同。 So, what's the difference between them?那么,它们之间有什么区别呢? I think that I should go for the Android Client ID, but I'd like to know the really differences.我认为我应该选择 Android 客户端 ID,但我想知道真正的区别。

On client side I use:在客户端,我使用:

final String token = GoogleAuthUtil.getToken(mContext, userEmail, G_PLUS_SCOPE);

Where G_PLUS_SCOPE = oauth2:https://www.googleapis.com/auth/plus.me其中G_PLUS_SCOPE = oauth2:https://www.googleapis.com/auth/plus.me

On server side, I check with Google with this code:在服务器端,我使用以下代码与 Google 核对:

GoogleIdToken token = GoogleIdToken.parse(mJFactory, getRequest().getAuthToken());

        if (mVerifier.verify(token)) {
            GoogleIdToken.Payload tempPayload = token.getPayload();
            if (!tempPayload.getAudience().equals(mAudience)) {
                problem = "Audience mismatch";
                errorMessage = new ErrorMessage(ErrorCodes.AUDIENCE_MISMATCH,problem,null);
                mResponse = new ErrorResponse( errorMessage);
            }
            else if (!mClientIDs.contains(tempPayload.getAuthorizedParty())) {
                problem = "Client ID mismatch";
                errorMessage = new ErrorMessage(ErrorCodes.CLIENT_ID_MISMATCH,problem,null);
                mResponse = new ErrorResponse(errorMessage);
            }

I also don't understand what's the exact value of mAudience.我也不明白 mAudience 的确切价值是什么。 Do I need to put the Client ID as mAudience?我是否需要将客户端 ID 设置为 mAudience? And, is the mClientIDs the array containing all the key (Including the Android client ID key)?并且,mClientIDs 是包含所有密钥(包括 Android 客户端 ID 密钥)的数组吗?

Thanks for your help谢谢你的帮助

EDIT: Following http://android-developers.blogspot.it/2013/01/verifying-back-end-calls-from-android.html I've read that the Audience is the Client ID for Web Application and the mIds are all the ID for installed application (1 for me because I've only Android).编辑:在http://android-developers.blogspot.it/2013/01/verifying-back-end-calls-from-android.html之后,我读到 Audience 是 Web 应用程序的客户端 ID,mIds 是已安装应用程序的所有 ID(对我来说是 1,因为我只有 Android)。 But I'm not sure if this is the right way of thinking it for every case.但我不确定这是否是对每种情况的正确思考方式。

I don't have answer to your question but I found this blog which can help you out:我没有回答你的问题,但我发现这个博客可以帮助你:

http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/ http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/

I hope this helps you.我希望这可以帮助你。

Technically the audience is the client ID which the ID token is intended to authenticate the user to, where the authorized party is the client ID which the ID token was issued to:从技术上讲,受众是 ID 令牌用于对用户进行身份验证的客户端 ID,其中授权方是 ID 令牌颁发给的客户端 ID:

http://openid.net/specs/openid-connect-core-1_0.html#IDTokenhttp://openid.net/specs/openid-connect-core-1_0.html#IDToken

You should verify both when both are provided.当两者都提供时,您应该验证两者。 When requesting an ID Token from your Android app, you should use the Client ID of your server to make the request.从您的 Android 应用程序请求 ID 令牌时,您应该使用服务器的客户端 ID 发出请求。 Your server should then verify that it is the audience for the token when it receives it from your Android client.然后,您的服务器应在从您的 Android 客户端接收令牌时验证它是令牌的受众。

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

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