Session HttpApi

(Sistemas Logicos) #1

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

1 Like

(antonk) #3

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:

0 Likes

(Sistemas Logicos) #4

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;
0 Likes

(antonk) #5

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

0 Likes

(Marcos Cunha Lima) #6

Do you have a Delphi sample project of this?

0 Likes

(EvgenyK) #9

Hi,

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

0 Likes

(Marcos Cunha Lima) #10

Yes I will

0 Likes