刷新失败,出现 403 禁止访问错误.刷新令牌已吊销或过期



我正在使用Microsoft.WindowsAzure.MobileServices.MobileServiceClient使用Google帐户对用户进行身份验证,并使用Xamarin.Auth.AccountStore来存储令牌。首次运行应用时,帐户存储为空。用户使用 MobileServiceClient.LoginAsync 方法登录。

client.LoginAsync(_mainActivity, 
MobileServiceAuthenticationProvider.Google, "myjobdiary", new Dictionary<string, string>
{
{ "access_type", "offline" }
});

一切正常,用户已授权并使用方法存储令牌。

public void StoreTokenInSecureStore(MobileServiceUser user)
{
var account = new Account(user.UserId);
account.Properties.Add("token", user.MobileServiceAuthenticationToken);
_accountStore.Save(account, "myjobdiary");
}

现在我重新启动我的应用程序并使用方法从帐户存储中获取用户。

public MobileServiceUser RetrieveTokenFromSecureStore()
{
var accounts = _accountStore.FindAccountsForService("myjobdiary");
if (accounts != null)
{
foreach (var acct in accounts)
{
if (acct.Properties.TryGetValue("token", out string token))
{
return new MobileServiceUser(acct.Username)
{
MobileServiceAuthenticationToken = token
};
}
}
}
return null;
}

检索到的用户设置为已使用的移动服务客户端。现在我想使用 MobileServiceClient.RefreshUserAsync 方法刷新令牌。异常"刷新失败,出现 403 禁止访问错误。刷新令牌已吊销或已过期。 具有 Azure 刷新令牌的移动应用

return await client.LoginAsync(
_mainActivity, MobileServiceAuthenticationProvider.Google, "myjobdiary", new Dictionary<string, string>
{
{ "access_type", "offline" },
{ "prompt", "consent" }
});

最新更新