Hello,
Hello Alex,
How to implement XData Auth demo with Echo enabled?
There is a demo in Echo install (<echo_install_dir>\demos\xdata) that shows how to use Echo with TMS XData. Then if you want to protect the server, just add a JWT middleware to it and only clients sending a valid JWT token will be able to access the server. The process of issuing the token is the same for other servers, and is described here:
Ok, and is it my question: in offline mode will be impossible to work with JWT?
In other words: no offline more if we have JWT middleware?
I don't see the relation between "offline" and "JWT middleware". Two very different things.
How to determine, when customer need authenticate on the server?
He will need to authenticate to the server when he needs to connect to the server, i.e., when he needs to send the batches of data to be replicated to the server ("push" data).
Hello again,
var
IndyServer: TIndySparkleHTTPServer;
Echo: TEcho;
Timer: TSparkleTimer;
procedure ServerStartEcho(const APort: string);
var
EchoModule: TEchoServerModule;
Pool: IDBConnectionPool;
NodeManager: IEchoNodeManager;
Conn: IDBConnection;
Encrypt: IEncryptMiddleware;
begin
if Assigned(IndyServer) then
Exit;
IndyServer := TIndySparkleHTTPServer.Create;
Pool := TDBConnectionPool.Create(50, TDBConnectionFactory.Create(
function: IDBConnection
var
FDConnection: TFDConnection;
Connection: TAureliusConnection;
begin
FDConnection := TFDConnection.Create(nil);
FDConnection.Params.Values['Database'] := 'C:\Temp\Test.sdb';
FDConnection.Params.Values['DriverID'] := 'SQLite';
FDConnection.Params.Values['Encrypt'] := 'enAes_256';
FDConnection.Params.Values['UserName'] := 'UserName';
FDConnection.Params.Values['Password'] := 'Password';
Connection := TAureliusConnection.Create(nil);
Connection.AdaptedConnection := FDConnection;
Connection.AdapterName := 'FireDac';
Connection.SQLDialect := 'SQLite';
Result := Connection.CreateConnection;
end));
EchoModule := TEchoServerModule.Create('http://+:' + APort + '/tms/echo', Pool);
EchoModule.AddMiddleware(TJwtMiddleware.Create('secret', False, True));
IndyServer.Dispatcher.AddModule(EchoModule);
Echo := TEcho.Create(Pool);
{$IFDEF MSWINDOWS}if not IsDebuggerPresent then{$ENDIF}
begin
Conn := Echo.Pool.GetConnection;
TDatabaseManager.Update(Conn);
TDatabaseManager.Update(Conn, TEcho.Explorer);
Conn := nil;
end;
// Get the NodeManager instance
NodeManager := Echo.GetNodeManager;
if NodeManager.SelfNode = nil then begin
NodeManager.CreateNode('server');
NodeManager.DefineSelfNode('server');
end;
Timer := TSparkleTimer.Create(
procedure(Echo: TObject)
begin
TEcho(Echo).BatchLoad;
TEcho(Echo).Route;
end,
Echo, 2000, TTimerType.Periodic);
IndyServer.Active := True;
end;
Or this is possible?
Can't find any info in documentation
XClient := TXDataClient.Create;
XClient.Uri := 'http://localhost:' + APort + '/tms/echo';
Token := XClient.Service<ILoginService>.Login('testuser', 'testuser');
- I suppose you are destroying IndyServer, Echo and Timer at the end of your application?2. You are leaking both FDConnection and Connection. Since you are creating it manually, don't use Connection (TAureliusConnection). Just create the FDConnection and return IDBConnection using TFireDacConnectionAdapter using True as the second parameter: http://www.tmssoftware.biz/business/aurelius/doc/web/component_adapters.html3. Make sure the timer doesn't perform twice at same time. BatchLoad is not "thread-safe". Set a flag before the processing and reset at the end, and do not execute the timer code if the flag is set.4. For extra service operations, use XData a module.