Boa tarde, Tenho uma aplicação .net hospedada no serviço de aplicações e estou tentando fazer uma integração com um banco via api, localmente funciona, o token é gerado corretamente, porém quando é hospedada no azure não funciona, o trecho de código está abaixo.
O certificado é carregado corretamente para a pasta e está valido.
private string GetAccessToken()
{
try
{
// Configurações
var authUrl = _config["Boleto:Url_Auth"];
var clientId = _config["Boleto:Client_Id"];
string senhaPfx = _config["Boleto:SenhaCertPfx"];
var clientSecret = clientId;
string diretorioDoProjeto = AppDomain.CurrentDomain.BaseDirectory;
string caminhoDaPastaReports = Path.Combine(diretorioDoProjeto, "Certificado");
string caminhoDoArquivo = Path.Combine(caminhoDaPastaReports, "certificado.pfx");
var certPath = Path.Combine(caminhoDoArquivo);
var certificate = new X509Certificate2(certPath, senhaPfx);
// Configurar as opções do RestClient para usar o certificado
var options = new RestClientOptions($"{authUrl}/URL")
{
MaxTimeout = -1,
ClientCertificates = new X509CertificateCollection { certificate }
};
// Criar o cliente e a requisição
var client = new RestClient(options);
var request = new RestRequest("", Method.Post);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
// request.AddHeader("Cookie", "TS01dfa94a=017a3a183bb25bfbf7003004f5db3bb7575362a5772fc45c9e184e8341f3b7eb6d5672ac206c2d56ed38ed9b1975820b7df1a8f09d83ac5c3cf219ef822da6d3a5cdc3af3d0d8d766358e9da05f9fd2842bd702cea; 447fb61b35fb4f9d67cbcbbebfb597fc=cfd190176d94003bbcc0bf16258c7a42; TS012629b2=017a3a183b144ba5d392ab920903f46eae8a801a4c2fc45c9e184e8341f3b7eb6d5672ac206c2d56ed38ed9b1975820b7df1a8f09d306ac3c5ae37a3ca2e0ea74c2d34e57f");
request.AddParameter("grant_type", "client_credentials");
request.AddParameter("client_id", clientId);
request.AddParameter("scope", "boletos_inclusao boletos_consulta boletos_alteracao");
// Executar a requisição
RestResponse response = client.Execute(request);
if (response.IsSuccessful)
{
dynamic result = JsonConvert.DeserializeObject(response.Content.ToString());
// Retornar o token de acesso
return result.access_token;
}
else
{
return null;
}
}
catch (Exception ex)
{
var e = ex;
throw;
}
}
E recebo o seguinte erro: System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> System.ComponentModel.Win32Exception (0x8009030D): The credentials supplied to the package were not recognized at System.Net.SSPIWrapper.AcquireCredentialsHandle(ISSPIInterface secModule, String package, CredentialUse intent, SCH_CREDENTIALS* scc) at System.Net.Security.SslStreamPal.AcquireCredentialsHandle(CredentialUse credUsage, SCH_CREDENTIALS* secureCredential) at System.Net.Security.SslStreamPal.AcquireCredentialsHandleSchCredentials(SslAuthenticationOptions authOptions) at System.Net.Security.SslStreamPal.AcquireCredentialsHandle(SslAuthenticationOptions sslAuthenticationOptions, Boolean newCredentialsRequested) --- End of inner exception stack trace --- at System.Net.Security.SslStreamPal.AcquireCredentialsHandle(SslAuthenticationOptions sslAuthenticationOptions, Boolean newCredentialsRequested) at System.Net.Security.SslStream.AcquireCredentialsHandle(SslAuthenticationOptions sslAuthenticationOptions, Boolean newCredentialsRequested) at System.Net.Security.SslStream.AcquireClientCredentials(Byte[]& thumbPrint, Boolean newCredentialsRequested) at System.Net.Security.SslStream.GenerateToken(ReadOnlySpan1 inputBuffer, Byte[]& output) at System.Net.Security.SslStream.NextMessage(ReadOnlySpan
1 incomingBuffer) at System.Net.Security.SslStream.ProcessBlob(Int32 frameSize) at System.Net.Security.SslStream.ReceiveBlobAsyncTIOAdapter at System.Net.Security.SslStream.ForceAuthenticationAsyncTIOAdapter at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem) at System.Threading.Tasks.TaskCompletionSourceWithCancellation1.WaitWithCancellationAsync(CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.HttpConnectionWaiter
1.WaitForConnectionAsync(Boolean async, CancellationToken requestCancellationToken) at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at RestSharp.RestClient.ExecuteRequestAsync(RestRequest request, CancellationToken cancellationToken)
Alguém já teve esse problema?