5

I'm creating a Rails app which have both a GUI part, and a REST/JSON-API.

The REST/JSON API is fairly simple, and the controller returns data like this:

def get_players
    @players = Player.all
    render json: @players
end

The GUI part of the app is using Devise for authentication, and it works fine.

Now I want to add authentication for the REST/JSON Api too, how do I do that?

Also, how do I test the REST API using curl when the Authentication is added?

---- edit ----

as it turns out, Devise wasnt necessary in this case. A home-cooked token-authentication method works for now. (token created when Player is created, and returned on correct e-mail/password combo).

Peter Andersson
  • 1,947
  • 3
  • 28
  • 44

1 Answers1

6

After getting a few tips, I found a number of great sites. There are several ways to do this, however I don't know which one is best, but these sites help a long way:

Community
  • 1
  • 1
Peter Andersson
  • 1,947
  • 3
  • 28
  • 44
  • The labs.kollegorna url is dead, but I found the content here: https://github.com/kollegorna/labs.kollegorna.se/blob/master/source/posts/2015-04-09-build-an-api-now.html.md#adding-authentication – Sean Dec 20 '19 at 20:39