mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
feat(python): add jwt token lifetime from config
This commit is contained in:
@ -1,5 +1,6 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
- python: jwt token lifetime from config
|
||||||
- java-spring: jwt token lifetime from config
|
- java-spring: jwt token lifetime from config
|
||||||
- java: jwt token lifetime from config
|
- java: jwt token lifetime from config
|
||||||
- csharp-mvc: jwt token lifetime from config
|
- csharp-mvc: jwt token lifetime from config
|
||||||
|
|||||||
@ -92,6 +92,9 @@ class ConfigurationManager:
|
|||||||
def jwt_header(self) -> str:
|
def jwt_header(self) -> str:
|
||||||
return environ.get('JWT_HEADER') or 'Authorization'
|
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:
|
def jwt_use_for_request(self) -> bool:
|
||||||
use = environ.get('JWT_USE_FOR_REQUEST')
|
use = environ.get('JWT_USE_FOR_REQUEST')
|
||||||
return string.boolean(use, True)
|
return string.boolean(use, True)
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import time
|
||||||
import jwt
|
import jwt
|
||||||
from src.configuration import ConfigurationManager
|
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
|
# encode a payload object into a token using a secret key and decodes it into the utf-8 format
|
||||||
def encode(payload):
|
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')
|
return jwt.encode(payload, config_manager.jwt_secret(), algorithm='HS256')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user