mirror of
				https://github.com/MindWorkAI/AI-Studio.git
				synced 2025-11-04 03:20:21 +00:00 
			
		
		
		
	Fixed another bug related to ERI server authentication when adding new servers
This commit is contained in:
		
							parent
							
								
									0125f48f61
								
							
						
					
					
						commit
						08df79ca73
					
				@ -199,7 +199,7 @@ public sealed class AgentDataSourceSelection (ILogger<AgentDataSourceSelection>
 | 
			
		||||
                        // Call the ERI server to get the server description:
 | 
			
		||||
                        //
 | 
			
		||||
                        using var eriClient = ERIClientFactory.Get(eriDataSource.Version, eriDataSource)!;
 | 
			
		||||
                        var authResponse = await eriClient.AuthenticateAsync(eriDataSource, rustService, token);
 | 
			
		||||
                        var authResponse = await eriClient.AuthenticateAsync(rustService, token);
 | 
			
		||||
                        if (authResponse.Successful)
 | 
			
		||||
                        {
 | 
			
		||||
                            var serverDescriptionResponse = await eriClient.GetDataSourceInfoAsync(token);
 | 
			
		||||
 | 
			
		||||
@ -98,7 +98,7 @@ public partial class DataSourceERI_V1InfoDialog : ComponentBase, IAsyncDisposabl
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            var loginResult = await client.AuthenticateAsync(this.DataSource, this.RustService);
 | 
			
		||||
            var loginResult = await client.AuthenticateAsync(this.RustService);
 | 
			
		||||
            if (!loginResult.Successful)
 | 
			
		||||
            {
 | 
			
		||||
                this.dataIssues.Add(loginResult.Message);
 | 
			
		||||
 | 
			
		||||
@ -188,14 +188,8 @@ public partial class DataSourceERI_V1Dialog : ComponentBase, ISecretId
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var cts = new CancellationTokenSource(TimeSpan.FromSeconds(14));
 | 
			
		||||
            var dataSource = new DataSourceERI_V1
 | 
			
		||||
            {
 | 
			
		||||
                AuthMethod = this.dataAuthMethod,
 | 
			
		||||
                Hostname = this.dataHostname,
 | 
			
		||||
                Port = this.dataPort,
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            using var client = ERIClientFactory.Get(ERIVersion.V1, dataSource);
 | 
			
		||||
            this.DataSource = this.CreateDataSource();
 | 
			
		||||
            using var client = ERIClientFactory.Get(ERIVersion.V1, this.DataSource);
 | 
			
		||||
            if(client is null)
 | 
			
		||||
            {
 | 
			
		||||
                await this.form.Validate();
 | 
			
		||||
@ -217,7 +211,7 @@ public partial class DataSourceERI_V1Dialog : ComponentBase, ISecretId
 | 
			
		||||
 | 
			
		||||
            this.availableAuthMethods = authSchemes.Data!.Select(n => n.AuthMethod).ToList();
 | 
			
		||||
 | 
			
		||||
            var loginResult = await client.AuthenticateAsync(this.DataSource, this.RustService, cts.Token);
 | 
			
		||||
            var loginResult = await client.AuthenticateAsync(this.RustService, cts.Token);
 | 
			
		||||
            if (!loginResult.Successful)
 | 
			
		||||
            {
 | 
			
		||||
                await this.form.Validate();
 | 
			
		||||
 | 
			
		||||
@ -62,7 +62,7 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
 | 
			
		||||
        var logger = Program.SERVICE_PROVIDER.GetRequiredService<ILogger<DataSourceERI_V1>>();
 | 
			
		||||
        
 | 
			
		||||
        using var eriClient = ERIClientFactory.Get(this.Version, this)!;
 | 
			
		||||
        var authResponse = await eriClient.AuthenticateAsync(this, rustService, token);
 | 
			
		||||
        var authResponse = await eriClient.AuthenticateAsync(rustService, token);
 | 
			
		||||
        if (authResponse.Successful)
 | 
			
		||||
        {
 | 
			
		||||
            var retrievalRequest = new RetrievalRequest
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,14 @@
 | 
			
		||||
using System.Text.Json;
 | 
			
		||||
using System.Text.Json.Serialization;
 | 
			
		||||
 | 
			
		||||
using AIStudio.Settings;
 | 
			
		||||
 | 
			
		||||
namespace AIStudio.Tools.ERIClient;
 | 
			
		||||
 | 
			
		||||
public abstract class ERIClientBase(string baseAddress) : IDisposable
 | 
			
		||||
public abstract class ERIClientBase(IERIDataSource dataSource) : IDisposable
 | 
			
		||||
{
 | 
			
		||||
    protected readonly IERIDataSource dataSource = dataSource;
 | 
			
		||||
    
 | 
			
		||||
    protected static readonly JsonSerializerOptions JSON_OPTIONS = new()
 | 
			
		||||
    {
 | 
			
		||||
        WriteIndented = true,
 | 
			
		||||
@ -21,7 +25,7 @@ public abstract class ERIClientBase(string baseAddress) : IDisposable
 | 
			
		||||
    
 | 
			
		||||
    protected readonly HttpClient httpClient = new()
 | 
			
		||||
    {
 | 
			
		||||
        BaseAddress = new Uri(baseAddress),
 | 
			
		||||
        BaseAddress = new Uri($"{dataSource.Hostname}:{dataSource.Port}"),
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
    protected string securityToken = string.Empty;
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,7 @@ public static class ERIClientFactory
 | 
			
		||||
{
 | 
			
		||||
    public static IERIClient? Get(ERIVersion version, IERIDataSource dataSource) => version switch
 | 
			
		||||
    {
 | 
			
		||||
        ERIVersion.V1 => new ERIClientV1($"{dataSource.Hostname}:{dataSource.Port}"),
 | 
			
		||||
        ERIVersion.V1 => new ERIClientV1(dataSource),
 | 
			
		||||
        
 | 
			
		||||
        _ => null
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,7 @@ using AIStudio.Tools.Services;
 | 
			
		||||
 | 
			
		||||
namespace AIStudio.Tools.ERIClient;
 | 
			
		||||
 | 
			
		||||
public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIClient
 | 
			
		||||
public class ERIClientV1(IERIDataSource dataSource) : ERIClientBase(dataSource), IERIClient
 | 
			
		||||
{
 | 
			
		||||
    #region Implementation of IERIClient
 | 
			
		||||
 | 
			
		||||
@ -59,13 +59,13 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public async Task<APIResponse<AuthResponse>> AuthenticateAsync(IERIDataSource dataSource, RustService rustService, CancellationToken cancellationToken = default)
 | 
			
		||||
    public async Task<APIResponse<AuthResponse>> AuthenticateAsync(RustService rustService, CancellationToken cancellationToken = default)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            var authMethod = dataSource.AuthMethod;
 | 
			
		||||
            var username = dataSource.Username;
 | 
			
		||||
            switch (dataSource.AuthMethod)
 | 
			
		||||
            var authMethod = this.dataSource.AuthMethod;
 | 
			
		||||
            var username = this.dataSource.Username;
 | 
			
		||||
            switch (this.dataSource.AuthMethod)
 | 
			
		||||
            {
 | 
			
		||||
                case AuthMethod.NONE:
 | 
			
		||||
                    using (var request = new HttpRequestMessage(HttpMethod.Post, $"auth?authMethod={authMethod}"))
 | 
			
		||||
@ -99,7 +99,7 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
 | 
			
		||||
                    }
 | 
			
		||||
            
 | 
			
		||||
                case AuthMethod.USERNAME_PASSWORD:
 | 
			
		||||
                    var passwordResponse = await rustService.GetSecret(dataSource);
 | 
			
		||||
                    var passwordResponse = await rustService.GetSecret(this.dataSource);
 | 
			
		||||
                    if (!passwordResponse.Success)
 | 
			
		||||
                    {
 | 
			
		||||
                        return new()
 | 
			
		||||
@ -146,7 +146,7 @@ public class ERIClientV1(string baseAddress) : ERIClientBase(baseAddress), IERIC
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                case AuthMethod.TOKEN:
 | 
			
		||||
                    var tokenResponse = await rustService.GetSecret(dataSource);
 | 
			
		||||
                    var tokenResponse = await rustService.GetSecret(this.dataSource);
 | 
			
		||||
                    if (!tokenResponse.Success)
 | 
			
		||||
                    {
 | 
			
		||||
                        return new()
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,3 @@
 | 
			
		||||
using AIStudio.Settings;
 | 
			
		||||
using AIStudio.Tools.ERIClient.DataModel;
 | 
			
		||||
using AIStudio.Tools.Services;
 | 
			
		||||
 | 
			
		||||
@ -19,11 +18,10 @@ public interface IERIClient : IDisposable
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Authenticate the user to the ERI server.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    /// <param name="dataSource">The data source to use.</param>
 | 
			
		||||
    /// <param name="rustService">The Rust service.</param>
 | 
			
		||||
    /// <param name="cancellationToken">The cancellation token.</param>
 | 
			
		||||
    /// <returns>The authentication response.</returns>
 | 
			
		||||
    public Task<APIResponse<AuthResponse>> AuthenticateAsync(IERIDataSource dataSource, RustService rustService, CancellationToken cancellationToken = default);
 | 
			
		||||
    public Task<APIResponse<AuthResponse>> AuthenticateAsync(RustService rustService, CancellationToken cancellationToken = default);
 | 
			
		||||
    
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Retrieves the data source information from the ERI server.
 | 
			
		||||
 | 
			
		||||
@ -113,7 +113,7 @@ public sealed class DataSourceService
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            this.logger.LogInformation($"Authenticating with ERI source '{source.Name}' (id={source.Id})...");
 | 
			
		||||
            var loginResult = await client.AuthenticateAsync(eriSource, this.rustService, cancellationTokenSource.Token);
 | 
			
		||||
            var loginResult = await client.AuthenticateAsync(this.rustService, cancellationTokenSource.Token);
 | 
			
		||||
            if (!loginResult.Successful)
 | 
			
		||||
            {
 | 
			
		||||
                this.logger.LogWarning($"Authentication with ERI source '{source.Name}' (id={source.Id}) failed. We skip this source. Reason: {loginResult.Message}");
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								app/MindWork AI Studio/wwwroot/changelog/v0.9.34.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								app/MindWork AI Studio/wwwroot/changelog/v0.9.34.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
			
		||||
# v0.9.34, build 209 (2025-03-11 xx:xx UTC)
 | 
			
		||||
- Fixed another bug related to ERI server authentication when adding new servers.
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user