Skip to content

Instantly share code, notes, and snippets.

@ryankirkman
Created March 29, 2011 08:43
Show Gist options
  • Save ryankirkman/892018 to your computer and use it in GitHub Desktop.
Save ryankirkman/892018 to your computer and use it in GitHub Desktop.
How to authenticate to an express.js web service with curl
#!/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