Files
plugin-library/Assets/00.StaryEvo/Runtime/Utility/RemoteServicesWithAuth.cs
2025-03-31 14:57:48 +08:00

60 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/****************************************************
文件RemoteServicesWithAuth.cs
作者xosmo_
邮箱:
日期2025/3/31 14:39:5
功能:
*****************************************************/
using YooAsset;
using System.Collections;
using Stary.Evo;
using UnityEngine.Networking;
public class RemoteServicesWithAuth : IRemoteServices
{
private readonly string _defaultHostServer;
private readonly string _fallbackHostServer;
private string _authToken;
private string _authServiceUrl;
public string CurrentToken { get; private set; }
public RemoteServicesWithAuth(string defaultHostServer,
string fallbackHostServer,
string authToken,
string authServiceUrl)
{
_defaultHostServer = defaultHostServer;
_fallbackHostServer = fallbackHostServer;
_authToken = authToken;
_authServiceUrl = authServiceUrl;
RefreshToken();
}
private void RefreshToken()
{
// 这里实现具体的token刷新逻辑
CurrentToken = _authToken; // 简单示例直接使用初始token
// 实际项目应该通过authServiceUrl获取新token
}
string IRemoteServices.GetRemoteMainURL(string fileName)
{
// 在原始URL后附加鉴权参数
return $"{_defaultHostServer}/{fileName}?token={CurrentToken}";
}
public string GetRemoteFallbackURL(string fileName)
{
return $"{_fallbackHostServer}/{fileName}?token={CurrentToken}";
}
// UnityWebRequest CreateRequest(string url)
// {
// var request = base.CreateRequest(url);
// request.SetRequestHeader("Authorization", $"Bearer {CurrentToken}");
// return request;
// }
}