Compare commits

...

2 Commits

Author SHA1 Message Date
wangyingpan a33dcd30bc 🎨 调整代码排版 2024-07-01 15:37:46 +08:00
wangyingpan ac3c348a93 🐛 本地令牌 "确认交易" 时,当access_token 过期时使用refresh_token 刷新当前 access_token 以保持会话 2024-07-01 14:59:46 +08:00
2 changed files with 47 additions and 5 deletions
@@ -1,8 +1,7 @@
using AppResources = BD.WTTS.Client.Resources.Strings;
using BD.SteamClient.Models;
using BD.SteamClient.Services;
using WinAuth;
using AppResources = BD.WTTS.Client.Resources.Strings;
using WSteamClient = WinAuth.SteamClient;
namespace BD.WTTS.UI.ViewModels;
@@ -73,11 +72,55 @@ public sealed partial class SteamTradePageViewModel : WindowViewModel
}
else
{
IsLogged = true;
IsLogged = await CheckAndRefreshToken();
await GetConfirmations(_steamClient);
}
}
public async ValueTask<bool> CheckAndRefreshToken()
{
IsLoading = true;
// 不具备检查条件 没有保持的会话信息
if (_steamClient == null)
return false;
if (_steamClient.Session == null || _steamAuthenticator == null)
return false;
// token 依旧有效 直接返回
if (!_steamClient.Session.IsAccessTokenExpired())
return true;
try
{
// 是否有 refresh token
string? refreshToken = _steamClient.Session?.RefreshToken;
if (string.IsNullOrWhiteSpace(refreshToken))
return false;
var session = _steamClient.Session;
// 刷新 access token (有效时间同样为一天)
await session!.RefreshAccessToken(_steamClient);
// 使用原先获取的具体派生类型 修改数据
_steamAuthenticator.SessionData = session.ToString();
// 通过原始令牌引用保存信息
await AuthenticatorHelper.SaveAuthenticator(_authenticatorDto)
.ConfigureAwait(false);
return true;
}
finally
{
IsLoading = false;
}
}
public async Task Refresh()
{
if (_steamClient?.IsLoggedIn() == true)
@@ -314,7 +357,6 @@ public sealed partial class SteamTradePageViewModel : WindowViewModel
// Content = Strings.LocalAuth_AuthTrade_MessageBoxTip_.Format(statusText)
// }, statusText, isCancelButton: true, isDialog: false))
//{
Toast.Show(ToastIcon.Info, Strings.LocalAuth_AuthTrade_ConfirmTip_.Format(statusText));
if (!await ChangeTradeStatus(status, selectedList)) return;