Jonathan Wareham
Jonathan Wareham

Reputation: 3397

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.

Upvotes: 3

Views: 1649

Answers (1)

Arjen van der Spek
Arjen van der Spek

Reputation: 2660

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!

Upvotes: 1

Related Questions