Skip to content

Commit

Permalink
Fix #40 Auth token verification now uses session from request handler
Browse files Browse the repository at this point in the history
- This is very difficult to reproduce, so changing the request handler
  (which is currently the only caller of User.verify_auth_token()) to
  send its own session when calling is a best guess at solving this.
  • Loading branch information
jathanism committed Apr 13, 2015
1 parent d2a1f8a commit 1e7d821
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion nsot/handlers/util.py
Expand Up @@ -164,7 +164,9 @@ def get_current_user(self):
if auth_token is None:
raise exc.Unauthorized('Missing Required argument: auth_token')

user = models.User.verify_auth_token(email, auth_token)
user = models.User.verify_auth_token(
email, auth_token, session=self.session
)

# If user is bad this time, it's an invalid login
if user is None:
Expand Down
8 changes: 6 additions & 2 deletions nsot/models.py
Expand Up @@ -297,13 +297,17 @@ def verify_secret_key(self, secret_key):

@classmethod
def verify_auth_token(cls, email, auth_token,
expiration=None):
expiration=None, session=None):
"""Verify token and return a User object."""
if expiration is None:
expiration = settings.auth_token_expiry

# First we lookup the user by email
user = User.query().filter_by(email=email).scalar()
if session is None:
query = User.query()
else:
query = session.query(User)
user = query.filter_by(email=email).scalar()

if user is None:
log.debug('Invalid user when verifying token')
Expand Down
2 changes: 1 addition & 1 deletion nsot/version.py
@@ -1 +1 @@
__version__ = "0.5.1"
__version__ = "0.5.2"

0 comments on commit 1e7d821

Please sign in to comment.