mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
feat(python): add jwt token lifetime from config
This commit is contained in:
@ -92,6 +92,9 @@ class ConfigurationManager:
|
||||
def jwt_header(self) -> str:
|
||||
return environ.get('JWT_HEADER') or 'Authorization'
|
||||
|
||||
def jwt_expires_in(self) -> int:
|
||||
return int(environ.get('JWT_EXPIRES_IN', 5))
|
||||
|
||||
def jwt_use_for_request(self) -> bool:
|
||||
use = environ.get('JWT_USE_FOR_REQUEST')
|
||||
return string.boolean(use, True)
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
|
||||
"""
|
||||
|
||||
import time
|
||||
import jwt
|
||||
from src.configuration import ConfigurationManager
|
||||
|
||||
@ -34,6 +35,9 @@ def useForRequest():
|
||||
|
||||
# encode a payload object into a token using a secret key and decodes it into the utf-8 format
|
||||
def encode(payload):
|
||||
now = time.time()
|
||||
payload['iat'] = now
|
||||
payload['exp'] = now + config_manager.jwt_expires_in() * 60
|
||||
return jwt.encode(payload, config_manager.jwt_secret(), algorithm='HS256')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user