diff --git a/gns3server/services/authentication.py b/gns3server/services/authentication.py index 3d165c55d..c507c01a8 100644 --- a/gns3server/services/authentication.py +++ b/gns3server/services/authentication.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 21c8a9ba6..8535a81b4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -417,7 +417,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