from flask import Flask, g
from flask_httpauth import HTTPTokenAuth
app = Flask(__name__)
# auth = HTTPTokenAuth(scheme='Bearer',header='token')
auth = HTTPTokenAuth(header='token')
tokens = {
"secret-token-1": "John",
"secret-token-2": "Susan"
}
@auth.verify_token
def verify_token(token):
g.user = None
if token in tokens:
g.user = tokens[token]
return True
return False
@app.route('/')
@auth.login_required
def index():
return "Hello, %s!" % g.user
if __name__ == '__main__':
app.run()
falsk token鉴权
最新推荐文章于 2024-07-13 23:22:01 发布