Identity Extraction¶
Built-in extractors¶
RemoteAddressExtractor (default)¶
Identifies clients by IP address. Handles X-Forwarded-For and X-Real-IP.
from drogue.core.identity import RemoteAddressExtractor
extractor = RemoteAddressExtractor(
trusted_proxies=["10.0.0.0/8"],
proxy_header="x-forwarded-for",
trust_x_real_ip=True,
)
UserExtractor¶
Identifies by authenticated user ID. Returns "anonymous" for unauthenticated requests.
from drogue.core.identity import UserExtractor
extractor = UserExtractor(
user_id_key="user_id",
anonymous_value="anonymous",
)
HeaderExtractor¶
Identifies by any HTTP header value.
from drogue.core.identity import HeaderExtractor
extractor = HeaderExtractor(header_name="x-api-key", fallback="anonymous")
StaticKeyExtractor¶
Uses a fixed key for global rate limiting.
Combining extractors¶
Use + or | to create composite extractors. First non-anonymous value wins:
from drogue.core.identity import RemoteAddressExtractor, UserExtractor
extractor = UserExtractor() + RemoteAddressExtractor()