Auth¶
erpc.auth ¶
eRPC authentication configuration dataclasses.
Maps the eRPC auth strategy surface to Python dataclasses. Each strategy type corresponds to a supported eRPC authentication method: secret tokens, JWT verification, Sign-In with Ethereum (SIWE), and network-level IP filtering.
Examples:
>>> from erpc.auth import AuthConfig, SecretAuth, SIWEAuth
>>> auth = AuthConfig(
... strategies=[
... SecretAuth(value="my-api-key", rate_limit_budget="free-tier"),
... SIWEAuth(rate_limit_budget="wallet-tier"),
... ]
... )
>>> auth.to_dict()["strategies"][0]["type"]
'secret'
AuthStrategy
dataclass
¶
Base class for eRPC authentication strategies.
Subclasses must set strategy_type and implement to_dict().
Attributes:
| Name | Type | Description |
|---|---|---|
strategy_type |
str
|
The eRPC strategy type identifier. |
Source code in erpc/auth.py
to_dict ¶
Serialize to an eRPC-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary matching the eRPC auth strategy YAML schema. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If called on the base class directly. |
Source code in erpc/auth.py
SecretAuth
dataclass
¶
Bases: AuthStrategy
Secret token authentication strategy.
Authenticates requests via a shared secret value (e.g., API key).
Attributes:
| Name | Type | Description |
|---|---|---|
value |
str
|
The secret token value. |
rate_limit_budget |
str | None
|
Optional rate limit budget name to apply. |
Examples:
>>> auth = SecretAuth(value="my-key")
>>> auth.to_dict()
{'type': 'secret', 'secret': {'value': 'my-key'}}
Source code in erpc/auth.py
to_dict ¶
Serialize to an eRPC-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with |
Source code in erpc/auth.py
JWTAuth
dataclass
¶
Bases: AuthStrategy
JWT (JSON Web Token) authentication strategy.
Verifies JWTs using public keys and extracts rate limit budget from a configurable claim.
Attributes:
| Name | Type | Description |
|---|---|---|
verification_keys |
list[dict[str, Any]]
|
List of key configs (algorithm + publicKeyPem). |
rate_limit_budget_claim_name |
str
|
JWT claim name containing the budget identifier. |
allowed_issuers |
list[str] | None
|
Optional whitelist of token issuers. |
allowed_audiences |
list[str] | None
|
Optional whitelist of token audiences. |
Examples:
>>> keys = [{"algorithm": "RS256", "publicKeyPem": "..."}]
>>> auth = JWTAuth(verification_keys=keys, rate_limit_budget_claim_name="plan")
>>> auth.to_dict()["type"]
'jwt'
Source code in erpc/auth.py
to_dict ¶
Serialize to an eRPC-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with |
Source code in erpc/auth.py
SIWEAuth
dataclass
¶
Bases: AuthStrategy
Sign-In with Ethereum (SIWE) authentication strategy.
Authenticates requests using EIP-4361 signed messages.
Attributes:
| Name | Type | Description |
|---|---|---|
rate_limit_budget |
str | None
|
Optional rate limit budget name to apply. |
Examples:
>>> auth = SIWEAuth(rate_limit_budget="wallet-tier")
>>> auth.to_dict()
{'type': 'siwe', 'rateLimitBudget': 'wallet-tier'}
Source code in erpc/auth.py
to_dict ¶
Serialize to an eRPC-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with |
Source code in erpc/auth.py
NetworkAuth
dataclass
¶
Bases: AuthStrategy
Network-level (IP-based) authentication strategy.
Restricts access by source IP address or CIDR range.
Attributes:
| Name | Type | Description |
|---|---|---|
rate_limit_budget |
str | None
|
Optional rate limit budget name to apply. |
allowed_ips |
list[str] | None
|
Optional list of allowed IP addresses or CIDR ranges. |
Examples:
>>> auth = NetworkAuth(allowed_ips=["10.0.0.0/8"])
>>> auth.to_dict()
{'type': 'network', 'network': {'allowedIPs': ['10.0.0.0/8']}}
Source code in erpc/auth.py
to_dict ¶
Serialize to an eRPC-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with |
Source code in erpc/auth.py
AuthConfig
dataclass
¶
Composable authentication configuration for an eRPC project.
Combines multiple authentication strategies. Each strategy is tried in order until one succeeds.
Attributes:
| Name | Type | Description |
|---|---|---|
strategies |
list[AuthStrategy]
|
Ordered list of authentication strategies. |
Examples:
>>> config = AuthConfig(strategies=[SecretAuth(value="key")])
>>> len(config.to_dict()["strategies"])
1
Source code in erpc/auth.py
to_dict ¶
Serialize to an eRPC-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with |