Skip to content

Commit

Permalink
Update token auth handling to use HanaToken model instead of encoded …
Browse files Browse the repository at this point in the history
…string
  • Loading branch information
NeonDaniel committed Nov 12, 2024
1 parent 7987ce6 commit d0776e9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions neon_users_service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from copy import copy
from typing import Optional
from ovos_config import Configuration

from neon_data_models.models.api.jwt import HanaToken
from neon_users_service.databases import UserDatabase
from neon_users_service.exceptions import (ConfigurationError,
AuthenticationError,
Expand Down Expand Up @@ -58,11 +60,11 @@ def create_user(self, user: User) -> User:
return self.database.create_user(user)

def _read_user(self, user_spec: str, password: Optional[str] = None,
auth_token: Optional[str] = None) -> User:
auth_token: Optional[HanaToken] = None) -> User:
user = self.database.read_user(user_spec)
if password and self._ensure_hashed(password) == user.password_hash:
return user
elif auth_token and any((tok.access_token == auth_token
elif auth_token and any((tok.jti == f"{auth_token.jti}.refresh"
for tok in user.tokens)):
return user
else:
Expand All @@ -82,7 +84,7 @@ def read_unauthenticated_user(self, user_spec: str) -> User:

def read_authenticated_user(self, username: str,
password: Optional[str] = None,
auth_token: Optional[str] = None) -> User:
auth_token: Optional[HanaToken] = None) -> User:
"""
Helper to get a user from the database, only if the requested username
and password match a database entry.
Expand Down

0 comments on commit d0776e9

Please sign in to comment.