mirror of
https://github.com/sartography/spiffworkflow-backend.git
synced 2025-02-24 13:28:31 +00:00
mypy issues, still 172
This commit is contained in:
parent
6a5e145664
commit
7cb3c65527
@ -1,4 +1,5 @@
|
|||||||
"""User."""
|
"""User."""
|
||||||
|
from typing import Optional
|
||||||
import jwt
|
import jwt
|
||||||
import marshmallow
|
import marshmallow
|
||||||
from flask import current_app
|
from flask import current_app
|
||||||
@ -28,11 +29,15 @@ class UserModel(db.Model): # type: ignore
|
|||||||
overlaps="user_group_assignments,users",
|
overlaps="user_group_assignments,users",
|
||||||
)
|
)
|
||||||
|
|
||||||
def encode_auth_token(self):
|
def encode_auth_token(self) -> str:
|
||||||
"""Generates the Auth Token.
|
"""Generate the Auth Token.
|
||||||
|
|
||||||
:return: string
|
:return: string
|
||||||
"""
|
"""
|
||||||
|
secret_key = current_app.config.get("SECRET_KEY")
|
||||||
|
if secret_key is None:
|
||||||
|
raise KeyError("we need current_app.config to have a SECRET_KEY")
|
||||||
|
|
||||||
# hours = float(app.config['TOKEN_AUTH_TTL_HOURS'])
|
# hours = float(app.config['TOKEN_AUTH_TTL_HOURS'])
|
||||||
payload = {
|
payload = {
|
||||||
# 'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=hours, minutes=0, seconds=0),
|
# 'exp': datetime.datetime.utcnow() + datetime.timedelta(hours=hours, minutes=0, seconds=0),
|
||||||
@ -41,24 +46,28 @@ class UserModel(db.Model): # type: ignore
|
|||||||
}
|
}
|
||||||
return jwt.encode(
|
return jwt.encode(
|
||||||
payload,
|
payload,
|
||||||
current_app.config.get("SECRET_KEY"),
|
secret_key,
|
||||||
algorithm="HS256",
|
algorithm="HS256",
|
||||||
)
|
)
|
||||||
|
|
||||||
def is_admin(self):
|
def is_admin(self) -> bool:
|
||||||
"""Is_admin."""
|
"""Is_admin."""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def decode_auth_token(auth_token):
|
def decode_auth_token(auth_token: str) -> dict[str, Optional[str]]:
|
||||||
"""Decodes the auth token.
|
"""Decode the auth token.
|
||||||
|
|
||||||
:param auth_token:
|
:param auth_token:
|
||||||
:return: integer|string
|
:return: integer|string
|
||||||
"""
|
"""
|
||||||
|
secret_key = current_app.config.get("SECRET_KEY")
|
||||||
|
if secret_key is None:
|
||||||
|
raise KeyError("we need current_app.config to have a SECRET_KEY")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = jwt.decode(
|
payload = jwt.decode(
|
||||||
auth_token, current_app.config.get("SECRET_KEY"), algorithms="HS256"
|
auth_token, secret_key, algorithms="HS256"
|
||||||
)
|
)
|
||||||
return payload
|
return payload
|
||||||
except jwt.ExpiredSignatureError as exception:
|
except jwt.ExpiredSignatureError as exception:
|
||||||
|
@ -12,7 +12,7 @@ from spiffworkflow_backend.models.user import UserModel
|
|||||||
|
|
||||||
|
|
||||||
def verify_token(token=None):
|
def verify_token(token=None):
|
||||||
"""Verifies the token for the user (if provided).
|
"""Verify the token for the user (if provided).
|
||||||
|
|
||||||
If in production environment and token is not provided, gets user from the SSO headers and returns their token.
|
If in production environment and token is not provided, gets user from the SSO headers and returns their token.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user