Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi XE2 DataSnap - Access REST connection properties in server methods module

I'm building an XE2 DataSnap server which will serve connections from REST clients. My DSServerClass LifeCycle property is set to 'Invocation'. The REST connection properties will include username and password, which are handled through the DSAuthenticationManager UserAuthenticate() event. What I need to know is how can I access the username and password within the server methods class? I want to be able to know which REST username/password launched the object instance of my server class.

like image 999
Jonathan Wareham Avatar asked Jan 18 '26 23:01

Jonathan Wareham


1 Answers

You can use DSServerClass.OnPrepare for that:

procedure TServerContainerTest.DSServerClass1Prepare(
  DSPrepareEventObject: TDSPrepareEventObject);
begin
  // Add username property to TServerMethodsTest
  if DSPrepareEventObject.MethodInstance is TServerMethodsTest then
    TServerMethodsTest(DSPrepareEventObject.MethodInstance).Username := DSPrepareEventObject.UserName;
end;

There's is no password available. Don't use Server LifeCycle for this!

like image 186
Arjen van der Spek Avatar answered Jan 21 '26 14:01

Arjen van der Spek