mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-09-29 23:30:11 +03:00
Merge pull request #2902 from markparonyan/mypy-services-authentication
fix(typing): resolve mypy errors in services.authentication
This commit is contained in:
commit
b9192438c9
@ -73,21 +73,23 @@ class AuthService:
|
||||
encoded_jwt = jwt.encode({"alg": algorithm}, to_encode, key)
|
||||
return encoded_jwt
|
||||
|
||||
def create_access_token(self, username, token_version: int = 0, secret_key: str = None, expires_in: int = 0) -> str:
|
||||
def create_access_token(
|
||||
self, username, token_version: int = 0, secret_key: Optional[str] = None, expires_in: int = 0
|
||||
) -> str:
|
||||
|
||||
if not expires_in:
|
||||
expires_in = Config.instance().settings.Controller.jwt_access_token_expire_minutes
|
||||
return self._create_token(username, token_version, "access", expires_in, secret_key)
|
||||
|
||||
def create_refresh_token(
|
||||
self, username, token_version: int = 0, secret_key: str = None, expires_in: int = 0
|
||||
self, username, token_version: int = 0, secret_key: Optional[str] = None, expires_in: int = 0
|
||||
) -> str:
|
||||
|
||||
if not expires_in:
|
||||
expires_in = Config.instance().settings.Controller.jwt_refresh_token_expire_minutes
|
||||
return self._create_token(username, token_version, "refresh", expires_in, secret_key)
|
||||
|
||||
def get_token_data(self, token: str, secret_key: str = None) -> TokenData:
|
||||
def get_token_data(self, token: str, secret_key: Optional[str] = None) -> TokenData:
|
||||
|
||||
def auth_error(detail: str) -> HTTPException:
|
||||
return HTTPException(
|
||||
@ -105,7 +107,7 @@ class AuthService:
|
||||
key = OctKey.import_key(secret_key)
|
||||
try:
|
||||
payload = jwt.decode(token, key, algorithms=[algorithm])
|
||||
username: str = payload.claims.get("sub")
|
||||
username: Optional[str] = payload.claims.get("sub")
|
||||
if username is None:
|
||||
raise auth_error("Invalid token: missing subject claim")
|
||||
# Validate the exp claim — joserfc does not validate time-based claims by default
|
||||
@ -123,5 +125,5 @@ class AuthService:
|
||||
raise auth_error(f"Invalid token ({type(e).__name__})")
|
||||
return token_data
|
||||
|
||||
def get_username_from_token(self, token: str, secret_key: str = None) -> Optional[str]:
|
||||
def get_username_from_token(self, token: str, secret_key: Optional[str] = None) -> Optional[str]:
|
||||
return self.get_token_data(token, secret_key).username
|
||||
|
||||
@ -395,7 +395,6 @@ module = [
|
||||
"gns3server.schemas.controller.templates.virtualbox_templates", # 1
|
||||
"gns3server.schemas.controller.templates.vmware_templates", # 1
|
||||
"gns3server.schemas.qemu_disk_image", # 2
|
||||
"gns3server.services.authentication", # 5
|
||||
"gns3server.services.computes", # 4
|
||||
"gns3server.services.templates", # 18
|
||||
"gns3server.utils.asyncio.aiozipstream", # 8
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user