Delphi Datasnap Server User Authentication

2020-08-01 12:21发布

问题:

We are developing a new, and our first, DataSnap server and client apps. I have added authentication to the server but I cannot dynamically change the login details for the connection from the client. The User and Password in the

procedure TServerContainer1.DSAuthenticationManager1UserAuthenticate(
  Sender: TObject; const Protocol, Context, User, Password: string;
  var valid: Boolean; UserRoles: TStrings);

stays blank.

In the client we set the values as such ...

DSConnection := TSQLConnection.Create(nil);
DSConnection.DriverName := 'DATASNAP';
DSConnection.LoginPrompt := False;
DSConnection.Params.Values['port'] :=  Port;
DSConnection.Params.Values['HostName'] :=  HostName;
DSConnection.Params.Values['DSAuthUser'] :=  Username;
DSConnection.OnLogin := DSConnectionOnLogin;
DSProviderConnection1.SQLConnection := DSConnection;
MMLog.Log('DSConnection: ' + DSConnection.Params.Text);
DSConnection.Open;

If I however look at DSConnectEventObject.ConnectProperties.Properties.Text in the server OnConnect event, I can see the parameters as passed.

Am I missing something?

Thanks, Pieter

回答1:

The solution is to use the correct Value descriptors.

DSConnection.Params.Values['DSAuthUser'] :=  Username;

becomes

DSConnection.Params.Values['DSAuthenticationUser'] :=  Username;
DSConnection.Params.Values['DSAuthenticationPassword'] := Password;

This way the Authentication Manager gets the correct username and password.