tba-protocol-oauth 0.4.0.dev2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. tba_protocol_oauth/__init__.py +122 -0
  2. tba_protocol_oauth/bindings.py +116 -0
  3. tba_protocol_oauth/capability_requirements.py +5 -0
  4. tba_protocol_oauth/claim_sets.py +19 -0
  5. tba_protocol_oauth/claims.py +79 -0
  6. tba_protocol_oauth/compatibility.py +39 -0
  7. tba_protocol_oauth/errors.py +25 -0
  8. tba_protocol_oauth/features.py +36 -0
  9. tba_protocol_oauth/jwtoken.py +16 -0
  10. tba_protocol_oauth/migrations.py +37 -0
  11. tba_protocol_oauth/protocol.py +282 -0
  12. tba_protocol_oauth/py.typed +0 -0
  13. tba_protocol_oauth/reusable_components.py +5 -0
  14. tba_protocol_oauth/schemas.py +198 -0
  15. tba_protocol_oauth/standards/__init__.py +9 -0
  16. tba_protocol_oauth/standards/_dpop/__init__.py +57 -0
  17. tba_protocol_oauth/standards/_dpop/metadata.py +18 -0
  18. tba_protocol_oauth/standards/_dpop/primitives.py +194 -0
  19. tba_protocol_oauth/standards/_dpop/proofs.py +393 -0
  20. tba_protocol_oauth/standards/_dpop/state.py +74 -0
  21. tba_protocol_oauth/standards/_introspection_activity.py +32 -0
  22. tba_protocol_oauth/standards/_mtls_identity.py +98 -0
  23. tba_protocol_oauth/standards/_rfc8693/__init__.py +26 -0
  24. tba_protocol_oauth/standards/_rfc8693/endpoint.py +56 -0
  25. tba_protocol_oauth/standards/_rfc8693/runtime.py +289 -0
  26. tba_protocol_oauth/standards/_rfc9700/__init__.py +45 -0
  27. tba_protocol_oauth/standards/_rfc9700/security_profile.py +265 -0
  28. tba_protocol_oauth/standards/_rfc9700/sender_constraints.py +397 -0
  29. tba_protocol_oauth/standards/assertion_framework.py +173 -0
  30. tba_protocol_oauth/standards/authorization_framework.py +102 -0
  31. tba_protocol_oauth/standards/authorization_server_metadata.py +43 -0
  32. tba_protocol_oauth/standards/authorization_server_metadata_endpoint.py +21 -0
  33. tba_protocol_oauth/standards/bearer_token_usage.py +86 -0
  34. tba_protocol_oauth/standards/client_registration_management.py +89 -0
  35. tba_protocol_oauth/standards/device_authorization.py +140 -0
  36. tba_protocol_oauth/standards/dpop.py +59 -0
  37. tba_protocol_oauth/standards/dynamic_client_registration.py +68 -0
  38. tba_protocol_oauth/standards/gnap.py +6 -0
  39. tba_protocol_oauth/standards/introspection.py +56 -0
  40. tba_protocol_oauth/standards/issuer_identification.py +130 -0
  41. tba_protocol_oauth/standards/json_web_token.py +159 -0
  42. tba_protocol_oauth/standards/jwt_access_tokens.py +44 -0
  43. tba_protocol_oauth/standards/jwt_best_practices.py +44 -0
  44. tba_protocol_oauth/standards/jwt_client_auth.py +208 -0
  45. tba_protocol_oauth/standards/jwt_secured_authorization_requests.py +421 -0
  46. tba_protocol_oauth/standards/legacy_jwt_client_assertions.py +113 -0
  47. tba_protocol_oauth/standards/mutual_tls_client_authentication.py +394 -0
  48. tba_protocol_oauth/standards/native_apps.py +132 -0
  49. tba_protocol_oauth/standards/oauth_security_bcp.py +47 -0
  50. tba_protocol_oauth/standards/proof_key_for_code_exchange.py +82 -0
  51. tba_protocol_oauth/standards/protected_resource_metadata.py +103 -0
  52. tba_protocol_oauth/standards/pushed_authorization_requests.py +198 -0
  53. tba_protocol_oauth/standards/resource_indicators.py +127 -0
  54. tba_protocol_oauth/standards/resource_verifier_contract.py +91 -0
  55. tba_protocol_oauth/standards/revocation.py +59 -0
  56. tba_protocol_oauth/standards/rich_authorization_requests.py +221 -0
  57. tba_protocol_oauth/standards/token_endpoint.py +76 -0
  58. tba_protocol_oauth/standards/token_exchange.py +60 -0
  59. tba_protocol_oauth/versions.py +110 -0
  60. tba_protocol_oauth-0.4.0.dev2.dist-info/METADATA +114 -0
  61. tba_protocol_oauth-0.4.0.dev2.dist-info/RECORD +62 -0
  62. tba_protocol_oauth-0.4.0.dev2.dist-info/WHEEL +4 -0
