Config: account tweaks, UTF-8 fix, update server url
This commit is contained in:
parent
6412afbfbb
commit
4f8deea8e0
@ -32,9 +32,11 @@ namespace Pal.Client.Configuration
|
|||||||
throw new InvalidOperationException("invalid account id format");
|
throw new InvalidOperationException("invalid account id format");
|
||||||
}
|
}
|
||||||
|
|
||||||
public string EncryptedId { get; init; } = null!;
|
[JsonPropertyName("Id")]
|
||||||
|
[JsonInclude]
|
||||||
|
public string EncryptedId { get; private set; } = null!;
|
||||||
|
|
||||||
public string Server { get; set; } = null!;
|
public string Server { get; init; } = null!;
|
||||||
|
|
||||||
[JsonIgnore] public bool IsUsable => DecryptAccountId(EncryptedId) != null;
|
[JsonIgnore] public bool IsUsable => DecryptAccountId(EncryptedId) != null;
|
||||||
|
|
||||||
@ -56,7 +58,7 @@ namespace Pal.Client.Configuration
|
|||||||
ConfigurationData.Entropy, DataProtectionScope.CurrentUser);
|
ConfigurationData.Entropy, DataProtectionScope.CurrentUser);
|
||||||
return new Guid(guidBytes);
|
return new Guid(guidBytes);
|
||||||
}
|
}
|
||||||
catch (CryptographicException e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
PluginLog.Verbose(e, $"Could not load account id {id}");
|
PluginLog.Verbose(e, $"Could not load account id {id}");
|
||||||
return null;
|
return null;
|
||||||
@ -71,10 +73,21 @@ namespace Pal.Client.Configuration
|
|||||||
DataProtectionScope.CurrentUser);
|
DataProtectionScope.CurrentUser);
|
||||||
return $"s:{Convert.ToBase64String(guidBytes)}";
|
return $"s:{Convert.ToBase64String(guidBytes)}";
|
||||||
}
|
}
|
||||||
catch (CryptographicException)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
return g.ToString();
|
return g.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool EncryptIfNeeded()
|
||||||
|
{
|
||||||
|
if (Guid.TryParse(EncryptedId, out Guid g))
|
||||||
|
{
|
||||||
|
string oldId = EncryptedId;
|
||||||
|
EncryptedId = EncryptAccountId(g);
|
||||||
|
return oldId != EncryptedId;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
using System;
|
using System.IO;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Dalamud.Logging;
|
using Dalamud.Logging;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Newtonsoft.Json;
|
using NJson = Newtonsoft.Json;
|
||||||
using JsonSerializer = System.Text.Json.JsonSerializer;
|
|
||||||
|
|
||||||
namespace Pal.Client.Configuration
|
namespace Pal.Client.Configuration
|
||||||
{
|
{
|
||||||
@ -31,7 +30,7 @@ namespace Pal.Client.Configuration
|
|||||||
PluginLog.Information("Migrating config file from v1-v6 format");
|
PluginLog.Information("Migrating config file from v1-v6 format");
|
||||||
|
|
||||||
ConfigurationV1 configurationV1 =
|
ConfigurationV1 configurationV1 =
|
||||||
JsonConvert.DeserializeObject<ConfigurationV1>(
|
NJson.JsonConvert.DeserializeObject<ConfigurationV1>(
|
||||||
File.ReadAllText(_pluginInterface.ConfigFile.FullName)) ?? new ConfigurationV1();
|
File.ReadAllText(_pluginInterface.ConfigFile.FullName)) ?? new ConfigurationV1();
|
||||||
configurationV1.Migrate();
|
configurationV1.Migrate();
|
||||||
configurationV1.Save();
|
configurationV1.Save();
|
||||||
@ -52,7 +51,7 @@ namespace Pal.Client.Configuration
|
|||||||
public void Save(IConfigurationInConfigDirectory config)
|
public void Save(IConfigurationInConfigDirectory config)
|
||||||
{
|
{
|
||||||
File.WriteAllText(ConfigPath,
|
File.WriteAllText(ConfigPath,
|
||||||
JsonSerializer.Serialize(config, config.GetType(), new JsonSerializerOptions { WriteIndented = true }),
|
JsonSerializer.Serialize(config, config.GetType(), new JsonSerializerOptions { WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }),
|
||||||
Encoding.UTF8);
|
Encoding.UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +93,8 @@ namespace Pal.Client.Configuration
|
|||||||
if (string.IsNullOrEmpty(accountId))
|
if (string.IsNullOrEmpty(accountId))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
IAccountConfiguration newAccount = v7.CreateAccount(server, accountId);
|
string serverName = server.Replace(".μ.tv", ".liza.sh");
|
||||||
|
IAccountConfiguration newAccount = v7.CreateAccount(serverName, accountId);
|
||||||
newAccount.CachedRoles = oldAccount.CachedRoles.ToList();
|
newAccount.CachedRoles = oldAccount.CachedRoles.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,9 +72,9 @@ namespace Pal.Client.Configuration
|
|||||||
|
|
||||||
public interface IAccountConfiguration
|
public interface IAccountConfiguration
|
||||||
{
|
{
|
||||||
public bool IsUsable { get; }
|
bool IsUsable { get; }
|
||||||
public string Server { get; }
|
string Server { get; }
|
||||||
public Guid AccountId { get; }
|
Guid AccountId { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is taken from the JWT, and is only refreshed on a successful login.
|
/// This is taken from the JWT, and is only refreshed on a successful login.
|
||||||
@ -84,6 +84,8 @@ namespace Pal.Client.Configuration
|
|||||||
/// This has no impact on what roles the JWT actually contains, but is just to make it
|
/// This has no impact on what roles the JWT actually contains, but is just to make it
|
||||||
/// easier to draw a consistent UI. The server will still reject unauthorized calls.
|
/// easier to draw a consistent UI. The server will still reject unauthorized calls.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> CachedRoles { get; set; }
|
List<string> CachedRoles { get; set; }
|
||||||
|
|
||||||
|
bool EncryptIfNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ namespace Pal.Client.Net
|
|||||||
var createAccountReply = await accountClient.CreateAccountAsync(new CreateAccountRequest(), headers: UnauthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken);
|
var createAccountReply = await accountClient.CreateAccountAsync(new CreateAccountRequest(), headers: UnauthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken);
|
||||||
if (createAccountReply.Success)
|
if (createAccountReply.Success)
|
||||||
{
|
{
|
||||||
if (Guid.TryParse(createAccountReply.AccountId, out Guid accountId))
|
if (!Guid.TryParse(createAccountReply.AccountId, out Guid accountId))
|
||||||
throw new InvalidOperationException("invalid account id returned");
|
throw new InvalidOperationException("invalid account id returned");
|
||||||
|
|
||||||
configuredAccount = Service.Configuration.CreateAccount(RemoteUrl, accountId);
|
configuredAccount = Service.Configuration.CreateAccount(RemoteUrl, accountId);
|
||||||
@ -92,7 +92,16 @@ namespace Pal.Client.Net
|
|||||||
PluginLog.Information($"TryConnect: Login successful with account id: {configuredAccount.AccountId.ToPartialId()}");
|
PluginLog.Information($"TryConnect: Login successful with account id: {configuredAccount.AccountId.ToPartialId()}");
|
||||||
_loginInfo = new LoginInfo(loginReply.AuthToken);
|
_loginInfo = new LoginInfo(loginReply.AuthToken);
|
||||||
|
|
||||||
configuredAccount.CachedRoles = _loginInfo.Claims?.Roles.ToList() ?? new List<string>();
|
bool save = configuredAccount.EncryptIfNeeded();
|
||||||
|
|
||||||
|
List<string> newRoles = _loginInfo.Claims?.Roles.ToList() ?? new();
|
||||||
|
if (!newRoles.SequenceEqual(configuredAccount.CachedRoles))
|
||||||
|
{
|
||||||
|
configuredAccount.CachedRoles = newRoles;
|
||||||
|
save = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (save)
|
||||||
Service.ConfigurationManager.Save(Service.Configuration);
|
Service.ConfigurationManager.Save(Service.Configuration);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -14,7 +14,7 @@ namespace Pal.Client.Net
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
public const string RemoteUrl = "http://localhost:5145";
|
public const string RemoteUrl = "http://localhost:5145";
|
||||||
#else
|
#else
|
||||||
public const string RemoteUrl = "https://pal.μ.tv";
|
public const string RemoteUrl = "https://pal.liza.sh";
|
||||||
#endif
|
#endif
|
||||||
private readonly string _userAgent = $"{typeof(RemoteApi).Assembly.GetName().Name?.Replace(" ", "")}/{typeof(RemoteApi).Assembly.GetName().Version?.ToString(2)}";
|
private readonly string _userAgent = $"{typeof(RemoteApi).Assembly.GetName().Name?.Replace(" ", "")}/{typeof(RemoteApi).Assembly.GetName().Version?.ToString(2)}";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user