MCPcopy
hub / github.com/PostHog/posthog / find_key_with_source

Method find_key_with_source

posthog/auth.py:31–51  ·  view source on GitHub ↗

Try to find personal API key in request and return it along with where it was found.

(
        cls,
        request: Union[HttpRequest, Request],
        request_data: Optional[Dict[str, Any]] = None,
        extra_data: Optional[Dict[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

29
30 @classmethod
31 def find_key_with_source(
32 cls,
33 request: Union[HttpRequest, Request],
34 request_data: Optional[Dict[str, Any]] = None,
35 extra_data: Optional[Dict[str, Any]] = None,
36 ) -> Optional[Tuple[str, str]]:
37 """Try to find personal API key in request and return it along with where it was found."""
38 if "HTTP_AUTHORIZATION" in request.META:
39 authorization_match = re.match(rf"^{cls.keyword}\s+(\S.+)$", request.META["HTTP_AUTHORIZATION"])
40 if authorization_match:
41 return authorization_match.group(1).strip(), "Authorization header"
42 data = request.data if request_data is None and isinstance(request, Request) else request_data
43
44 if data and "personal_api_key" in data:
45 return data["personal_api_key"], "body"
46 if "personal_api_key" in request.GET:
47 return request.GET["personal_api_key"], "query string"
48 if extra_data and "personal_api_key" in extra_data:
49 # compatibility with /capture endpoint
50 return extra_data["personal_api_key"], "query string data"
51 return None
52
53 @classmethod
54 def find_key(

Callers 3

process_viewMethod · 0.80
find_keyMethod · 0.80
authenticateMethod · 0.80

Calls 2

matchMethod · 0.80
groupMethod · 0.80

Tested by

no test coverage detected