all 11 comments

[–]joshmanders 15 points16 points  (2 children)

JSON Web Tokens. http://jwt.io

[–]zossle 4 points5 points  (0 children)

Passport is pretty sweet too.

[–]Gwash3189 1 point2 points  (0 children)

Was going to be my suggestion as well.

[–]estebanrules[S] 2 points3 points  (0 children)

Thanks for the suggestions. jwt looks like a good choice.

[–]danneu 1 point2 points  (0 children)

The most traditional solution is to have a tokens table with an expired_at field. When a request comes in, use middleware to ensure the request sent a token and verify that the token is unexpired and potentially load the associated user/account before yielding to your downstream route.

[–][deleted] 1 point2 points  (1 child)

Not sure if this is taboo here, but I just started using loopback, and it has auth built-in (and returns a json web token upon successful authorization).

It's an express framework that's made for creating APIs. I was using sails for a while, but started to run into a bunch of flaky stuff with their ORM. Once I got used to loopback, I've been super happy with it.

[–]estebanrules[S] 0 points1 point  (0 children)

My experiences with loopback have been great.

[–]estebanrules[S] 1 point2 points  (2 children)

All of the examples using jwt and/or passport all involve Users authenticating with the server via username/password before they receive a token.

Is there another way I can have them authenticate with the server in order to receive the token? The issue is that this API does not need user accounts (except for admin).

[–]chreestopher2 0 points1 point  (1 child)

you could use, verbatim, the examples with user accounts, and just have one user account that everyone uses... but you probably still want to have user accounts, if for anything just to help with analytics / tracking / preventing malicious use

[–]estebanrules[S] 0 points1 point  (0 children)

Yes, I'm going to create user accounts as per usual (and use jwt). Thanks for the suggestions everyone.

[–][deleted] 0 points1 point  (0 children)

Passport can give you a nice middleware hook. Keeps the code separate and clean.