Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authentication for Sinatra REST API app

I'm building an API with Sinatra (using Angular for the client side and want others to have access to API) and have it also be an OAuth provider. I am wondering what the best route to take (work off existing gems or roll own solution off Warden or something).

Have used devise and doorkeeper for authentication and oauth before with Rails, wondering what best solution for Sinatra is.

Ideally I don't want the views or be able to extend/mod the actions of an existing solution, as I'm interacting with it purely as an API.

like image 975
DexCurl Avatar asked Aug 19 '13 13:08

DexCurl


1 Answers

I just recently did the same thing using the following answer from S/O

What is a very simple authentication scheme for Sinatra/Rack

It implies a user model, but instead of using that, I just set a user and admin password in my config file. Then I had a login form that just took a password. When the user enters that password, I checked it against the one in settings and set the session['user'] to :admin or :user according to whichever it matched (or nil if none). Then on each of my routes, I called auth: :user or auth: :admin accordingly.

like image 176
Josh Hunter Avatar answered Sep 18 '22 16:09

Josh Hunter