forked from jarmani/angular-jwt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
36 lines (28 loc) · 771 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# app.py
from flask import Flask, send_file
from flask_jwt import JWT, jwt_required
app = Flask(__name__)
app.debug = True
app.config['SECRET_KEY'] = 'super-secret'
jwt = JWT(app)
class User(object):
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
@jwt.authentication_handler
def authenticate(username, password):
if username == 'test' and password == 'test':
return User(id=1, username='test')
@jwt.user_handler
def load_user(payload):
if payload['user_id'] == 1:
return User(id=1, username='test')
@app.route('/protected')
@jwt_required()
def protected():
return 'Success!'
@app.route('/')
def index():
return send_file('index.html')
if __name__ == '__main__':
app.run()