Basic Authentication
Basic Authentication is a simple method of passing a username and password in the request to an API to access its protected resources. Although its simplicity makes it easy to implement, it is not considered highly secure on its own and many applications use more advanced methods of authentication like API Access Key and OAuth2.0.
To implement basic authentication, the username and password are combined with a “:“, base64 encoded and passed in the authorization header of the request preceding “Basic“. In a HTTP request, it would look like this:
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQxMjM=
You can clearly see how basic authentication is structured in the Translator:
local username = 'username'
local password = 'password123'
local credentials = filter.base64.enc(username..":"..password)
trace(credentials) -- dXNlcm5hbWU6cGFzc3dvcmQxMjM=
local Headers = {}
Headers.Authorization = 'Basic '..credentials
However, Iguana makes it even easier to use basic authentication with your HTTP request. The net.http.* library supports an auth table parameter which implements basic authentication by default.
You simply put the username and password into a table and provide it to the auth parameter. For example:
local auth = {}
auth.username = 'username'
auth.password = 'password123'
local R, C = net.http.post{url=Url, auth=Auth, body=Payload}
Â