How to authenticate delphi rest server with XMLHttpRequest?

I need help here. I've created a basic Delphi rest template using the wizard and setup a simple authentication method using the AuthenticationManager.

procedure TWebModule1.DSAuthenticationManager1UserAuthenticate(
  Sender: TObject; const Protocol, Context, User, Password: string;
  var valid: Boolean; UserRoles: TStrings);

begin

  valid := (user = 'username') and (password = 'password')

end;

Now I need to pass both the username and password to this server from a JavaScript client through invoking one of the server methods. I've tried the following three ways:

request = new XMLHttpRequest();
request.open('GET','http://username:[email protected]:8080/datasnap/rest/TServerMethods1/ReverseString/blah', true);

,

request = new XMLHttpRequest();
request.open('GET','http://localhost:8080/datasnap/rest/TServerMethods1/ReverseString/blah', true, 'username', 'password');

and

request = new XMLHttpRequest();
request.open('GET','http://username:[email protected]:8080/datasnap/rest/TServerMethods1/ReverseString/blah', true);
request.setRequestHeader("Authorization", "Basic " + StringToBase64("username:password"));  

None of them works. They all returned 401 errors. Any ideas?

Answers:

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.