#1 2022-09-01 14:56:01

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 416

How to set a JWT Bearer in TRestHttpClientWinHttp

It took me some time to debug it and find why I got denials when using a TRestHttpClientWinHttp to authenticate using JWTs

In the following code gives back error that JWT is not provided :

cl:=TRestHttpClientWinHttp.Create(SrvIP,inttostr(SrvPort),TOrmModel.Create([],urlbase),SrvSsl,'','',netsendTimeout,netretTimeout,netsendTimeout);
cl.Model.Owner:=cl; 
if cl.ServerTimestampSynchronize then 
begin
cl.CustomHeader:=AuthorizationBearer(TheJWThere);
if cl.ServiceDefine([iservice],sicShared) then cl.Resolve(iservice,serv);
end;

Instead of the following

cl.CustomHeader:=AuthorizationBearer(TheJWThere);

use the following:

cl.SessionHttpHeader:=AuthorizationBearer(TheJWThere);

it seems that cl.CustomHeader is not sent to the server

Offline

Board footer

Powered by FluxBB