How do you use cURL to authenticate on a Rails application that uses Devise? How do you use cURL to authenticate on a Rails application that uses Devise? curl curl

How do you use cURL to authenticate on a Rails application that uses Devise?


This works:

Authenticate:

curl -H 'Content-Type: application/json' \  -H 'Accept: application/json' \  -X POST http://localhost:3000/users/sign_in \  -d "{'user' : { 'email' : 'test@example.com', 'password' : 'password'}}" \  -c cookie

Show:

curl -H 'Content-Type: application/json' \  -H 'Accept: application/json' \  -X GET http://localhost:3000/pages/1.xml \  -b cookie


This is because Rails by default adds an authenticity token to forms to protect from malicious forgery of submitted parameters. As you do not supply this token with your request, rails does not accept it.You can bypass this with

skip_before_filter :verify_authenticity_token

in your controller, where authorization takes place, better even to limit it to the authorization action with :only.


Have you tried something like this (not tested):

curl --user name:password http://www.domain.comcurl --user name:password -f 'key=value' http://www.domain.com