【发布时间】:2023-03-10 18:21:01
【问题描述】:
我正在使用 Microsoft.WindowsAzure.MobileServices.MobileServiceClient 使用其 Google 帐户和 Xamarin.Auth.AccountStore 对用户进行身份验证以存储令牌。当应用程序第一次运行时,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。现在我想使用 MobileServiceClient.RefreshUserAsync 方法刷新令牌。异常'刷新失败,出现 403 禁止错误。刷新令牌已被撤销或过期。发生。 mobile apps with azure, refresh tokens
【问题讨论】:
-
当我调用 .auth/me 时,我能够看到 refresh_token。我该怎么办?
标签: c# xamarin.android azure-mobile-services google-authentication refresh-token