Skip to content

Commit

Permalink
remove incorrect references to JWT in example application
Browse files Browse the repository at this point in the history
fixes #69
  • Loading branch information
miguelgrinberg committed Jun 15, 2018
1 parent b6457ae commit a310b78
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions examples/token_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
"""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
one of the tokens:
curl -X GET -H "Authorization: Bearer <jwt-token>" 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))


@auth.verify_token
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:
Expand Down

0 comments on commit a310b78

Please sign in to comment.