Coverage for src/mcpadapt/auth/providers.py: 100%
16 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-06 19:35 +0530
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-06 19:35 +0530
1"""Authentication provider classes for MCPAdapt."""
3from typing import Any
6class ApiKeyAuthProvider:
7 """Simple API key authentication provider."""
9 def __init__(self, header_name: str, header_value: str):
10 """Initialize with API key configuration.
12 Args:
13 header_name: Name of the header to send the API key in
14 header_value: The API key value
15 """
16 self.header_name = header_name
17 self.header_value = header_value
19 def get_headers(self) -> dict[str, str]:
20 """Get authentication headers.
22 Returns:
23 Dictionary of headers to add to requests
24 """
25 return {self.header_name: self.header_value}
28class BearerAuthProvider:
29 """Simple Bearer token authentication provider."""
31 def __init__(self, token: str):
32 """Initialize with Bearer token configuration.
34 Args:
35 token: The bearer token
36 """
37 self.token = token
39 def get_headers(self) -> dict[str, str]:
40 """Get authentication headers.
42 Returns:
43 Dictionary of headers to add to requests
44 """
45 return {"Authorization": f"Bearer {self.token}"}
48def get_auth_headers(auth_provider: Any) -> dict[str, str]:
49 """Get authentication headers from provider.
51 Args:
52 auth_provider: Authentication provider instance
54 Returns:
55 Dictionary of headers to add to requests
56 """
57 if isinstance(auth_provider, (ApiKeyAuthProvider, BearerAuthProvider)):
58 return auth_provider.get_headers()
59 return {}