Delphi Datasnap Server User Authentication

泪湿孤枕 提交于 2019-12-06 15:16:20

问题


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.



来源:https://stackoverflow.com/questions/11684843/delphi-datasnap-server-user-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!