Reputation: 77
I want to know is it possible to secure flask api with out login credentials like basic authentication. I want to share only Key and secret to my client.
Upvotes: 1
Views: 4345
Reputation: 2428
You can easily write static (per user of course) API-key for your appilcation. Usually this is done by adding pre-shared secret in HTTP headers. Or as a URI parameter. I'd prefer HTTP. There is at least one library available in Github: https://github.com/ericsopa/flask-api-key. And api-key authentication is rather easy to implement yourself.
For better security you can use token authentication. It is explained in https://realpython.com/token-based-authentication-with-flask/
And remenber. Always HTTPS never HTTP!
When talking about API many of us think about REST. When talking about REST and authentication, it good to remember that REST is stateless. So authentication (such as sendin toke or API key or credentials) is done in every request. There is no session for authenticated users. Of course there is many other APIs than REST out there.
Upvotes: 2