I'm trying to access the Bearer token from the Authorization header in my REST service class, but I'm getting a 500 Internal Server Error when I try to use %request.GetCgiEnv("HTTP_AUTHORIZATION").
My Environment:
- InterSystems ensemble 2018
- Using
EnsLib.REST.Service with HTTP Inbound Adapter
- REST API URL:
http://ip:port/api-kiosk/patientData
My Code:
objectscript
Class CIS.PATIENT.ReadPatientData Extends EnsLib.REST.Service
{
Parameter ADAPTER = "EnsLib.HTTP.InboundAdapter";
Parameter HandleCorsRequest = 1;
XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
<Route Url="/patientData" Method="POST" Call="getPatientData"/>
</Routes>
}
Parameter EnsServicePrefix = "|api-kiosk";
Method getPatientData(pInput As %Library.AbstractStream, Output pOutput As %Stream.Object,
pPersonType As %String, pKeyField As %String, pKeyVal As %String,
pGetField As %String = "") As %Status
{
Set tSC = $$$OK
Try {
Set reqData = pInput.Read(,.tSC)
// This line causes 500 Internal Server Error
Set authHeader = %request.GetCgiEnv("HTTP_AUTHORIZATION")
// ... rest of my logic
} Catch ex {
Set tSC = ex.AsStatus()
}
Quit tSC
}
}
I need to access the Bearer token from the Authorization header in my REST service method. What is the correct way to access HTTP headers (specifically the Authorization header) in EnsLib.REST.Service methods?
Any help would be greatly appreciated!