Question
· Jan 30

Intercepting JWT Token in Cookies Instead of Authorization Header in Web Application

I am building a web application that uses JWT for authentication. I would like to pass the token in cookies instead of the Authorization header.
Is there a way to intercept the request and check the token from the cookies instead of the header? I tried overriding the OnPreDispatch() method and adding it to my dispatch class, but it seems like it never gets executed, as the response returns "Unauthorized" before reaching it.

ClassMethod OnPreDispatch(pURL As %String, pMethod As %String, ByRef pContinue As %Boolean) As %Status
{
        Set token = %request.Cookies.Get("JWT-TOKEN")
        
        If token = "" {
            Set pContinue = 0
            Quit $$$ERROR($$$GeneralError, "Unauthorized: Token not found in cookie")
        }
        
        Do %request.SetCgiEnv("HTTP_AUTHORIZATION", "Bearer "_token)
        
        Set pContinue = 1
        Quit $$$OK
}
Product version: IRIS 2023.1
Discussion (0)2
Log in or sign up to continue