Created
March 29, 2011 08:43
-
-
Save ryankirkman/892018 to your computer and use it in GitHub Desktop.
How to authenticate to an express.js web service with curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## Save cookies to the "cookies.txt" file | |
## Assumes the web service expects username | |
## and password in a JSON object, submitted via POST. | |
curl --cookie-jar cookies.txt -H "Content-Type: application/json" -X POST http://localhost:3000/user/login -d "{\"username\": \"YOURUSERNAME\", \"password\": \"YOURPASSWORD\"}" | |
## Now to use the authenticated session: | |
## (Assuming your web service speaks JSON) | |
curl --cookie cookies.txt -X GET http://localhost:3000/user/SOMEID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment