Is there a way I can access HTTP Header in a incoming HTTP

Posted by Walter Mangra on 10-May-2018 16:30

I need to extract username and password for user authentication. 

All Replies

Posted by Peter Judge on 10-May-2018 16:34

For the REST transport you can map the header you’re interested in to an input parameter.
 

Posted by Walter Mangra on 13-May-2018 19:54

As suggested I tried adding ReqHeader  to the Service_Interface code, but when I tried to map the HTTP GET once more

I am getting the following error:

Rest file include Invocation file generation failed. The procedure  includes unsupported data types "openedge.net.http.httpheader". Remove the unsupported parameter data types from the following procedures(s):

"Read1"  to successfully generate REST invocation file.

Any ideas on how to recover the userid/password  from the request  header since I am sending it to  the OEPAS instance ?

/* Code from Service_Interface

block-level on error undo, throw.

using Progress.Lang.*.

/* ***************************  Definitions  ************************** */

define variable CustInfoInstanceRead as AppServer.CustomerDispatcher no-undo.

define input parameter CustId as integer no-undo.

define input parameter ReqHeader as OpenEdge.Net.HTTP.HttpHeader no-undo.

define temp-table custrecord like Customer.

define output parameter TABLE  for custrecord.

define output parameter reason as character no-undo.

CustInfoInstanceRead= new AppServer.CustomerDispatcher().

CustInfoInstanceRead:Read1(input CustId,input ReqHeader,output TABLE custrecord,output reason).

return.

---------------------------------------------------------------------------------------------------------------

/* Snippet from CustomerDispatcher Class */

@openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").

method public integer Read1(input custId as integer, input ReqHeader as OpenEdge.Net.HTTP.HttpHeader, output TABLE custRecord, output httpReason as character):

define variable httpStatus as integer initial 200.

       /* Assume 200 status code */

       empty temp-table custRecord.

       find first Customer where Customer.CustNum = custId no-error.

       if available Customer then do:

           create custRecord.

           buffer-copy Customer to custRecord.

       end.

       else do:

           httpStatus = 404.

           httpReason = "ERROR: Customer " + STRING(custId) + " not found]".

       end.

       release Customer.

       return httpStatus.

end method.

Posted by Mike Fechner on 13-May-2018 21:54

Pretty sure only simple parameter types like Character and Integer etc. are supported for REST interfaces.

Sent from Nine

Von: Walter Mangra <bounce-wmangra@community.progress.com>
Gesendet: Montag, 14. Mai 2018 02:56
An: TU.OE.Development@community.progress.com
Betreff: RE: [Technical Users - OE Development] Is there a way I can access HTTP Header in a incoming HTTP Request for an OE REST service call ?

Update from Progress Community
Walter Mangra

As suggested I tried adding ReqHeader  to the Service_Interface code, but when I tried to map the HTTP GET once more

I am getting the following error:

Rest file include Invocation file generation failed. The procedure  includes unsupported data types "openedge.net.http.httpheader". Remove the unsupported parameter data types from the following procedures(s):

"Read1"  to successfully generate REST invocation file.

Any ideas on how to recover the userid/password  from the request  header since I am sending it to  the OEPAS instance ?

/* Code from Service_Interface

block-level on error undo, throw.

using Progress.Lang.*.

/* ***************************  Definitions  ************************** */

define variable CustInfoInstanceRead as AppServer.CustomerDispatcher no-undo.

define input parameter CustId as integer no-undo.

define input parameter ReqHeader as OpenEdge.Net.HTTP.HttpHeader no-undo.

define temp-table custrecord like Customer.

define output parameter TABLE  for custrecord.

define output parameter reason as character no-undo.

CustInfoInstanceRead= new AppServer.CustomerDispatcher().

CustInfoInstanceRead:Read1(input CustId,input ReqHeader,output TABLE custrecord,output reason).

return.

---------------------------------------------------------------------------------------------------------------

/* Snippet from CustomerDispatcher Class */

@openapi.openedge.export(type="REST", useReturnValue="false", writeDataSetBeforeImage="false").

method public integer Read1(input custId as integer, input ReqHeader as OpenEdge.Net.HTTP.HttpHeader, output TABLE custRecord, output httpReason as character):

define variable httpStatus as integer initial 200.

       /* Assume 200 status code */

       empty temp-table custRecord.

       find first Customer where Customer.CustNum = custId no-error.

       if available Customer then do:

           create custRecord.

           buffer-copy Customer to custRecord.

       end.

       else do:

           httpStatus = 404.

           httpReason = "ERROR: Customer " + STRING(custId) + " not found]".

       end.

       release Customer.

       return httpStatus.

end method.

View online

 

You received this notification because you subscribed to the forum.  To unsubscribe from only this thread, go here.

Flag this post as spam/abuse.

Posted by Jean-Christophe Cardot on 14-May-2018 04:29

We do this by mapping the Authorization header, then we get the value through an CHARACTER input parameter.

Using Basic authentification scheme, the first entry (separated by " ") must be "Basic" and the second one is a base64 encoded string that you must pass through base64-decode in order to get the string "user:password".

Posted by cwmangra on 20-May-2018 20:43

Thank for you response. No sure I am doing this correctly. I tried to  select  'Authorization' under the input  "Headers" tag of the URI editor, but only 'Content-Type' was available to choose from  once I click and selected the 'Add Node'.option.

I am aware of the need to base64-decode,  the base64 encoded once I retrieve it, but my show stopper is how to get to that string...

This thread is closed