尝试重新使用auth令牌将xamarin应用程序连接到azure失败



首次登录成功:

public static MobileServiceClient MOBILE = new MobileServiceClient("https://myapp.azure-mobile.net/",myApplicationKey);
MobileServiceAuthenticationProvider GOOGLEPROVIDER = MobileServiceAuthenticationProvider.Google;
private async Task Connect() {
    var USER = await MOBILE.LoginAsync(this, GOOGLEPROVIDER);
    var CACHE = new Dictionary<string, string> { { "token", USER.MobileServiceAuthenticationToken } };
    var ACCOUNT = new Account(USER.UserId, CACHE);
    var STORE = AccountStore.Create(this);
    STORE.Save(ACCOUNT, "Google");
}

但是,这种在没有登录页面的情况下重新使用令牌进行连接的尝试失败了:

public async Task Reconnect() {
    var STORE = AccountStore.Create(this);
    var token = STORE.FindAccountsForService("Google").ToArray()[0].Properties["token"];
    // token seems ok
    var jsonToken = new JObject();
    jsonToken.Add("access_token", token);
    var USER = await MOBILE.LoginAsync(MobileServiceAuthenticationProvider.Google, jsonToken); // BOOM!
}

并显示以下消息:"POST Google登录请求必须在请求正文中同时包含代码和id_token。"

我做错了什么?

您在代码中使用的令牌,即。var CACHE=新字典{{"token",USER.MobileServiceAuthenticationToken}};

上面的MobileServiceAuthenticationToken是MobileServices特有的令牌,不能在LoginAsync方法中使用(LoginAync方法需要Google OAuth令牌。)

请参阅此使用Xamarin Android 的Azure移动服务从Google Api获取用户信息

相关内容

最新更新