android - 使用 Google 登录的 Azure 移动授权错误

标签 android azure

当我尝试通过 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/

相关文章:

android - R.string.close ,close 无法解析或不是字段

android - 如何使用 XML 在 Android 上放大我的图像?

azure - 按 ADF 中的管道参数过滤管道运行

azure - 在azure云服务中工作的多个实例

python - Azure函数Python导入错误: libpython3. 6m.so.1.0

azure - 有没有办法指定目标日志文件供微软监控代理监听并从代码中获取日志?

java - 短信发送错误

android - 不同设备上的准确时间

Azure Cloud Shell - 无法识别术语 'Stop-AzureVM'

android - OnClick 监听器应用于整个卡片 View ,而不仅仅是 textView