Question

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.

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top