[SOLVED] UHTTP send with OAuth 2

Author: slana@compekon.cz (jitkas)

Hi, can you give me some example, how to call external api via HTTPS with OAuth2? I have https address, valid token and my test in SoapUI works OK. I'm trying this code in Uniface 9.7, but it doesn/t work:

variables string vUri, vHeaders, vContent, vResponse, vToken endvariables vUri="https://..." vToken="eyJ0e..." vHeaders="Authorization=Bearer %%vToken" vContent="" vResponse="" activate "UHTTP".send(vUri, "GET", "", "", vHeaders, vContent, vResponse) Thanks, Jitka

5 Comments

  1. Hi Jitka, Could you please provide more details? > Which exact version and patch level of Uniface 9.7 are you using? > What error is returned ($status/$procerror) by the UHTTP.SEND operation? > Is anything returned in vContent or vResponse? Thanks, Daniel


    Author: diseli (daniel.iseli@uniface.com)
  2. Hi Daniel, my Uniface version is 9.7.04.02 (G405 1024_1), platform W81. Return values: $status -12 $procerror 0 and nothing in vContent or vResponse. I don't know, how to say that it is OAuth2 type of authentication. Jitka


    Author: jitkas (slana@compekon.cz)
  3. Hi Jitka, Thanks for the info. The return value ($status) -12 usually means that the SSL Certificate Verification failed. The CA (Certificate Authorities) certificates need to be stored in a local store called ca-bundle.crt that must be resent in the \common\usys directory (of Uniface). In case you trust the site then you also can disable the verification using SET_FLAGS, before using the SEND operation. E.g.

    activate “UHTTP”.set_flags(3) You can find more info about the SSL Verification in the Uniface Library. E.g. > Protecting Your Data > Secure HTTP Connections (HTTPS) > Protecting Your Data > Secure HTTP Connections (HTTPS) > Verification for Web Services over HTTPS A download link for a CA certificate store (in the required format) can be found here. Download the cacert.pem, rename it to ca-bundle.crt and copy it to the \common\usys directory of your Uniface installation. I hope this helps. Daniel


    Author: diseli (daniel.iseli@uniface.com)
  4. Hi, Daniel, thanks a lot, your advice works. Jitka


    Author: jitkas (slana@compekon.cz)
  5. Hi Jitka, Thanks for your reply. And you are welcome. Good to hear that it's working now. Daniel


    Author: diseli (daniel.iseli@uniface.com)