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

时间:2013-12-09 21:25:32

标签: authentication azure xamarin

此初始登录成功:

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。”

我在这里错了什么?

1 个答案:

答案 0 :(得分:1)

您在代码中使用的令牌,即。     var CACHE = new Dictionary {{“token”,USER.MobileServiceAuthenticationToken}};

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

请参阅此Get User Info from Google Api Using Azure Mobile Services for Xamarin Android