refactor authentication code

moved api_key secret manipulation (generating and getting) into
authentiation/utils, and added a property on the model, to facilitate
easier matching of authenticated requests and the api keys they used
This commit is contained in:
Leo Hemsted
2016-06-29 14:15:32 +01:00
parent 18b30de452
commit adbe02783d
7 changed files with 36 additions and 44 deletions

View File

@@ -5,14 +5,13 @@ from sqlalchemy.dialects.postgresql import (
UUID,
JSON
)
from sqlalchemy import UniqueConstraint
from app.encryption import (
hashpw,
check_hash
)
from app.authentication.utils import get_secret
from app import (
db,
encryption
@@ -135,6 +134,10 @@ class ApiKey(db.Model, Versioned):
UniqueConstraint('service_id', 'name', name='uix_service_to_key_name'),
)
@property
def unsigned_secret(self):
return get_secret(self.secret)
KEY_TYPE_NORMAL = 'normal'
KEY_TYPE_TEAM = 'team'