Xia*_* Yu 5 authentication android token google-signin
我将谷歌登录集成到我的项目中,并使用后端服务器进行身份验证。我按照谷歌提供的示例代码进行操作。
这是初始化 google api 客户端的代码:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(Constants.GoogleSignIn.SERVER_CLIENT_ID)
.requestScopes(new Scope(Scopes.EMAIL))
.build();
// Build GoogleAPIClient with the Google Sign-In API and the above options.
client = new GoogleApiClient.Builder(context.getApplicationContext())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
Run Code Online (Sandbox Code Playgroud)
这是获取谷歌登录结果的代码:
private void handleSignInResult(@NonNull GoogleSignInResult result)
{
BHLog.d(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess())
{
GoogleSignInAccount acct = result.getSignInAccount();
if (acct != null)
{
String idToken = acct.getIdToken();
Managers.getLoginManager().loginWithGoogle(idToken);
}
}
else
{
if (listener != null)
{
listener.onGoogleLoginFailed();
}
}
}
Run Code Online (Sandbox Code Playgroud)
与谷歌示例代码几乎相同。
问题是昨天我通过这种方式得到了令牌并且令牌是有效的。今天我仍然以这种方式获取令牌,但它无效。今天和昨天的代币是一样的。我认为令牌昨天已过期,今天我将获得一个新令牌,但我仍然得到了相同的令牌。
然后我使用了另一个设备并获取了令牌。我得到了一个新的,它是有效的。
所以条件很奇怪。不同的设备获得不同的令牌。使用相同的设备总是得到相同的令牌,即使在一天之后也是如此。
有人对这个问题有想法吗?非常感谢。
| 归档时间: |
|
| 查看次数: |
654 次 |
| 最近记录: |