date-encode
This commit is contained in:
parent
e9b594703c
commit
6c97d39e24
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import time
|
||||||
import jwt
|
import jwt
|
||||||
|
from base.exceptions import ExpiredToken
|
||||||
from validations.auth import TokenPayload
|
from validations.auth import TokenPayload
|
||||||
from settings import JWT_ALGORITHM, JWT_SECRET_KEY
|
from settings import JWT_ALGORITHM, JWT_SECRET_KEY
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@ class JWTCodec:
|
||||||
# "user_email": user.email, # less secure
|
# "user_email": user.email, # less secure
|
||||||
# "device": device, # no use cases
|
# "device": device, # no use cases
|
||||||
"exp": exp,
|
"exp": exp,
|
||||||
"iat": datetime.utcnow()
|
"iat": time.mktime(datetime.now().timetuple()),
|
||||||
|
"iss": "discours"
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
return jwt.encode(payload, JWT_SECRET_KEY, JWT_ALGORITHM)
|
return jwt.encode(payload, JWT_SECRET_KEY, JWT_ALGORITHM)
|
||||||
|
@ -29,12 +30,13 @@ class JWTCodec:
|
||||||
key=JWT_SECRET_KEY,
|
key=JWT_SECRET_KEY,
|
||||||
options={
|
options={
|
||||||
"verify_exp": verify_exp,
|
"verify_exp": verify_exp,
|
||||||
"verify_signature": False
|
# "verify_signature": False
|
||||||
},
|
},
|
||||||
algorithms=[JWT_ALGORITHM],
|
algorithms=[JWT_ALGORITHM],
|
||||||
|
issuer="discours"
|
||||||
)
|
)
|
||||||
r = TokenPayload(**payload)
|
r = TokenPayload(**payload)
|
||||||
print('[jwtcodec] debug payload %r' % r)
|
print('[jwtcodec] debug payload %r' % r)
|
||||||
return r
|
return r
|
||||||
except Exception as e:
|
except jwt.ExpiredSignatureError:
|
||||||
print('[jwtcodec] JWT decode error %r' % e)
|
raise ExpiredToken
|
||||||
|
|
|
@ -6,6 +6,11 @@ class BaseHttpException(GraphQLError):
|
||||||
message = "500 Server error"
|
message = "500 Server error"
|
||||||
|
|
||||||
|
|
||||||
|
class ExpiredToken(BaseHttpException):
|
||||||
|
code = 403
|
||||||
|
message = "403 Expired Token"
|
||||||
|
|
||||||
|
|
||||||
class InvalidToken(BaseHttpException):
|
class InvalidToken(BaseHttpException):
|
||||||
code = 403
|
code = 403
|
||||||
message = "403 Invalid Token"
|
message = "403 Invalid Token"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user