Jump to content
KMarb

Need help/components for OAuth2 SSL client certificate REST

Recommended Posts

I have a requirement for my Delphi program to use a corporate web service. I've done a little of this, but not using OAuth2 or client certificates. I'm stumped and looking for some recommendations.

 

I have used Postman and can successfully make the calls I need. The HTTP REST calls are 2-part, one to retrieve a bearer/access token, and then another call (GET or PUSH) to retrieve/send the data I need.

 

I am hoping to get feedback from someone who can tell me 1) what Delphi components to use (happy to purchase something), and 2) how to take my working Postman experience and translate it to the recommended components.

 

The things I have: client id, client secret, client certificate and several versions of pem, crt, cer, p7b files. The things I don't have: a good understanding of the underlying technologies. I will learn what I need to, but I do not want to spend a lot of time learning about this world right now.

 

Does TMS has a product that can do this? What about n/ software (I think that's the name). I've been trying ICS for over a week but it is not working and I don't know how to dig into the data to see why it does not work.

 

Thanks in advance.

Share this post


Link to post

Hi,

 

OAuth2 is basically an authorization protocol that after a successful authorization, returns a bearer token (like an id) that can be used later to access to a REST API. You just need to pass the bearer token in the HTTP headers of the Get/Post... request.

I've a commercial product called sgcWebSockets that implements OAuth2 (among other protocols), you can download a trial for Delphi from:

 

https://www.esegece.com/websockets/download/download-delphi-cbuilder

 

If you want to read more about the OAuth2 implementation, you can use the following link:

 

https://www.esegece.com/help/sgcWebSockets/#t=Components%2FHTTP%2FAuthorization%2FOAuth2%2Fclient%2FTsgcHTTP_OAuth2_Client.htm

 

If you are in trouble testing the demo or you need assistance converting the postman scripts, you can use the following link: https://www.esegece.com/contact/contact-us

 

Kind Regards,

Sergio

 

 

 

  • Like 1
  • Thanks 1

Share this post


Link to post

Trying to install design package trial in D 10.1 and receive this error:

 

exception message  : Can't load package E:\Programming\sgcWebSockets_D10_1\Packages\dclsgcWebSocketsD10_1.bpl. The specified module could not be found.

 

What dll's or files might be missing from my path?

 

Share this post


Link to post

Seems there is an error while installing the components using the installer, seems a configuration problem, because this is the error you got:

 

Quote

C:\Program Files (x86)\Embarcadero\Studio\18.0\Bin\CodeGear.Delphi.Targets(405,5): error MSB6004: The specified task executable location "C:\Program Files (x86)\Embarcadero\Studio\18.0\bin\dcc64.exe" is invalid.

 

You can try to install manually too, just open the group project  E:\Programming\sgcWebSockets_D10_1\Packages\sgcWebSocketsD10_1.groupproj and follow the steps:

 

https://www.esegece.com/help/sgcWebSockets/#t=Install%2FInstall_Package.htm

 

 

Share this post


Link to post

I was installing manually following those steps. Both run-time and design-time packages compile, but when I try to install design-time I get that error, 

 

Can't load package E:\Programming\sgcWebSockets_D10_1\Packages\dclsgcWebSocketsD10_1.bpl. The specified module could not be found.

 

I had a similar problem when trying to test ICS and had to add a couple of DLLs to my path. Any other ideas?

Share this post


Link to post

No, there is no need to add any dll.

The message you get is a bit weird, because is trying to load the bpl from E:\Programming\sgcWebSockets_D10_1\Packages\, while usually the packages are located in $(BDSCOMMONDIR)\Bpl

Try to check in the IDE menu Tools / Options, the Package Output Directory is correct, by default these are the following (for win32 / win64)

 

package_win32.thumb.png.0303ffb35cef50293968022e9efbbd40.png package_win64.thumb.png.b79fc5096bdb1ffbc92a3d97b7a6569d.png

Share this post


Link to post

Your were right. My Package output directory was blank. I entered $(BDSCOMMONDIR)\Bpl as you suggested and then the components installed without problem. Thank you.

 

Also with your help by email I have been able to request and receive an access token. The second thing I need to do is call the REST API with the token to send/receive data. Thank you for the help!

Share this post


Link to post

Hi,

 

Glad to hear it works now.

You can use the TsgcHTTP1Client which is an HTTP client based with authorization features like OAuth2.
 
 
You can attach a TsgcHTTP_OAuth2_Client to the oHTTP Client, and when you do a call request to the API, if the client detects there is not a valid Bearer Token, it will ask from OAuth2 Client. Once has a bearer token, this is attached automatically to the HTTP headers. Find below a simple example:
 
procedure DoHTTPAPI;
var
  oAuth2: TsgcHTTP_OAuth2_Client;
  oHTTP: TsgcHTTP1Client;
begin
  oAuth2 := TsgcHTTP_OAuth2_Client.Create(nil);
  // ... here your oauth2 configuration

  oHTTP := TsgcHTTP1Client.Create(nil);
  Try
    oHTTP.Authentication.Token.OAuth := OAuth2;
    oHTTP.Get('http://www.yourapi.com/test');
  Finally
    oHTTP.Free;
  End;
end;

 

Kind Regards,

Sergio

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

×