#1 2015-03-26 07:58:55

eipz
Member
Registered: 2015-03-26
Posts: 2

Using interfaced based and defining a POST-method

Hello!

This is my first post here, so please be patient if im posting it wrong or something.

Im trying to use the interfaced based version and i want to make a method that is used for logging in a user.
I know there is something made default in mormot, but i cant use it for this specific type of user.

I also tried to follow the MVC-example.

  IUser = interface(IInvokable) ['{666521A6-CB98-4C71-96D7-40890F0B29C6}']
    function   ChangePassword(const oldPassword, newPassword, token:string):TServiceCustomAnswer;
    function   Login(const userName,password:string):TServiceCustomAnswer;
    function   Logout(const token:string):TServiceCustomAnswer;
    function   ResetPassword(const userName,email:string):TServiceCustomAnswer;
  end;

When i try to for example make a POST to LOGIN with the post parameters  username and password i get a 400-error saying

errorText: "Shared execution failed (probably due to bad input parameters) for IUser.Login"

Any ideas? Any help would be really appreciated.

Greetings
Tobias

Offline

#2 2015-03-26 08:12:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,232
Website

Re: Using interfaced based and defining a POST-method

If I understand correctly, you are using not a mORMot client, but a regular HTTP client, right?

First of all, ensure you disabled the authentication for the service.

Then, the POST request should be as expected, i.e. with application/json content type, and a JSON content as input body, or you can encode the parameters at URI level.
See the low-level layout in http://synopse.info/files/html/Synopse% … #TITLE_373

BTW sending the password directly is pretty weak, in terms of safety.
Consider using a challenge, e.g. as we implemented in http://synopse.info/files/html/api-1.18 … faces.html

Offline

#3 2015-03-26 10:01:18

eipz
Member
Registered: 2015-03-26
Posts: 2

Re: Using interfaced based and defining a POST-method

Thanks for the impressive quick reply!

I got it to work, i thought i needed to do something special when i defined my methods.
I can't get it to work with:

username=USERNAME&password=PASSWORD

In the HTTP POST, but it does work with

["USERNAME","PASSWORD"]

Perhaps support for the first version would be nice?

Thanks again for the quick response!

Offline

#4 2015-03-26 11:36:05

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: Using interfaced based and defining a POST-method

By the first version do you mean URL-encoded parameters? According the document provided by Arnaud above, it seems the URL parameters are only considered if the body content of your POST is empty. If you use the body content of the POST method, the format has always to be JSON. I think this is a adequate design, your "first version" is similar to INI files, and it will not be able to express some complex contents. JSON is THE format for transferring web data  nowadays.

Last edited by edwinsn (2015-03-26 11:38:10)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

Board footer

Powered by FluxBB