I'm interested in developing a RESTful JSON data API using Sinatra, and have an HTML5/JS app consume that data API. Obviously the data API needs some form of authentication so that user Joe can only access his own stuff via the API. It would be nice if I could not roll my own authentication, and instead rely on Google/Facebook/Twitter to be the identity provider.
I've looked into OAuth2 using Omniauth and I can wire that up easily enough for traditional web apps, but when talking about securing the JSON API using FB/Twitter/Google, my understanding breaks down because:
- The API shouldn't really be the thing doing the redirects for the OAuth2 flow, should it?
- When the callback data from an identity provider comes through, it'd probably hit the HTML/JS app, right?
A further kink would be if I ever wanted to provide 3rd party developers API access via non-web mechanisms; the OAuth2 redirect flow business certainly wouldn't work here.
So all told, I'd have an architecture that looks like this:
[ HTML/JS client ] --- [ JSON API ] [ FB/Twitter/Google ]
|
|
[ Developer ]
In effect, what I'm after is what's here, except this is for Rails only:
Any pointers for doing this with Sinatra? Please use some specific examples.