我试图与后端服务器进行身份验证的用户的Android:的Android getServerAuthCode()不需要额外的权限
- 应用程序调用
getServerAuthCode()
和转发使用HTTPS我们的BE - 的BE交流的授权码访问令牌的服务器授权代码使用GoogleAuthorizationCodeTokenRequest
- BE将访问令牌传递给www.googleapis.com/games/v1/applications返回playerId(这就是我真正需要的,我不在乎电子邮件和其他用户信息)
该过程这里概述:
和这里
如果我使用2017年的指令,我可以在不请求任何额外权限的情况下获取ServerAuthCode()。唯一的权限是:Google Play /管理您的游戏活动。这可以通过指定GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN
通过使用play-service 10.2.1来实现。由于第三方依赖关系,我无法使用10.2.1。
2016年文章解释了如何getServerAuthCode()
的“老”的方式(使用播放服务9.6.1),但我不能没有要求一些额外的权限度日。
如果我这样做,我得到了问“知道你是在谷歌谁”:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestServerAuthCode(serverClientId)
.requestScopes(Games.SCOPE_GAMES)
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
...
protected void onActivityResult(int request, int response, Intent data) {
super.onActivityResult(request, response, data);
if (request == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
if (result.isSuccess()) {
GoogleSignInAccount acct = result.getSignInAccount();
String authCode = acct.getServerAuthCode();
}
如果我从GSO删除.requestServerAuthCode(serverClientId)
,AUTHCODE为空。
另一件事我想(只使用Games.API登录):
mGoogleApiClient = new GoogleApiClient.Builder(this, this, this)
.addApi(Games.API)
.build();
...
Games.GetServerAuthCodeResult result = Games.getGamesServerAuthCode(mGoogleApiClient, serverClinetId).await();
if (result.getStatus().isSuccess()) {
String authCode = result.getCode();
我得到result.getStatus().isSuccess()=false
和result.getStatus().getStatusMessage()
回报STATUS_CLIENT_RECONNECT_REQUIRED (2)
。在日志中我看到:
[GetToken] GetToken failed with status code: NeedPermission
04-10 14:27:41.764: W/GamesServerAuthCodeOp(5775): Failed to retrieve the server auth code
04-10 14:27:41.764: W/GamesServerAuthCodeOp(5775): com.google.android.gms.auth.UserRecoverableAuthException: NeedPermission
Finnaly,我能够达到最好的是“仅仅”获得“查看您的基本个人信息”权限这样做:
Scope scope = new Scope("https://www.googleapis.com/auth/userinfo.profile");
mGoogleApiClient = new GoogleApiClient.Builder(this, this, this)
.addApi(Games.API)
.addScope(scope)
.build();
因此,要回顾一下 - 我想使用9.6.1获得服务器授权代码,而不会被提示输入任何额外的权限(例如在2017年的文章中使用10.2.1使用DEFAULT_GAMES_SIGN_IN
)。
是否有任何范围我可以使用,将给我的服务器授权码(获取playerId)而不要求额外的权限?
谢谢AL。 - 我还注意到,在Google的“我的帐户”/“连接的应用程序和网站”中,旧应用程序都需要这些权限,但新的权限不需要。 –