1
votes

I had a problem regarding redirect after I had successfully log in using CURL.

My CURL command:

curl -H 'Content-Type: application/json' -X POST http://localhost:3000/users/sign_in -d '{"user": {"email": "[email protected]", "password": "abc12345"}}' -i

My CURL Response:

HTTP/1.1 302 Found X-Frame-Options: SAMEORIGIN X-Xss-Protection: 1; mode=block X-Content-Type-Options: nosniff Location: http://localhost:3000/ Content-Type: text/html; charset=utf-8 Cache-Control: no-cache X-Request-Id: 15d20863-7666-4c8a-8de1-ec8de97e5e53 X-Runtime: 0.109029 Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08) Date: Thu, 30 Jul 2015 03:52:04 GMT Content-Length: 88 Connection: Keep-Alive Set-Cookie: request_method=POST; path=/ Set-Cookie: _stuckplaces_session=UWpsUlRhZ0pPdmxOcXlpa3Bpd1ZRbDRGOE1GUXErMnQ1MHNSQUxYMzN2V3lROHJUbU5BWTZJZTJERlVxTTFPajJub2grMWRnK05zTnNGMXN2K09DU1NFdEJUblliZlJuOUdlWTZOakZ3ai85ZjdqVTJqa0pzcEcrUFNTWjIzc2dFc2lOMm1ZaFdIUG56UHU5ZU9NNGliSmUyNmNIdk81MWQ5bXJyWVpXbGtDVGtVeEFzdS9PYk5IaDMvSUkxZnpjaEZ2K3hmQU9FcTI4dTQ3UldwVDNuZjhlTDRKMiszZTdSS01WMzZmNi9yb21Zei85N2laZ2VQOWI3eDlkTVkzQS0tT1JNbDdKbng5cVdaT0hYRFFIc0JCQT09--971fd40b128844eb52699bd18b54ed31f2bf162f; path=/; HttpOnly

You are being redirected.

And this is log that I got in terminal:

Started POST "/users/sign_in" for ::1 at 2015-07-30 11:52:03 +0800 Processing by Devise::SessionsController#create as / Parameters: {"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "session"=>{"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}}} User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? ORDER BY "users"."id" ASC LIMIT 1 [["email", "[email protected]"]] (0.1ms) begin transaction SQL (0.3ms) UPDATE "users" SET "last_sign_in_at" = ?, "current_sign_in_at" = ?, "sign_in_count" = ?, "updated_at" = ? WHERE "users"."id" = ? [["last_sign_in_at", "2015-07-30 03:51:57.486750"], ["current_sign_in_at", "2015-07-30 03:52:04.060786"], ["sign_in_count", 23], ["updated_at", "2015-07-30 03:52:04.061836"], ["id", 6]] (8.8ms) commit transaction Redirected to http://localhost:3000/ Completed 302 Found in 105ms (ActiveRecord: 9.3ms)

This is my sessions_controller.rb :

https://gist.github.com/afiq90/2d3f02878cf9c23a03b1

I also had commented protect_from_forgery with: :exception in application_controller, if I'm not commented this line, I will got error 422 Unprocessable Entity.

As far as I understand based on the log, I had successfully signed in into rails app using CURL, but the response for CURL is 302 redirect supposedly it should be 200 and returned the token associated with successfully login credentials. I hope someone can help me with this problem. Thank you in advance.

1
I still cannot get token value after have made changes. @AbdulRahimMohamad - z3r0

1 Answers

1
votes

Modify your curl url to

http://localhost:3000/users/sign_in.json

If we look at the given gist https://gist.github.com/afiq90/2d3f02878cf9c23a03b1 It will take html format and as a response, it will redirect you to root page.