Node.js Login using http post and get data after log in - node.js

How to do following actions using Node.js http POST, GET?
Log in to abc.com(It is a login page with login form)
In the page after log in, fill another form using POST and GET the result after posting the form.

Use the request module: https://www.npmjs.com/package/request. Inspect the login form, look at it's method and action, the using request send a request of the method type to the action with the needed form data. Then use the response's origin to see what the route of the next page is, and then POST to that route. You shouldn't need the GET then, it should respond with the result.
But instead of all this, if the site has supports oauth, you'd be much better off authenticating doing that with passport.js and using their api.

Related

OAuth 2 can i use Post Form Response and PCKE at the same time?

I am trying to secure an SPA, now there is recommendations to use PCKE which is fine, there is also a lot of articles which suggest use post form response, however if the server returns a html form then how would i add the pcke verifier?
you don't, post form uses implicit flow so pcke isn't used

QR code best approach for POST request from REST API

I'm setting up a website that will be mobile focused and one of the features I wan't to implement is users to be able to log an entry by just scanning a QR code.
For what I read is not really possible to make a POST request directly from a QR code, so I was thinking in two different options:
1. Make a GET request and then redirect that inside my server to a POST route in my routes.
So the URL would be something like https://example.com/user/resources/someresourceid123/logs/new and then this would create a POST request to https://example.com/user/resources/someresourceid123/logs/ and create the new entry to then send a response to the user but I'm not really sure this is the best approach or if it's possible at all.
My POST request only requires the resourceid which I should be able to get from req.params and the userid which I get from my req.user.
2. Do my logic and log the entry to my DB using the GET request to https://example.com/user/resources/someresourceid123/logs/new.
This would mean that my controller for that request will do everything needed from the GET request without having to make an additional POST request afterwards. I should be able to get both the resourceid and userid from the req object but not sure if being a GET request limits what I can do with it.
If any of those are possible, which would be the best approach?
I'd propose to go with a second option simply for the sake of performance. But you need to make sure your requests are not cached by any proxy, which is usually the case with GET requests.

Using Python Requests to maintain a session

I am trying to login to a website and based on the REST API guide provided, I will be able to receive some data for an application.
The two steps required for me to enact are:
1. Send a HTTP post command for authentication.
2. Send a GET command for receiving the data.
When I send the post command using python requests, i receive the required json response showing my login rights. e.g. role admin.
However, when I perform the get command after, it doesn't retrieve the data but sends an HTML form showing that I require authentication even though I have authenticated already.
Has anyone encountered this and how will I be able to solve it?
I am working on this for a customer and as a result, cannot post the actual login I am using and url and will hence replace this with my name with the code I will display.
Thanks
enter image description here
You can take a look at the session object in the requests library. It's used to keep a session across multiple requests.
https://3.python-requests.org/user/advanced/#session-objects
import requests
s = requests.Session()
s.get('http://httpbin.org/cookies/set?authcookie=123')
r = s.get('http://httpbin.org/cookies')
print(r.text)
This is a sample that uses a request session object to call a url that sets a cookie and then does another call with the same session (including the cookie). Just some basic example using http://httpbin.org/.

how the internet connecting all clints via server?

can any explain me about how the server responds if we click the button in browser using PHP script then which situation we use JAVASCRIPT and which situation we have to use PHP .
If you're asking about how it works, I'll suggest to google about HTTP protocol, POST and GET methods.
Usually, you use JavaScript to send request to a server when you want it to be AJAX, ie when you want to send request to server and receive response without reloading page. And you use PHP when you have form in your HTML (like login or registration form), and you send it to server in one request to go to another page

Handling a response from node.js without rendering it?

I am returning a simple response in node.js with res.send() in response to a POST request. My problem is that I want the client to stay on the same page. Currently the client just gets taken to a blank page that has the contents of res.send() written on it. But I want the client to update it's current page (the page from which the POST request was sent) instead of displaying the response. Is there a way to do this?
You need to change the action of your HTML form using jquery, angular, or backbone (etc..) The page change is the default functionality of a html form submission, and this cannot be resolved by node.js.

Resources