3
我使用GoogleAuthUtil.getToken()在Android應用中獲取一次性代碼,然後將其發送到我們的服務器。我們的服務器然後交換這個訪問令牌,並使用它來獲取用戶的電子郵件。Google API來自GoogleAuthUtil.getToken的一次性授權碼無效授予
這似乎工作。但是,如果我做到以下幾點:
- 獲取一次性代碼
- 它發送到服務器
- 消費它,並驗證用戶
- 擦拭Android應用數據(使它忘記認證
- 獲取一次性代碼
第二一次性代碼實際上是等同於第一。
這已經已經被使用一次,所以想換取一個訪問令牌的第二遍的時候服務器得到以下錯誤:
Error:"invalid_grant", Description:"Invalid code.[Email:
Token Record:
Token: "4/aQQ_nbklfajrilawjvlkasjvVMD.AMsaNNC-gdsai3gJDIAvajvkrelwiDDI"
IssueDomain: "123456789012-1231231564adsafdas1f23a45fd6sad2.apps.googleusercontent.com"
IssueTimeSec: 1387110988
ExpirationTime: 1387111588
TokenUsage: 3
Scope: "https://www.googleapis.com/auth/plus.login"
Scope: "https://www.googleapis.com/auth/userinfo.email"
Scope: "https://www.googleapis.com/auth/plus.moments.write"
Scope: "https://www.googleapis.com/auth/plus.me"
Scope: "https://www.googleapis.com/auth/plus.profile.agerange.read"
Scope: "https://www.googleapis.com/auth/plus.profile.language.read"
Scope: "https://www.googleapis.com/auth/plus.circles.members.read"
ServiceInfo {
ServiceId: 123
Info <
[13245678] <
0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a
>
>
}
ServiceInfo {
ServiceId: 226
Info <
[security_lso_auth_oauth2.EarlyIssuedTokenProto] <
auto_approved: false
access_token: "fd12.a.Afdsa1eawfdsa2avi_f1ds2af15eaw61f2ag45a6v8-1f3ds2af5ew6a12-ad5A"
refresh_token: "2/da4ge5a4f5dsav-fsa54fe4wa5f_dfasenU-dsaddew"
>
>
}
Revoked: true
AuthorizedBy: 0x1234567890
OAuthCallbackUrl: "urn:accounts.google.com:api_auth:programmatic:virtual_redirect_uri"
OfflineAccess: true
RevokeOnPasswordChange: true
ClientManagedRevocation: false
InBundle: true
]", Uri:""
(敏感數據被替換爲隨機值)
我看到ExpirationTime尚未達到(10分鐘有效),但是不應該只從GoogleAuthUtil.getToken()返回一次性代碼?
這在部署情況下可能不是問題,因爲大多數用戶只會登錄一次,所以這是否是設計?我應該以任何方式在服務器上處理它,或者只是接受這會發生?
查看註釋#2來回答這裏:http://stackoverflow.com/questions/18959880/is-googleauthutil-gettoken-thread-safe不知道他的來源是什麼,但。 – soulseekah
謝謝。似乎是這樣,它被緩存。也許有點奇怪,因爲服務器無論如何都不能再次接受這個令牌。 – jnystad
對於客戶端在10分鐘內安裝兩次的罕見情況,您的服務器應向客戶端返回一個很好的錯誤:「稍等一會,再試一次,速度太快......」。 – soulseekah