Authentication on GET help

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
BrianH
Posts: 2
Joined: Fri Oct 14, 2022 1:24 pm

Authentication on GET help

Post by BrianH »

Hi Everyone!

I'm looking for some help. I have an API over HTTPS that requires POST at login, from there you can use either the security cookie or token supplied in the returned JSON. My issue is with the next GET, POST, PUT, or DELETE request. I turned on debugging and reviewed the log, I don't think the API likes setAuth or setOption. The website's directions are very specific about what needs to be supplied in the header.

After logging in, all subsequent requests require -H Authorization and -H Content-Type. For example,

curl -X GET -H "Authorization: MY_TOKEN_ AT_LOGIN_OR_SEC_COOKIE" -H "Content-Type: application/json"
'https://mywebsite.com/Projects/api/gets ... =something'

How do you regurgitate Auth and Content in the header of requests?

Thank you,
Brian
Scott Klement
Site Admin
Posts: 636
Joined: Sun Jul 04, 2021 5:12 am

Re: Authentication on GET help

Post by Scott Klement »

You can specify the content-type in the "content-type" parameter. Please don't try to supply it manually.

The authorization header you are using is non-standard (it does not conform with the internet standards for HTTP). So you will not be able to use setAuth or setOption to set it. You can do it with an "additional header exit point" like this:

Before calling the URL:

Code: Select all

 http_xproc( HTTP_POINT_ADDL_HEADER
             : %paddr(BriansHeaders) );
During all subsequent HTTP requests, it will call a subprocedure named BriansHeaders that should look like this:

Code: Select all

      P BriansHeaders   B
      D BriansHeaders   PI
      D   Header                    1024A   varying
      D   UserData                      *   value
       /free
          Header = 'Authorization: ' + VARIABLE_WITH_TOKEN_OR_COOKIE  + x'0d25';
       /end-free
      P                 E
BrianH
Posts: 2
Joined: Fri Oct 14, 2022 1:24 pm

Re: Authentication on GET help

Post by BrianH »

Hi Scott,

The http_xproc worked great!

Thank you so much!!
Brian
Post Reply