I am using Flask-Restless to make a super simple REST API. I would like to add authentication, but just for put/post/delete calls, while I want to leave get calls public.
So far, I put in my views.py file this:
manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)
manager.create_api(models.mymodel, methods=['GET', 'POST', 'DELETE'])
I had a look on different solutions for authentication, but they all look too "big". I'll have just one user that should be able to make PUT/POST/DELETE calls, and then "public" users will just use GET.
I think that a simple way should be something like this:
- Public users making a get call: return the api response, as it is now
- Public users making a put/post/delete call: return the "not authorized" response
- Registered user making get/put/post/delete calls: check if it is registered and reply the appropriate response.
The "check" shouldn't be something like storing a secret-key in my config.py
file and then comparing it to an attribute of the header of the api call? I think that creating an entire table for users, as I saw in some tutorials, and then having usernames+password
that generates API tokens is too "big" and not necessary here.. Since I will be the only user that can be authenticated, I know what the key is and I can just put some 'secret-key' : mysecretkey
in the header. Am I missing something?
Thanks!