File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
python-flask-rest-api-basic-auth Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ You can read tutorial https://www.roytuts.com/python-flask-http-basic-authentication/
Original file line number Diff line number Diff line change
1
+ from flask import Flask
2
+ from flask import jsonify
3
+ from flask_httpauth import HTTPBasicAuth
4
+
5
+ app = Flask (__name__ )
6
+ auth = HTTPBasicAuth ()
7
+
8
+ @app .route ('/rest-auth' )
9
+ @auth .login_required
10
+ def get_response ():
11
+ return jsonify ('You are an authenticate person to see this message' )
12
+
13
+ @auth .verify_password
14
+ def authenticate (username , password ):
15
+ if username and password :
16
+ if username == 'roy' and password == 'roy' :
17
+ return True
18
+ else :
19
+ return False
20
+ return False
21
+
22
+ if __name__ == "__main__" :
23
+ app .run ()
You can’t perform that action at this time.
0 commit comments