Skip to main content

JWT with Devise (App and API)

Rails • Asked by Stephen Gold

Hi,

I'm looking to extend my Rails 5.2 application that uses Devise for authentication so I can support API requests via JSON. I have looked at Chris' videos and did some searching around -- most tutorials I have found only make use of using an "API Only" mode. I would like to make use off of the existing code I have (e.g. use respond_to in the controller, instead of making separate API::Controllers for the exact same code).

Is this possible to do? If so please point me in the right direction. Thank you!


Hey Stephen, did you see the series on how to build an OAuth Provider in Rails? It integrates with Devise, it will generate JWTs for access tokens if you want, and you can use it with iOS and Android to provide a "Login with My App" process just like Twitter or Facebook which is cool.


Hi Chris just wondering if the techinques outlined in the course you've suggested covers using devise for session based login on web alongside OAuth for authenticating the same user over an api for something like a react native app?


Oliver, yep. If you login on the web, you'll login with a session cookie. Otherwise you'll hit the API with a token and be logged in only for that request.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.