Website Form-Login Authentication

I am currently working on a project that requires a login screen which would need to authenticate with a website via username/password.

I tried the following to try to send the username and password but the event response was just the HTML from the website I pointed to.

local function networkListener( event ) if ( event.isError ) then print( "Network error: ", event.response ) else print( "RESPONSE: " .. event.response) end end local params = {} local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" params.formdata = "username=user&password=pass" params.headers = headers network.request("https://example.com/login", "POST", networkListener, params)

Is there any way to authenticate with a website this way?

It’s the responsibility of the webpage to return values to you. If the script is just returning the HTML of the web page, perhaps that’s signal enough that your login was successful. But I’m not sure what other networking you’re wanting to do with that site. Most sites that let apps login have an API that will return to you a token that you can use to authenticate future requests to other API calls.

With a webView you and a normal web login the site would likely set a cookie indicating that you’re logged in. The network.request API doesn’t really use cookies, but you should be getting the cookies in a header value returned by the server. You can include those cookies in the header when you make requests back too.

Make sure you have already required the “json” library (local json = require(“json”) at the top of the module) and then inside your networkListener function do:

print( json.prettify( event ) )

And see what all data you’re getting back from the server. If you see a login cookie, you can include it in the header on future network requests and that might work for you.

What further work/scripts are you wanting from the site? 

It’s the responsibility of the webpage to return values to you. If the script is just returning the HTML of the web page, perhaps that’s signal enough that your login was successful. But I’m not sure what other networking you’re wanting to do with that site. Most sites that let apps login have an API that will return to you a token that you can use to authenticate future requests to other API calls.

With a webView you and a normal web login the site would likely set a cookie indicating that you’re logged in. The network.request API doesn’t really use cookies, but you should be getting the cookies in a header value returned by the server. You can include those cookies in the header when you make requests back too.

Make sure you have already required the “json” library (local json = require(“json”) at the top of the module) and then inside your networkListener function do:

print( json.prettify( event ) )

And see what all data you’re getting back from the server. If you see a login cookie, you can include it in the header on future network requests and that might work for you.

What further work/scripts are you wanting from the site?