Jump to content
pssDP

SSL error 1409442E using TRestClient OAuth2

Recommended Posts

While trying to get the token from an OAuth2 authorization web site, I get "error:1409442E:ssl3_read_bytes:tlsv1 alert protocol version"
I am using the code below using Delphi XE7.
As stated in some other posts, if using Indy, I can use SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2] to try to solve the problem, but this is not the case because I am using the REST Client Library, and I can not find any equivalent.
In another post here suggests to use TRESTCLient.SecurityProtocols, but I can not see this property in my XE7.
The OpenSSL libraries are version 1.0.2q.
Any ideas on how to solve this problem ?

 


  // OAuth
  OAuth2Authenticator1.ClientId := 'xxxxxwssks8gc4xxxxxx';
  OAuth2Authenticator1.ClientSecret := 'zzzzzzz9lb604zzzzz';
  OAuth2Authenticator1.ResponseType := TOAuth2ResponseType.rtCODE;
  OAuth2Authenticator1.TokenType := TOAuth2TokenType.ttBEARER;

  // Client
  RestClient1.Accept := 'application/json, text/plain; q=0.9, text/html;q=0.8,';
  RestClient1.AcceptCharset := 'UTF-8, *;q=0.8';
  RestClient1.AcceptEncoding := 'identity';
  RestClient1.ContentType := 'application/x-www-form-urlencoded';
  RestClient1.Authenticator := OAuth2Authenticator1;
  RestClient1.BaseURL := 'https://www.myweb.es/token';
  RestClient1.RaiseExceptionOn500 := False;
  RestClient1.Params.Clear;
  RestClient1.HandleRedirects := True;

  // Request
  RestRequest1.Client := RestClient1;
  RestRequest1.Method := TRESTRequestMethod.rmPOST;
  RestRequest1.Accept:='application/json';
  RestRequest1.Params.AddItem('grant_type', 'client_credentials', TRESTRequestParameterKind.pkGETorPOST);
  RestRequest1.Params.AddItem('scope', 'integration', TRESTRequestParameterKind.pkGETorPOST);
  RestRequest1.Response := RestResponse1;
  RestRequest1.SynchronizedEvents := False;

  // Response
  RestResponse1.ContentType := 'application/json';

Try
  RestRequest1.Execute;
Except
  on E: Exception do
  begin
    ShowMessage('B01 ERR: ' + E.Message);
  end;

 

Share this post


Link to post

Hmmm, on docwiki it say 

Quote

TRESTClient is built to hide any HTTP-related exceptions as long as the exception can be represented by a standard HTTP code. The client only throws 'hard' exceptions, connection failures, and so on. The framework operates on the newer TNetHTTPClient, which is based on system HTTP client sockets. This allows it to leverage the OS's ability to automatically resolve and deal with SSL/TLS/HTTPS.

But if XE7 has same feature....

 

Could you try install fresh Delphi Trial in a VM to test if compiled run good?

Share this post


Link to post

There is no .HttpClientComponent in the System XE7 Library, nor I can find any substitute that can help for that matter.

So,, you are right about using a more recent Delphi version.

Prepare a Delphi Trial in a VM is a hard and expensive work if finally the solution is to purchase the last Delphi version for commercial development, so first I will try to find another cheaper solution.

Also I see that Indy has no OAuth2 interface, so this is not a solution also.

 

Share this post


Link to post
32 minutes ago, pssDP said:

Prepare a Delphi Trial in a VM is a hard and expensive work if finally the solution is to purchase the last Delphi version for commercial development, so first I will try to find another cheaper solution.

Time is money, you are right. Maybe this Rio link makes you happy. Means that you could Install Delphi CE version for free and it should work straight out of the box. Not really if you have a bunch of custom components installed...

But before I would replace my real version, I would test and try such in a VM, not that it suck and all is my fault.

 

Here you could read about details of CE version.

Here you could obtain a copy for free.

 

Hope it helps!

Share this post


Link to post

Finally, I have followed the advice of KodeZwerg, installing Delphi Community Edition in a VM, and it worked.

So this tells me that something is wrong in the Rest Client Library of Delphi XE7.

Thanks to all for your help.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×