From a310b78db2b947ab70f3fc35c1a586d822acc7ca Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Thu, 14 Jun 2018 23:23:53 -0700 Subject: [PATCH] remove incorrect references to JWT in example application fixes #69 --- examples/token_auth.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/token_auth.py b/examples/token_auth.py index 99c4b43..e352860 100644 --- a/examples/token_auth.py +++ b/examples/token_auth.py @@ -2,7 +2,7 @@ """Token authentication example This example demonstrates how to protect Flask endpoints with token -authentication, using JWT tokens. +authentication, using tokens. When this application starts, a token is generated for each of the two users. To gain access, you can use a command line HTTP client such as curl, passing @@ -10,23 +10,23 @@ curl -X GET -H "Authorization: Bearer " http://localhost:5000/ -The response should include the username, which is obtained from the JWT token. +The response should include the username, which is obtained from the token. """ from flask import Flask, g from flask_httpauth import HTTPTokenAuth -from itsdangerous import TimedJSONWebSignatureSerializer as JWT +from itsdangerous import TimedJSONWebSignatureSerializer as Serializer app = Flask(__name__) app.config['SECRET_KEY'] = 'top secret!' -jwt = JWT(app.config['SECRET_KEY'], expires_in=3600) +token_serializer = Serializer(app.config['SECRET_KEY'], expires_in=3600) auth = HTTPTokenAuth('Bearer') users = ['john', 'susan'] for user in users: - token = jwt.dumps({'username': user}) + token = token_serializer.dumps({'username': user}).decode('utf-8') print('*** token for {}: {}\n'.format(user, token)) @@ -34,7 +34,7 @@ def verify_token(token): g.user = None try: - data = jwt.loads(token) + data = token_serializer.loads(token) except: # noqa: E722 return False if 'username' in data: