I am building a RESTful API on top of Scalatra. Being new to the framework, I'm not entirely sure if there's already a solution out there that'll help me authentication users against the API using some token based system (not OAuth). Doesn't have to be anything fancy, I just can't seem to find anything worthwhile on Google. Since the framework caters well to building REST APIs, perhaps there is something already out there to help auth users using a token based system?
3 Answers
Jos Dirksen has a tutorial which includes example code for HMAC auth with Scalatra, it's at:
http://www.smartjava.org/content/tutorial-getting-started-scala-and-scalatra-part-iii
It may or may not meet the needs of your implementation, but it'll give you an idea of one way to approach the problem.

- 554
- 4
- 6
If you need to generate a Unique, Hashed & Random token in scala for API Token calls, here is a sample class

- 539
- 4
- 11
I implemented something based on Christoph Hartmann post on Bearer Authentication. https://lollyrock.com/posts/scalatra-bearer-authentication/.
My code: https://gist.github.com/mawaldne/065ab8566e1de6db33cc947d166e4680
This is very quick and dirty and I think there are security issues. Timing attacks are possible. (See https://thoughtbot.com/blog/token-authentication-with-rails for more info). But for something quick it works. We're only using this for an internal API so Im fine with his approach. YMMV.

- 3,919
- 6
- 31
- 37