Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update authverifierbase.py #2337

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 4 additions & 36 deletions keep/identitymanager/authverifierbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,44 +125,17 @@ def authenticate(
) -> AuthenticatedEntity:
"""
Authenticate the request using either token, API key, or HTTP basic auth.

Args:
request (Request): The incoming request.
api_key (Optional[str]): The API key from the header.
authorization (Optional[HTTPAuthorizationCredentials]): The HTTP basic auth credentials.
token (Optional[str]): The OAuth2 token.

Returns:
AuthenticatedEntity: The authenticated entity.

Raises:
HTTPException: If authentication fails.
"""
self.logger.debug("Attempting authentication")
if token:
self.logger.debug("Attempting to authenticate with bearer token")
try:
return self._verify_bearer_token(token)
except HTTPException:
raise
except Exception:
self.logger.exception("Failed to validate token")
raise HTTPException(
status_code=401, detail="Invalid authentication credentials"
)
return self._verify_bearer_token(token)

api_key = self._extract_api_key(request, api_key, authorization)
if api_key:
self.logger.debug("Attempting to authenticate with API key")
try:
return self._verify_api_key(request, api_key, authorization)
except HTTPException:
raise
except Exception:
self.logger.exception("Failed to validate API Key")
raise HTTPException(
status_code=401, detail="Invalid authentication credentials"
)
return self._verify_api_key(request, api_key, authorization)

self.logger.error("No valid authentication method found")
raise HTTPException(
status_code=401, detail="Missing authentication credentials"
Expand Down Expand Up @@ -364,14 +337,9 @@ def _verify_api_key(
role=role,
)

def _provision_user(self, tenant_api_key, user_name, role):
def _provision_user(self, tenant_api_key: str, user_name: str, role: str) -> None:
"""
Create a user for impersonation.

Args:
tenant_api_key: The API key used for impersonation.
user_name: The name of the user to create.
role: The role of the user to create.
"""
raise NotImplementedError(
"User provisioning not implemented"
Expand Down
Loading