| I am working on service which exposes REST API. What is the best way to implement authorization for incoming requests. * Identify who is making the request. Can we use api key for this. * Make sure this REST api can be used just as easily using curl. I am not sure how to do this, as I dn't think exposing API key is a good idea. I can ask clients to hash request params with api key, but that makes it non-trivial to use with curl. What are the standard practices, and what are the trade offs. Please be kind and helpful. If I said anything wrong, please correct me instead of flagging this. Any help would be appreciated. Glad to provide any info that makes it useful to answer |
The authentication server stores email/username, encrypted password, and roles. To access the web app, you first get a token from the authentication server by exchanging a client_id, secret, username, password and grant type. The token is used whenever you want to make a request to the web app. The authentication server has an endpoint that lets the web app check to see if the token is valid and what roles the client has.
The token is only valid for a short time and can be revoked. To know who is making the request, you associate the username/email from the authentication server with a user object on the web application so you can look up based on username/email.
It's not worth doing this from scratch as there are plenty of open source implementations out there already like Spring Security Oauth2 and other libraries for Django/python, but they all require some reading to get started.
I've used Spring Security Oauth2, but it's not very well documented. I've thought about open sourcing my work, but not sure yet.