简体   繁体   中英

how to use flask REST API authentication

We are working on a project to provide search service of our search engine Humkinar to our clients. We are looking forward to have REST api which our client will use to get search results from our servers into his custom app.

To avoid public access to my REST API i want some sort of authentication in it. HTTP authentication do not work in my case. Because in my case, if i use basic HTTP authentication i have to provide username and password of client which is a secrete for client and users on client custom app must not know about client credentials.

For this purpose i need some sort of KEY based authentication which we provide to our clients and clients put them in their custom apps.

can anyone guide me how i can do this in flask REST API's?
how i can generate API keys and authenticate them?

Is there any standards for this? Kindly reply to me as soon as possible.

With little research i have solved this issue. Best way of authentication in my case was using API-Keys. Now i am generating API-Key for my clients which is universally unique. Each client will have its own API-key and will send this key in REST request. our service will receive request and get that key from it. Then this key will be verified from DB to validate and this way authentication will be make sure.

I am using UUID4 for generating universally unique 36 character long key

code for generating API-key is given below:

import uuid
uuid_str = str(uuid.uuid4())
print(uuid_str)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM