How to format POST to create a user using Basic HTTP Auth and Devise Rails Gem

I am new when it comes to this authentic business. Therefore, I searched for a while and did not find direct solutions:

I have a Rails back end using the Devise gem for the auth user and the iPhone frontend. I need to know how to create a user with an iPhone.

I have the resources to create asynchronous mail, but I need to understand the general concept of HTTP authentication a little better - if I, say, used Curl to create a message that would create a user using basic HTTP authentication, what would be the curl command that I would send on "www.example.com/createuser" to do this?

In this example, my Rails application model user attributes are email and password.

Thanks for the million in advance for any tips / links to resources. I really appreciate it!

Best, Jared

+3
source share
1 answer

Basically, it's just a matter of POSTing the correct data on the user's creation route (run rake routesto view all the routes you created as soon as you installed it correctly). For example, I did this with one of my applications (using command line curl):

curl -H "Content-Type:application/json" -H "Accept:application/json" -d "{\"user\":{\"email\":\"jared@jared.com\", \"password\":\"super_secret_pass\", \"password_confirmation\":\"super_secret_pass\"}}" http://jared-dev/users

.. and I come back:

{"status":"signed_in"}

.. and just to confirm:

irb(main):001:0> User.find_by_email('jared@jared.com')
=> #<User id: 2, email: "jared@jared.com", encrypted_password: "$2a$10$QMBAcpKjUwoC.pcRYt88a.vA0oq58jx0lagbgY298wjf...", password_salt: "$2a$10$QMBAcpKjUwoC.pcRYt88a.", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2011-03-15 19:49:47", last_sign_in_at: "2011-03-15 19:49:47", current_sign_in_ip: "127.0.1.1", last_sign_in_ip: "127.0.1.1", authentication_token: "yW37HrKUigwvSEDmXaB4", created_at: "2011-03-15 19:49:47", updated_at: "2011-03-15 19:49:47">

JSON, , , , . JSON auth, .

CURLOPT_HTTPHEADER, CURLOPT_POST CURLOPT_POSTFIELDS, curl_easy_setopt libcurl.

, .

+7

Source: https://habr.com/ru/post/1791064/


All Articles