b75e57fe31
Implementato il flusso OAuth2 grant_type=client_credentials come alternativa al flusso password gia' esistente per l'autenticazione Salesforce server-to-server. La modifica e' completamente retrocompatibile (default rimane Password). ## Dettaglio modifiche ### CredentialManager/Models/CredentialModels.cs - Aggiunto enum SalesforceGrantType con valori Password e ClientCredentials - Aggiunta proprieta' GrantType (default: Password) su RestApiCredential - Aggiunta proprieta' GrantType (default: Password) su SalesforceCredential ### DataConnection/REST/Configuration/RestServiceOptions.cs - Aggiunta proprieta' SalesforceGrantType per passare il tipo di flusso al client ### DataConnection/REST/Implementations/SalesforceServiceClient.cs - Iniettato ILogger<SalesforceServiceClient> con NullLogger come fallback - Sostituiti ~165 Console.WriteLine con chiamate ILogger appropriate (LogDebug per dettagli, LogInformation per eventi, LogWarning/LogError per problemi) - Aggiunto AuthenticateWithPasswordAsync: incapsula il flusso grant_type=password - Aggiunto AuthenticateWithClientCredentialsAsync: implementa grant_type=client_credentials (richiede solo ClientId e ClientSecret, nessun utente, URL My Domain obbligatorio) - Aggiunto SendTokenRequestAsync: helper condiviso per la POST al token endpoint - Aggiornato AuthenticateAsync() override: instrada al flusso corretto in base a GrantType - Rimosso modificatore static da NormalizeNumericValues (usava _logger, causava CS0120) ### Data_Coupler/Services/DataConnectionFactory.cs - Mappatura del campo GrantType dalle opzioni Salesforce a RestServiceOptions - Passaggio dell'ILogger al costruttore di SalesforceServiceClient ### CredentialManager/Services/CredentialService.cs - SaveRestApiCredentialAsync (blocco Salesforce): serializza GrantType in AdditionalParameters - SaveSalesforceCredentialAsync: aggiunto GrantType nel dizionario iniziale - MapToRestApiCredential: deserializza GrantType da AdditionalParameters con Enum.TryParse - MapToSalesforceCredential: idem per il tipo SalesforceCredential ### DataConnection/CredentialManagement/Services/DataConnectionCredentialService.cs - TestSalesforceOAuthLogin aggiornato: per ClientCredentials invia solo client_id e client_secret (senza username/password/security_token); per Password comportamento invariato ### Data_Coupler/Pages/CredentialManagement.razor - Aggiunto dropdown 'Tipo di Autenticazione OAuth2' nella sezione Salesforce - I campi Username, Password e Security Token vengono nascosti quando si seleziona il flusso ClientCredentials - Alert contestuale: warning My Domain URL per ClientCredentials, info per Password - GrantType propagato correttamente in EditRestApiCredential e TestRestApiConnectionFromModal ### AGENTS.md - Aggiunta sezione di documentazione per la nuova funzionalita' OAuth2 client_credentials
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
namespace DataConnection.REST.Configuration
|
|
{
|
|
/// <summary>
|
|
/// Configuration options for a REST service client.
|
|
/// </summary>
|
|
public class RestServiceOptions
|
|
{
|
|
/// <summary>
|
|
/// Base URL of the REST service.
|
|
/// </summary>
|
|
public string? BaseUrl { get; set; }
|
|
|
|
/// <summary>
|
|
/// API Key, if required.
|
|
/// </summary>
|
|
public string? ApiKey { get; set; }
|
|
|
|
/// <summary>
|
|
/// Username for authentication, if required.
|
|
/// </summary>
|
|
public string? Username { get; set; }
|
|
|
|
/// <summary>
|
|
/// Password for authentication, if required.
|
|
/// </summary>
|
|
public string? Password { get; set; }
|
|
|
|
/// <summary>
|
|
/// Authentication token (e.g., Bearer token), if required.
|
|
/// </summary>
|
|
public string? AuthToken { get; set; }
|
|
|
|
/// <summary>
|
|
/// Timeout for requests in seconds.
|
|
/// </summary>
|
|
public int TimeoutSeconds { get; set; } = 100; // Default timeout
|
|
|
|
/// <summary>
|
|
/// Gets or sets a value indicating whether to ignore SSL certificate errors.
|
|
/// Use with caution, especially in production environments.
|
|
/// </summary>
|
|
public bool IgnoreSslErrors { get; set; } = false;
|
|
|
|
/// <summary>
|
|
/// Salesforce OAuth2 grant type. Default: Password (retrocompatibile).
|
|
/// ClientCredentials = server-to-server, senza utente.
|
|
/// </summary>
|
|
public CredentialManager.Models.SalesforceGrantType SalesforceGrantType { get; set; }
|
|
= CredentialManager.Models.SalesforceGrantType.Password;
|
|
}
|
|
}
|