Auth client
HTTP client used by user-service to call auth-service.
This module is intentionally free of any Pact dependency, it is production code.
The Pact dependency only appears in
test_consumer_auth,
which exercises this client against a Pact mock server to define the contract
between user_service
(consumer) and auth-service (provider).
This also demonstrates the consumer-driven philosophy: the client only requests
and parses the fields it actually needs (valid), even though auth-service
may return additional information in its response.
Classes¶
AuthClient(base_url: str)
¶
HTTP client for credential validation against auth-service.
This client is used by
user_service to
verify user credentials before creating accounts. It satisfies the
CredentialsVerifier
protocol and is the real implementation that would run in production.
The matching Pact consumer tests live in
test_consumer_auth.
| PARAMETER | DESCRIPTION |
|---|---|
base_url
|
Base URL of
TYPE:
|
Source code in examples/http/service_consumer_provider/auth_client.py
Functions¶
validate_credentials(username: str, password: str) -> bool
¶
Validate credentials against auth-service.
Sends a POST /auth/validate request with the supplied credentials and
returns whether auth-service considers them valid. This is the only
field the client reads from the response: an example of how
consumer-driven contracts focus on what the consumer actually uses.
| PARAMETER | DESCRIPTION |
|---|---|
username
|
Username to validate.
TYPE:
|
password
|
Password to validate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
|
| RAISES | DESCRIPTION |
|---|---|
HTTPError
|
If |