当我尝试通过 Android 使用 Google+ 登录授权 Azure 移动服务时,出现以下错误。
com.microsoft.windowsazure.mobileservices.MobileServiceException:
{"code":401,"error":"Error: Invalid token format. Expected Envelope.Claims.Signature."}
我的授权代码如下。
id_token = GoogleAuthUtil.getToken( ParentActivity.this, user_mailAddress,
"oauth2:" + Scopes.PLUS_LOGIN + " https://www.googleapis.com/auth/plus.profile.emails.read" );
sharedPrefencesHelper.setActiveMailAddress( user_mailAddress );
// sharedPrefencesHelper.setActiveUserName( user_name );
// sharedPrefencesHelper.setActiveUserSurname( user_surname );
sharedPrefencesHelper.setUserConnectStatement( GOOGLE_CONNECT );
} catch ( UserRecoverableAuthException e ) {
startActivityForResult( e.getIntent(), RC_SIGN_IN );
} catch ( IOException | GoogleAuthException e ) {
e.printStackTrace();
}
JsonObject user = new JsonObject();
user.addProperty( "id_token", id_token );
mClient().login( MobileServiceAuthenticationProvider.Google, user, new UserAuthenticationCallback() {
@Override
public void onCompleted( MobileServiceUser user, Exception exception, ServiceFilterResponse response ) {
if ( exception == null ) {
syncronUserInformations( user_mailAddress );
} else {
exception.printStackTrace();
// TODO Azure login olurken bir hata
}
}
} );
}
我使用 facebook 完成了授权,并且我使用的是 google play services 7.3.0
最佳答案
id_token
只能通过服务器端 Web 登录获取。您使用的范围会为您提供 OAuth token ,该 token 与 id_token
不同。要获取 id_token
,您需要使用 Web 应用程序客户端 ID 来使用不同的范围。
// Create 'Client ID for web application' at https://console.developers.google.com
String web_client_id = "1234567890-abcdefghijklmnopqrstuvq.apps.googleusercontent.com";
id_token = GoogleAuthUtil.getToken( ParentActivity.this, user_mailAddress,
"audience:server:client_id:" + web_client_id);
既然您有了实际的 id_token
值,其余代码就应该可以工作了。
关于android - 使用 Google 登录的 Azure 移动授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30240722/