it would be awesome to see implemented a ui now for a user to actually sign up and see how that all gets wired up. I am trying to build and api for my mobile app and this is perfect.
yea this video is freakin awesome. You know how many times I have started a project and need and api or a website where people can either sign up on the website or on in my case one of my iphone apps. It would awesome to see added to this. A web UI from this app. So how to add a front end to this app where users can sign up and then also I could send a request from my ios app sign up page to this service and it will create a user for me and give me token so I can call the apis'. That would be so rad
See if this episode helps out. It uses `devise` and the `knock` gem for JWT authentication.
https://www.driftingruby.com/episodes/rails-api-authentication-with-jwt
When I tried the first curl command, I got a 401 Unauthorized so I went and copied from the notes in case I had made a mistake, but the error remains. Any idea what would be stopping me from getting an auth_token returned? My logs show the following: Processing by SessionsController#create as /
Parameters: {"'{email:john@example.com,password:1234}'"=>"[FILTERED]"} SELECT "users".* FROM "users" WHERE "users"."email" IS NULL LIMIT ? [["LIMIT", 1]]
Completed 401 Unauthorized.
I also created the user in the same way as the video shows, with a name, password, and password_confirmation.
Is the curl request in the notes malformed? I am only changing the values of the email and password like so:
curl -H 'Content-Type: application/json' -X POST -d '{"email":"john@example.com","password":"1234"}' http://localhost:3000/authenticate
Thank you for the very prompt reply!
Curl version:
curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL
Ruby version:
ruby 2.4.4p296 (2018-03-28 revision 63013) [x64-mingw32]
Line 17 of authenticate_user has the safe navigation operator which could potentially be causing issues, but I just checked and that was added in ruby 2.3.
Perhaps this is just an issue with development on windows, but I haven't had issues with curl in the past.
I believe you're correct. The Windows implementation of cURL may be a bit different and/or how the command prompt handles the syntax.
https://www.driftingruby.com/episodes/ruby-on-rails-development-with-microsoft-windows-10
https://www.driftingruby.com/episodes/intro-to-docker-on-windows
Check out these episodes. I'd highly recommend one of these methods if you're going to be developing on a Windows machine. Alternatively, you could also do a VirtualBox Ubuntu VM or something similar.
It ended up being an issue with how quotes are interpreted for windows cmd. I was able to get it working by replacing all the single quotes with double quotes and then escaping the double quotes for the arguments like so:
curl -H "Content-Type:application/json" -X POST -d "{\"email\": \"john@example.com\", \"password\": \"1234\"}" http://localhost:3000/authenticate
Thanks again. I will spin up an ubuntu server vm later but I didn't feel like dealing with the setup tonight.
One other thing, I think it would be good to mention your episode #123 Encrypted Credentials in Rails 5.2 as the setup in this is required, at least for generating the credentials.yml.enc and master.key.
☒ Yes, it would probably be the 24.hours.from_now set for the expiration. Personally, I don't think that the JWT token should be a long living one. If the server returns that the token is expired, the consuming app should have a mechanism to validate a new one without user interaction.
I find authorize_api_request. decoded_auth_token is false (due to http_auth_header?)
I suspect it due to the 24.hours exp of JWT.
any idea?