Session HttpApi

Can you use [ServiceRequiresLogin] with HttpAPI?
Do you have documentation about it?
or an example of implementing sessions with HttpAPI.

1 Like

Hello

The sample project is attached: HttpAPI_Session.zip (58.9 KB)

As you can see it defines an API method in a service marked with the ServiceRequiresLogin attribute and 2 methods for login and logiut in the LoginService. Note that there is a separate Login method defined for API that returns an access token instead of a boolean value.

The authentication manager is added to the server as simple as

		// Usual initialization
		var dispatcher = new HttpApiDispatcher();
		dispatcher.ApiHost = "localhost:8099";
		dispatcher.Server = server.NetworkServer.ServerChannel as IHttpServer;

		// Login processing
		var authenticationManager = new ApiSimpleAuthenticationManager();
		dispatcher.AuthenticationManager = authenticationManager;

Here’s this server in action. For a just-started service an attempt to access the protected method will fail:

Then we perform a login operation:

After that the server method will become accessible:

Also it is possible to perform log out:

very well thanks.

if I change port, it can not be authenticated,
the code is like this:

        IpHttpServerChannel Lchannel = new IpHttpServerChannel();
        Lchannel.Port = 8098;
        server.NetworkServer.ServerChannel = Lchannel;

        var dispatcher = new HttpApiDispatcher();
        dispatcher.ApiHost = "localhost:8098";
        dispatcher.Server = server.NetworkServer.ServerChannel as IHttpServer;

       
        var authenticationManager = new ApiSimpleAuthenticationManager();
        dispatcher.AuthenticationManager = authenticationManager;

        server.NetworkServer.Port = 8098;
        server.Run(args);
        return 0;

I cannot reproduce this. For me authentication works as expected. Could you send to support@ full service project and exact queries you used to authenticate and call service methods?

Thanks in advance

Do you have a Delphi sample project of this?

Hi,

We ship the HttpApi Authentication sample.
Can you review it?

Yes I will