@@ -0,0 +1,122 @@
1
+ """Versioned OAuth authorization-framework and extension protocol ownership."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from tba_contracts_identity.protocol_processing import (
6
+ build_protocol_capability_report,
7
+ )
8
+
9
+ from .bindings import CAPABILITY_REQUIREMENTS
10
+ from .claims import (
11
+ OAUTH_DPOP_PROOF_CLAIMS,
12
+ OAUTH_EXTENSION_CLAIMS,
13
+ OAUTH_TOKEN_EXCHANGE_CLAIMS,
14
+ compose_dpop_proof_claim_set,
15
+ compose_oauth_claim_set,
16
+ compose_token_exchange_claim_set,
17
+ )
18
+ from .compatibility import COMPATIBILITY_PATHS, OAuthCompatibility, compatibility
19
+ from .errors import OAuthBindingError, OAuthProtocolError, UnsupportedOAuthRevisionError
20
+ from .features import FEATURES_BY_VERSION, supports
21
+ from .migrations import REMOVED_GRANTS, migrate_client
22
+ from .protocol import (
23
+ DPoPProof,
24
+ DeviceAuthorization,
25
+ InMemoryOAuthRepository,
26
+ InMemoryOAuthState,
27
+ OAuthClient,
28
+ OAuthError,
29
+ OAuthGrantStatus,
30
+ OAuthProtocolService,
31
+ OAuthStateOperations,
32
+ TokenExchangeResult,
33
+ sha256_thumbprint,
34
+ )
35
+ from .schemas import (
36
+ AuthorizationCodeGrantForm,
37
+ DeviceAuthorizationIn,
38
+ DeviceAuthorizationOut,
39
+ DynamicClientRegistrationIn,
40
+ DynamicClientRegistrationManagementIn,
41
+ DynamicClientRegistrationOut,
42
+ IntrospectOut,
43
+ PasswordGrantForm,
44
+ PushedAuthorizationRequestIn,
45
+ PushedAuthorizationResponse,
46
+ RefreshIn,
47
+ RevocationIn,
48
+ RevocationOut,
49
+ TokenPair,
50
+ )
51
+ from .versions import (
52
+ CURRENT_VERSION,
53
+ EXTENSION_SPECIFICATIONS,
54
+ VERSION_HISTORY,
55
+ OAuthExtensionSpecification,
56
+ OAuthVersion,
57
+ select_version,
58
+ )
59
+
60
+
61
+ def capability_report() -> dict[str, object]:
62
+ return build_protocol_capability_report(
63
+ protocol="oauth",
64
+ revision=CURRENT_VERSION.identifier,
65
+ features=tuple(FEATURES_BY_VERSION[CURRENT_VERSION.identifier]),
66
+ evidence_links=("tests/unit/test_versioned_oauth_oidc_protocols.py",),
67
+ extra_requirements=CAPABILITY_REQUIREMENTS,
68
+ include_default_artifact_requirements=False,
69
+ )
70
+
71
+
72
+ __all__ = [
73
+ "CAPABILITY_REQUIREMENTS",
74
+ "COMPATIBILITY_PATHS",
75
+ "CURRENT_VERSION",
76
+ "EXTENSION_SPECIFICATIONS",
77
+ "FEATURES_BY_VERSION",
78
+ "OAUTH_DPOP_PROOF_CLAIMS",
79
+ "OAUTH_EXTENSION_CLAIMS",
80
+ "OAUTH_TOKEN_EXCHANGE_CLAIMS",
81
+ "REMOVED_GRANTS",
82
+ "VERSION_HISTORY",
83
+ "AuthorizationCodeGrantForm",
84
+ "DPoPProof",
85
+ "DeviceAuthorization",
86
+ "DeviceAuthorizationIn",
87
+ "DeviceAuthorizationOut",
88
+ "DynamicClientRegistrationIn",
89
+ "DynamicClientRegistrationManagementIn",
90
+ "DynamicClientRegistrationOut",
91
+ "InMemoryOAuthRepository",
92
+ "InMemoryOAuthState",
93
+ "IntrospectOut",
94
+ "OAuthBindingError",
95
+ "OAuthClient",
96
+ "OAuthCompatibility",
97
+ "OAuthError",
98
+ "OAuthExtensionSpecification",
99
+ "OAuthGrantStatus",
100
+ "OAuthProtocolError",
101
+ "OAuthProtocolService",
102
+ "OAuthStateOperations",
103
+ "OAuthVersion",
104
+ "PasswordGrantForm",
105
+ "PushedAuthorizationRequestIn",
106
+ "PushedAuthorizationResponse",
107
+ "RefreshIn",
108
+ "RevocationIn",
109
+ "RevocationOut",
110
+ "TokenExchangeResult",
111
+ "TokenPair",
112
+ "UnsupportedOAuthRevisionError",
113
+ "capability_report",
114
+ "compatibility",
115
+ "compose_dpop_proof_claim_set",
116
+ "compose_oauth_claim_set",
117
+ "compose_token_exchange_claim_set",
118
+ "migrate_client",
119
+ "select_version",
120
+ "sha256_thumbprint",
121
+ "supports",
122
+ ]
@@ -0,0 +1,116 @@
1
+ """OAuth wire operations mapped to reportable semantic capabilities."""
2
+
3
+ from tba_contracts_identity.capabilities import ProtocolCapabilityRequirement
4
+
5
+ CAPABILITY_REQUIREMENTS = (
6
+ ProtocolCapabilityRequirement(
7
+ "oauth-token-endpoint",
8
+ "RFC6749",
9
+ "issue-token-pair",
10
+ "POST /token",
11
+ "token.issuance",
12
+ "issue_token_pair",
13
+ "oauth:rfc6749",
14
+ ),
15
+ ProtocolCapabilityRequirement(
16
+ "oauth-token-endpoint",
17
+ "RFC6749",
18
+ "rotate-refresh-token",
19
+ "refresh_token grant",
20
+ "token.issuance",
21
+ "redeem_refresh_token",
22
+ "oauth:rfc6749",
23
+ ),
24
+ ProtocolCapabilityRequirement(
25
+ "oauth-token-revocation",
26
+ "RFC7009",
27
+ "token-revocation",
28
+ "/revoke",
29
+ "token.revocation",
30
+ "revoke_token",
31
+ "oauth:rfc7009",
32
+ ),
33
+ ProtocolCapabilityRequirement(
34
+ "oauth-token-introspection",
35
+ "RFC7662",
36
+ "token-introspection",
37
+ "/introspect",
38
+ "token.introspection",
39
+ "introspect_token",
40
+ "oauth:rfc7662",
41
+ ),
42
+ ProtocolCapabilityRequirement(
43
+ "oauth-token-exchange",
44
+ "RFC8693",
45
+ "token-exchange",
46
+ "POST /token/exchange",
47
+ "token.exchange",
48
+ "exchange_token",
49
+ "oauth:rfc8693",
50
+ ),
51
+ ProtocolCapabilityRequirement(
52
+ "oauth-pushed-authorization",
53
+ "RFC9126",
54
+ "pushed-authorization",
55
+ "/par",
56
+ "oauth.pushed-authorization",
57
+ "push_authorization_request",
58
+ "oauth:rfc9126",
59
+ ),
60
+ ProtocolCapabilityRequirement(
61
+ "oauth-dynamic-client-registration",
62
+ "RFC7591",
63
+ "register-client",
64
+ "POST /register",
65
+ "client.registration",
66
+ "register_client",
67
+ "oauth:rfc7591",
68
+ ),
69
+ ProtocolCapabilityRequirement(
70
+ "oauth-client-registration-management",
71
+ "RFC7592",
72
+ "read-registration",
73
+ "GET /register/{client_id}",
74
+ "client.registration",
75
+ "get_registration",
76
+ "oauth:rfc7592",
77
+ ),
78
+ ProtocolCapabilityRequirement(
79
+ "oauth-client-registration-management",
80
+ "RFC7592",
81
+ "update-registration",
82
+ "PUT /register/{client_id}",
83
+ "client.registration",
84
+ "update_registration",
85
+ "oauth:rfc7592",
86
+ ),
87
+ ProtocolCapabilityRequirement(
88
+ "oauth-client-registration-management",
89
+ "RFC7592",
90
+ "delete-registration",
91
+ "DELETE /register/{client_id}",
92
+ "client.registration",
93
+ "disable_registration",
94
+ "oauth:rfc7592",
95
+ ),
96
+ ProtocolCapabilityRequirement(
97
+ "oauth-dpop",
98
+ "RFC9449",
99
+ "dpop-jti-replay",
100
+ "jti",
101
+ "security.replay-protection",
102
+ "check_and_reserve",
103
+ "oauth:dpop-jti",
104
+ ),
105
+ ProtocolCapabilityRequirement(
106
+ "oauth-dpop",
107
+ "RFC9449",
108
+ "dpop-nonce-replay",
109
+ "nonce",
110
+ "security.replay-protection",
111
+ "check_and_reserve",
112
+ "oauth:dpop-nonce",
113
+ ),
114
+ )
115
+
116
+ __all__ = ["CAPABILITY_REQUIREMENTS"]
@@ -0,0 +1,5 @@
1
+ """Deprecated compatibility exports for :mod:`tba_protocol_oauth.bindings`."""
2
+
3
+ from .bindings import CAPABILITY_REQUIREMENTS
4
+
5
+ __all__ = ["CAPABILITY_REQUIREMENTS"]
@@ -0,0 +1,19 @@
1
+ """Deprecated compatibility exports for :mod:`tba_protocol_oauth.claims`."""
2
+
3
+ from .claims import (
4
+ OAUTH_DPOP_PROOF_CLAIMS,
5
+ OAUTH_EXTENSION_CLAIMS,
6
+ OAUTH_TOKEN_EXCHANGE_CLAIMS,
7
+ compose_dpop_proof_claim_set,
8
+ compose_oauth_claim_set,
9
+ compose_token_exchange_claim_set,
10
+ )
11
+
12
+ __all__ = [
13
+ "OAUTH_DPOP_PROOF_CLAIMS",
14
+ "OAUTH_EXTENSION_CLAIMS",
15
+ "OAUTH_TOKEN_EXCHANGE_CLAIMS",
16
+ "compose_dpop_proof_claim_set",
17
+ "compose_oauth_claim_set",
18
+ "compose_token_exchange_claim_set",
19
+ ]
@@ -0,0 +1,79 @@
1
+ """OAuth extension claim composition from standalone claim packages."""
2
+
3
+ from tba_concrete_claim_access_token_digest import AccessTokenDigestClaim
4
+ from tba_concrete_claim_actor import ActorClaim
5
+ from tba_concrete_claim_client_id import ClientIdClaim
6
+ from tba_concrete_claim_confirmation import ConfirmationClaim
7
+ from tba_concrete_claim_http_method import HttpMethodClaim
8
+ from tba_concrete_claim_http_uri import HttpUriClaim
9
+ from tba_concrete_claim_issued_at import IssuedAtClaim
10
+ from tba_concrete_claim_jwt_id import JwtIdClaim
11
+ from tba_concrete_claim_may_act import MayActClaim
12
+ from tba_concrete_claim_nonce import NonceClaim
13
+ from tba_concrete_claim_scope import ScopeClaim
14
+ from tba_contracts_identity.claims import ClaimSet
15
+
16
+ OAUTH_EXTENSION_CLAIMS = (ClientIdClaim, ScopeClaim, ConfirmationClaim)
17
+ OAUTH_DPOP_PROOF_CLAIMS = (
18
+ JwtIdClaim,
19
+ HttpMethodClaim,
20
+ HttpUriClaim,
21
+ IssuedAtClaim,
22
+ NonceClaim,
23
+ AccessTokenDigestClaim,
24
+ )
25
+ OAUTH_TOKEN_EXCHANGE_CLAIMS = (ActorClaim, MayActClaim)
26
+
27
+
28
+ def _compose(
29
+ claims: tuple[object, ...],
30
+ *,
31
+ allowed: tuple[type, ...],
32
+ protocol: str,
33
+ version: str,
34
+ ) -> ClaimSet:
35
+ unexpected = [
36
+ getattr(claim, "name", type(claim).__name__)
37
+ for claim in claims
38
+ if not isinstance(claim, allowed)
39
+ ]
40
+ if unexpected:
41
+ raise ValueError(f"claims are not valid for {protocol}: {unexpected}")
42
+ return ClaimSet(claims, protocol, version)
43
+
44
+
45
+ def compose_oauth_claim_set(*claims: object) -> ClaimSet:
46
+ return _compose(
47
+ claims,
48
+ allowed=OAUTH_EXTENSION_CLAIMS,
49
+ protocol="oauth-jwt-access-token",
50
+ version="RFC 9068",
51
+ )
52
+
53
+
54
+ def compose_dpop_proof_claim_set(*claims: object) -> ClaimSet:
55
+ return _compose(
56
+ claims,
57
+ allowed=OAUTH_DPOP_PROOF_CLAIMS,
58
+ protocol="dpop-proof",
59
+ version="RFC9449",
60
+ )
61
+
62
+
63
+ def compose_token_exchange_claim_set(*claims: object) -> ClaimSet:
64
+ return _compose(
65
+ claims,
66
+ allowed=OAUTH_TOKEN_EXCHANGE_CLAIMS,
67
+ protocol="oauth-token-exchange",
68
+ version="RFC8693",
69
+ )
70
+
71
+
72
+ __all__ = [
73
+ "OAUTH_DPOP_PROOF_CLAIMS",
74
+ "OAUTH_EXTENSION_CLAIMS",
75
+ "OAUTH_TOKEN_EXCHANGE_CLAIMS",
76
+ "compose_dpop_proof_claim_set",
77
+ "compose_oauth_claim_set",
78
+ "compose_token_exchange_claim_set",
79
+ ]
@@ -0,0 +1,39 @@
1
+ """Compatibility paths for the OAuth authorization-framework profile."""
2
+
3
+ from dataclasses import dataclass
4
+
5
+ from .versions import CURRENT_VERSION, VERSION_HISTORY
6
+
7
+
8
+ @dataclass(frozen=True, slots=True)
9
+ class OAuthCompatibility:
10
+ source: str
11
+ target: str
12
+ compatible: bool
13
+ lossless: bool
14
+ migration_required: bool
15
+
16
+
17
+ COMPATIBILITY_PATHS = tuple(
18
+ OAuthCompatibility(
19
+ source=version.identifier,
20
+ target=CURRENT_VERSION.identifier,
21
+ compatible=True,
22
+ lossless=version.identifier == CURRENT_VERSION.identifier,
23
+ migration_required=version.identifier != CURRENT_VERSION.identifier,
24
+ )
25
+ for version in VERSION_HISTORY
26
+ )
27
+
28
+
29
+ def compatibility(
30
+ source: str,
31
+ target: str = CURRENT_VERSION.identifier,
32
+ ) -> OAuthCompatibility:
33
+ for path in COMPATIBILITY_PATHS:
34
+ if path.source == source and path.target == target:
35
+ return path
36
+ return OAuthCompatibility(source, target, False, False, False)
37
+
38
+
39
+ __all__ = ["COMPATIBILITY_PATHS", "OAuthCompatibility", "compatibility"]
@@ -0,0 +1,25 @@
1
+ """OAuth protocol mapping errors."""
2
+
3
+
4
+ class OAuthProtocolError(RuntimeError):
5
+ """Base error for an OAuth wire or profile failure."""
6
+
7
+ def __init__(self, code: str, description: str) -> None:
8
+ super().__init__(description)
9
+ self.code = code
10
+ self.description = description
11
+
12
+
13
+ class UnsupportedOAuthRevisionError(OAuthProtocolError):
14
+ """Raised when an OAuth profile revision has no supported path."""
15
+
16
+
17
+ class OAuthBindingError(OAuthProtocolError):
18
+ """Raised when an OAuth wire element cannot map to a capability."""
19
+
20
+
21
+ __all__ = [
22
+ "OAuthBindingError",
23
+ "OAuthProtocolError",
24
+ "UnsupportedOAuthRevisionError",
25
+ ]
@@ -0,0 +1,36 @@
1
+ _OAUTH_21_FEATURES = frozenset(
2
+ {
3
+ "authorization-code",
4
+ "client-credentials",
5
+ "refresh-token",
6
+ "pkce-required",
7
+ "exact-redirect-uri",
8
+ "no-implicit",
9
+ "no-password-grant",
10
+ }
11
+ )
12
+
13
+ FEATURES_BY_VERSION = {
14
+ "RFC6749": frozenset(
15
+ {
16
+ "authorization-code",
17
+ "implicit",
18
+ "password",
19
+ "client-credentials",
20
+ "refresh-token",
21
+ }
22
+ ),
23
+ "draft-ietf-oauth-v2-1-13": _OAUTH_21_FEATURES,
24
+ "draft-ietf-oauth-v2-1-14": _OAUTH_21_FEATURES,
25
+ "draft-ietf-oauth-v2-1-15": _OAUTH_21_FEATURES,
26
+ }
27
+
28
+
29
+ def supports(feature: str, version: str = "draft-ietf-oauth-v2-1-15") -> bool:
30
+ try:
31
+ return feature in FEATURES_BY_VERSION[version]
32
+ except KeyError as exc:
33
+ raise ValueError(f"unsupported OAuth version/profile: {version}") from exc
34
+
35
+
36
+ __all__ = ["FEATURES_BY_VERSION", "supports"]
@@ -0,0 +1,16 @@
1
+ """Compatibility export for the environment-backed JOSE provider.
2
+
3
+ OAuth wire/profile modules may consume the provider, but key loading, key
4
+ creation, filesystem access, and token service construction remain in layer 20.
5
+ """
6
+
7
+ from tba_provider_identity_jose.jwt_coder import JWTCoder
8
+ from tba_provider_identity_jose.errors import InvalidTokenError
9
+ from tba_contracts_identity.tokens import (
10
+ DEFAULT_ACCESS_TOKEN_TTL as _ACCESS_TTL,
11
+ DEFAULT_REFRESH_TOKEN_TTL as _REFRESH_TTL,
12
+ )
13
+
14
+ _ALG = "EdDSA"
15
+
16
+ __all__ = ["InvalidTokenError", "JWTCoder", "_ACCESS_TTL", "_ALG", "_REFRESH_TTL"]
@@ -0,0 +1,37 @@
1
+ from typing import Any, Mapping
2
+
3
+ REMOVED_GRANTS = frozenset({"implicit", "password"})
4
+
5
+
6
+ def migrate_client(
7
+ value: Mapping[str, Any],
8
+ *,
9
+ source: str,
10
+ target: str = "draft-ietf-oauth-v2-1-15",
11
+ ) -> dict[str, Any]:
12
+ if source == target:
13
+ return dict(value)
14
+ supported_drafts = {
15
+ "draft-ietf-oauth-v2-1-13",
16
+ "draft-ietf-oauth-v2-1-14",
17
+ "draft-ietf-oauth-v2-1-15",
18
+ }
19
+ if target != "draft-ietf-oauth-v2-1-15" or source not in {
20
+ "RFC6749",
21
+ *supported_drafts,
22
+ }:
23
+ raise ValueError(f"unsupported OAuth migration: {source} -> {target}")
24
+ if source in supported_drafts:
25
+ return dict(value)
26
+ grants = set(value.get("grant_types", ()))
27
+ removed = grants & REMOVED_GRANTS
28
+ if removed:
29
+ raise ValueError(
30
+ f"OAuth 2.1 migration requires replacement for removed grants: {sorted(removed)}"
31
+ )
32
+ migrated = dict(value)
33
+ migrated["require_pkce"] = True
34
+ return migrated
35
+
36
+
37
+ __all__ = ["REMOVED_GRANTS", "migrate_client"]