[Feature] Aggiunto supporto OAuth2 client_credentials per Salesforce
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
This commit is contained in:
@@ -22,6 +22,27 @@ public enum RestServiceType
|
||||
Salesforce
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tipo di flusso OAuth2 per Salesforce
|
||||
/// </summary>
|
||||
public enum SalesforceGrantType
|
||||
{
|
||||
/// <summary>
|
||||
/// Flusso Username/Password (grant_type=password).
|
||||
/// Richiede: ClientId, ClientSecret, Username, Password (+SecurityToken se non IP-trusted).
|
||||
/// URL di login: https://login.salesforce.com o https://test.salesforce.com.
|
||||
/// </summary>
|
||||
Password,
|
||||
|
||||
/// <summary>
|
||||
/// Flusso Client Credentials (grant_type=client_credentials) — server-to-server, senza utente.
|
||||
/// Richiede: ClientId, ClientSecret.
|
||||
/// URL obbligatorio: My Domain URL (es. https://myorg.my.salesforce.com).
|
||||
/// La Connected App deve avere "Enable Client Credentials Flow" attivato e un Integration User assegnato.
|
||||
/// </summary>
|
||||
ClientCredentials
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tipi di database supportati (allineato con DataConnection.Enums.DatabaseType)
|
||||
/// </summary>
|
||||
@@ -106,6 +127,7 @@ public class RestApiCredential
|
||||
public string? ApiVersion { get; set; } = "59.0";
|
||||
public bool IsSandbox { get; set; } = false;
|
||||
public bool UseSoapApi { get; set; } = false;
|
||||
public SalesforceGrantType GrantType { get; set; } = SalesforceGrantType.Password;
|
||||
public string? RefreshToken { get; set; }
|
||||
public string? AccessToken { get; set; }
|
||||
public DateTime? TokenExpiry { get; set; }
|
||||
@@ -145,6 +167,8 @@ public class SalesforceCredential
|
||||
public bool IsSandbox { get; set; } = false; // Se è un ambiente sandbox
|
||||
public int TimeoutSeconds { get; set; } = 120;
|
||||
public bool UseSoapApi { get; set; } = false; // Se usare SOAP invece di REST
|
||||
/// <summary>Tipo di flusso OAuth2 da utilizzare. Default: Password (retrocompatibile).</summary>
|
||||
public SalesforceGrantType GrantType { get; set; } = SalesforceGrantType.Password;
|
||||
public string? RefreshToken { get; set; }
|
||||
public string? AccessToken { get; set; }
|
||||
public DateTime? TokenExpiry { get; set; }
|
||||
|
||||
@@ -233,6 +233,7 @@ public class CredentialService : ICredentialService
|
||||
additionalParams["ApiVersion"] = credential.ApiVersion;
|
||||
additionalParams["IsSandbox"] = credential.IsSandbox.ToString();
|
||||
additionalParams["UseSoapApi"] = credential.UseSoapApi.ToString();
|
||||
additionalParams["GrantType"] = credential.GrantType.ToString();
|
||||
if (!string.IsNullOrEmpty(credential.RefreshToken))
|
||||
additionalParams["RefreshToken"] = credential.RefreshToken;
|
||||
if (!string.IsNullOrEmpty(credential.AccessToken))
|
||||
@@ -523,7 +524,8 @@ public class CredentialService : ICredentialService
|
||||
["SecurityToken"] = credential.SecurityToken,
|
||||
["ApiVersion"] = credential.ApiVersion,
|
||||
["IsSandbox"] = credential.IsSandbox.ToString(),
|
||||
["UseSoapApi"] = credential.UseSoapApi.ToString()
|
||||
["UseSoapApi"] = credential.UseSoapApi.ToString(),
|
||||
["GrantType"] = credential.GrantType.ToString()
|
||||
};
|
||||
|
||||
// Aggiungi ClientId e ClientSecret se forniti
|
||||
@@ -793,6 +795,8 @@ public class CredentialService : ICredentialService
|
||||
credential.IsSandbox = sandbox;
|
||||
if (additionalParams.TryGetValue("UseSoapApi", out var useSoap) && bool.TryParse(useSoap, out var soap))
|
||||
credential.UseSoapApi = soap;
|
||||
if (additionalParams.TryGetValue("GrantType", out var grantTypeStr) && Enum.TryParse<SalesforceGrantType>(grantTypeStr, out var grantType))
|
||||
credential.GrantType = grantType;
|
||||
if (additionalParams.TryGetValue("RefreshToken", out var refreshToken))
|
||||
credential.RefreshToken = refreshToken;
|
||||
if (additionalParams.TryGetValue("AccessToken", out var accessToken))
|
||||
@@ -915,6 +919,8 @@ public class CredentialService : ICredentialService
|
||||
credential.IsSandbox = sandbox;
|
||||
if (additionalParams.TryGetValue("UseSoapApi", out var useSoap) && bool.TryParse(useSoap, out var soap))
|
||||
credential.UseSoapApi = soap;
|
||||
if (additionalParams.TryGetValue("GrantType", out var grantTypeStr) && Enum.TryParse<SalesforceGrantType>(grantTypeStr, out var grantType))
|
||||
credential.GrantType = grantType;
|
||||
if (additionalParams.TryGetValue("RefreshToken", out var refreshToken))
|
||||
credential.RefreshToken = refreshToken;
|
||||
if (additionalParams.TryGetValue("AccessToken", out var accessToken))
|
||||
|
||||
Reference in New Issue
Block a user