Jump to content

Recommended Posts

 Is it possible to perform user authentication between client app and server using SMS?

 

I want my app to authenticate with a server, and either return a JSON with a error message, or a JSON with user profile data.

 

Is this possible? If so, what do I need on the server side to perform the request?

 

e.g.  this gets an HTML document from google

 FHttp.Get('http://www.google.com');

I want to instead, post a username and password and in return get JSON  (error message not authenticated, or some user profile data)

 

but it doesn't look like TW3HttpRequest object has a put method

 

however, there is a Open method.

 

Can something like this be done?

fHTTP.Open('POST','http://mywebsite.com/login.php');

if so, how do I pass the parameters UserId and Password?

Link to post
Share on other sites

Exactly, you need to enable CORS. 

 

Delphi mORMot server will generate on-the-fly a smart client code ready to use.

procedure GetClient(const aServerAddress, aUserName,aPassword: string;
  onSuccess, onError: TSQLRestEvent; aServerPort: integer; aServerRoot: string;
  aHttps: boolean);
begin
  var client := TSQLRestClientHTTP.Create(aServerAddress,aServerPort,
    GetModel(aServerRoot),true,aHttps); // aOwnModel=true
  client.Connect(
  lambda
    try
      if client.ServerTimeStamp=0 then begin
        if Assigned(onError) then
          onError(client);
        exit;
      end;
      if not client.SetUser(TSQLRestServerAuthenticationDefault,aUserName,aPassword) then begin
        if Assigned(onError) then
          onError(client);
        exit;
      end;
      if Assigned(onSuccess) then
        onSuccess(client);
    except
      if Assigned(onError) then
        onError(client);
    end;
  end,
  onError);
end;

...then, you just have to include the generated unit, and call remotely the services, don't worry about the XHR (TW3HttpRequest - http requests GET/POST/PUT/DELETE), you just need to invoke the services. At the client side (SMS), just create a basic login screen, and call the service GetClient. 

 

Take a look at this info about authentication.

procedure checkLogin;
var
  wrongLogin = false;
  modalText := if wrongLogin then 'Wrong username or password' else 'Login with username and password';

begin
  //if TApplication(application).Client=nil then
  TApplication(self).myApp.showIndicator;
  if Client = nil then
    GetClient('127.0.0.1', UserEdit.Text, PassEdit.Text,
      lambda(aClient: TSQLRestClientURI)
      SMS(".toolbar .link").eq(0).hide(); // hide btn login
    
      TApplication(self).myApp.closeModal;
      TApplication(self).myApp.hideIndicator;
      TApplication(self).mainView.router.loadPage('pages/protected.html');

      Client := aClient;
      end,
      lambda
        TApplication(self).myApp.alert(modalText);
        TApplication(self).myApp.hideIndicator;
      end)
      else
        begin
          TApplication(self).myApp.hideIndicator;
          Client.Free;
          Client := nil;
        end;

end; 
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...