我試圖與後端服務器進行身份驗證的用戶的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的「我的帳戶」/「連接的應用程序和網站」中,舊應用程序都需要這些權限,但新的權限不需要。 –