TWebHTTPRequest

I am assuming HTTPRequest.User and HTTPRequest.Password are for basic authentication and have tried setting them but it seems they are ignored.


I can add a header for Basic Authentication manually and it works fine.

So how can I base64 encode the credentials to add into the header?
I cannot find a function to use.

You can use TWebHTTPRequest.Headers to add header info and you can use the function atob() in web.pas to perform base64 encoding.

This maps on:
https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding

Please, give an example Basic and JWT Authentication for TWebHttpRequest

Please, give an example Basic Authentication for TWebHttpRequest

This all depends on the exact authentication flow your server expects.

In TMS XData for example, it is JWT based and we have support built-in in the components and info about it can be found here: http://www.tmssoftware.biz/business/xdata/doc/web/authentication_example_using_j.html

If this is with another server and perhaps a different authentication flow, a starting point can be found here using basic HTTP that you could implement using the TWebHttpRequest in Pascal

https://stackoverflow.com/questions/34860814/basic-authentication-using-javascript