Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a token passed as header using datasnap?

In my client application I'm using the following code to add a token in the header:

RESTRequest.Params.AddItem('Authorization', 'Bearer ' + MyToken, TRESTRequestParameterKind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);

I'd like to get this token in my server using datasnap.

I've tried use the answer from here and here but without success.

Is it possible?

How can I do this?

EDIT

I could verify that Datasnap executes TIdCustomHTTPServer.DoParseAuthenticationand that DoParseAuthentication calls FOnParseAuthentication if it is assigned.

So, how can I hack Datasnap to assign my own OnParseAuthentication?

I think this solve my problem.

like image 975
Daniel Grillo Avatar asked Jan 27 '16 11:01

Daniel Grillo


1 Answers

I have the same problem. if the Authentication header is used then we get EIdHTTPUnsupportedAuthorisationScheme error, I need to setup OnParseAuthentication. I just started looking into this today and in the Test App "Desktop" I can do the following.

procedure TMainForm.FormCreate(Sender: TObject);
begin
  FServer := TIdHTTPWebBrokerBridge.Create(Self);
  FServer.OnParseAuthentication := DoParseAuthentication;// <-added this line
end;

Now I need to figure out how to update the ASAPI dll to do the same.

like image 108
Ammar AlKadi Avatar answered Oct 06 '22 04:10

Ammar AlKadi