swarmauri_auth_idp_keycloak 0.2.0.dev5__tar.gz → 0.11.0.dev2__tar.gz

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 (13) hide show
  1. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/PKG-INFO +16 -13
  2. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/README.md +10 -9
  3. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/pyproject.toml +6 -4
  4. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/swarmauri_auth_idp_keycloak/KeycloakOAuth20Login.py +3 -1
  5. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/swarmauri_auth_idp_keycloak/KeycloakOAuth21AppClient.py +14 -4
  6. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/swarmauri_auth_idp_keycloak/KeycloakOAuth21Login.py +6 -2
  7. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/swarmauri_auth_idp_keycloak/KeycloakOAuthLoginMixin.py +3 -1
  8. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/swarmauri_auth_idp_keycloak/KeycloakOIDC10AppClient.py +7 -2
  9. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/swarmauri_auth_idp_keycloak/KeycloakOIDC10Login.py +6 -2
  10. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/swarmauri_auth_idp_keycloak/KeycloakOIDCLoginMixin.py +5 -1
  11. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/LICENSE +0 -0
  12. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/swarmauri_auth_idp_keycloak/KeycloakOAuth20AppClient.py +0 -0
  13. {swarmauri_auth_idp_keycloak-0.2.0.dev5 → swarmauri_auth_idp_keycloak-0.11.0.dev2}/swarmauri_auth_idp_keycloak/__init__.py +0 -0
@@ -1,47 +1,48 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: swarmauri_auth_idp_keycloak
3
- Version: 0.2.0.dev5
3
+ Version: 0.11.0.dev2
4
4
  Summary: Keycloak OAuth 2.0 / OAuth 2.1 / OIDC 1.0 identity provider implementations for Swarmauri
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE
7
7
  Keywords: swarmauri,sdk,experimental,identity,oauth2,oauth21,oidc,keycloak,idp
8
8
  Author: Jacob Stewart
9
9
  Author-email: jacob@swarmauri.com
10
- Requires-Python: >=3.10,<3.13
10
+ Requires-Python: >=3.10,<3.15
11
11
  Classifier: Development Status :: 1 - Planning
12
12
  Classifier: Intended Audience :: Developers
13
13
  Classifier: License :: OSI Approved :: Apache Software License
14
14
  Classifier: Natural Language :: English
15
+ Classifier: Topic :: Internet :: WWW/HTTP
16
+ Classifier: Topic :: Security :: Cryptography
15
17
  Classifier: Programming Language :: Python
16
18
  Classifier: Programming Language :: Python :: 3
17
19
  Classifier: Programming Language :: Python :: 3 :: Only
18
20
  Classifier: Programming Language :: Python :: 3.10
19
21
  Classifier: Programming Language :: Python :: 3.11
20
22
  Classifier: Programming Language :: Python :: 3.12
21
- Classifier: Topic :: Internet :: WWW/HTTP
22
- Classifier: Topic :: Security :: Cryptography
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
23
25
  Requires-Dist: httpx (>=0.27)
24
26
  Requires-Dist: pyjwt[crypto] (>=2.8)
25
27
  Requires-Dist: swarmauri_base
26
28
  Requires-Dist: swarmauri_core
27
29
  Description-Content-Type: text/markdown
28
30
 
29
- ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/master/assets/swarmauri.brand.theme.svg)
31
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
30
32
 
31
33
  <p align="center">
34
+ <a href="https://pepy.tech/project/swarmauri_auth_idp_keycloak/">
35
+ <img src="https://static.pepy.tech/badge/swarmauri_auth_idp_keycloak/month" alt="PyPI - Downloads"/></a>
36
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_auth_idp_keycloak/">
37
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_auth_idp_keycloak.svg"/></a>
32
38
  <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
33
- <img src="https://img.shields.io/pypi/dm/swarmauri_auth_idp_keycloak" alt="PyPI - Downloads"/></a>
34
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_keycloak/">
35
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_keycloak.svg"/></a>
36
- <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
37
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_auth_idp_keycloak" alt="PyPI - Python Version"/></a>
39
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
38
40
  <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
39
41
  <img src="https://img.shields.io/pypi/l/swarmauri_auth_idp_keycloak" alt="PyPI - License"/></a>
40
42
  <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
41
43
  <img src="https://img.shields.io/pypi/v/swarmauri_auth_idp_keycloak?label=swarmauri_auth_idp_keycloak&color=green" alt="PyPI - swarmauri_auth_idp_keycloak"/></a>
42
- </p>
43
-
44
- ---
44
+ <a href="https://discord.gg/N4UpBuQv8T">
45
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
45
46
 
46
47
  # Swarmauri Auth IDP Keycloak
47
48
 
@@ -124,3 +125,5 @@ To contribute to swarmauri-sdk, review the
124
125
  [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
125
126
  which cover development workflow, testing, and coding standards.
126
127
 
128
+
129
+
@@ -1,19 +1,18 @@
1
- ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/master/assets/swarmauri.brand.theme.svg)
1
+ ![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)
2
2
 
3
3
  <p align="center">
4
+ <a href="https://pepy.tech/project/swarmauri_auth_idp_keycloak/">
5
+ <img src="https://static.pepy.tech/badge/swarmauri_auth_idp_keycloak/month" alt="PyPI - Downloads"/></a>
6
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_auth_idp_keycloak/">
7
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_auth_idp_keycloak.svg"/></a>
4
8
  <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
5
- <img src="https://img.shields.io/pypi/dm/swarmauri_auth_idp_keycloak" alt="PyPI - Downloads"/></a>
6
- <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_keycloak/">
7
- <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_keycloak.svg"/></a>
8
- <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
9
- <img src="https://img.shields.io/pypi/pyversions/swarmauri_auth_idp_keycloak" alt="PyPI - Python Version"/></a>
9
+ <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
10
10
  <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
11
11
  <img src="https://img.shields.io/pypi/l/swarmauri_auth_idp_keycloak" alt="PyPI - License"/></a>
12
12
  <a href="https://pypi.org/project/swarmauri_auth_idp_keycloak/">
13
13
  <img src="https://img.shields.io/pypi/v/swarmauri_auth_idp_keycloak?label=swarmauri_auth_idp_keycloak&color=green" alt="PyPI - swarmauri_auth_idp_keycloak"/></a>
14
- </p>
15
-
16
- ---
14
+ <a href="https://discord.gg/N4UpBuQv8T">
15
+ <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
17
16
 
18
17
  # Swarmauri Auth IDP Keycloak
19
18
 
@@ -95,3 +94,5 @@ asyncio.run(run_flow())
95
94
  To contribute to swarmauri-sdk, review the
96
95
  [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
97
96
  which cover development workflow, testing, and coding standards.
97
+
98
+
@@ -1,10 +1,10 @@
1
1
  [project]
2
2
  name = "swarmauri_auth_idp_keycloak"
3
- version = "0.2.0.dev5"
3
+ version = "0.11.0.dev2"
4
4
  description = "Keycloak OAuth 2.0 / OAuth 2.1 / OIDC 1.0 identity provider implementations for Swarmauri"
5
5
  license = "Apache-2.0"
6
6
  readme = "README.md"
7
- requires-python = ">=3.10,<3.13"
7
+ requires-python = ">=3.10,<3.15"
8
8
  repository = "https://github.com/swarmauri/swarmauri-sdk"
9
9
  authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
10
10
  classifiers = [
@@ -12,14 +12,16 @@ classifiers = [
12
12
  "Intended Audience :: Developers",
13
13
  "License :: OSI Approved :: Apache Software License",
14
14
  "Natural Language :: English",
15
+ "Topic :: Internet :: WWW/HTTP",
16
+ "Topic :: Security :: Cryptography",
15
17
  "Programming Language :: Python",
16
18
  "Programming Language :: Python :: 3",
17
19
  "Programming Language :: Python :: 3 :: Only",
18
20
  "Programming Language :: Python :: 3.10",
19
21
  "Programming Language :: Python :: 3.11",
20
22
  "Programming Language :: Python :: 3.12",
21
- "Topic :: Internet :: WWW/HTTP",
22
- "Topic :: Security :: Cryptography",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
23
25
  ]
24
26
  keywords = [
25
27
  "swarmauri",
@@ -18,7 +18,9 @@ class KeycloakOAuth20Login(KeycloakOAuthLoginMixin, OAuth20LoginBase):
18
18
  payload = await self._auth_payload()
19
19
  return {"url": payload["url"], "state": payload["state"]}
20
20
 
21
- async def exchange_and_identity(self, code: str, state: str) -> Mapping[str, Any]:
21
+ async def exchange_and_identity(
22
+ self, code: str, state: str
23
+ ) -> Mapping[str, Any]:
22
24
  tokens = await self._exchange_tokens(code, state)
23
25
  profile = await self._fetch_userinfo(tokens["access_token"])
24
26
  subject = profile.get("sub") or profile.get("id")
@@ -18,7 +18,9 @@ ASSERTION_TYPE = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
18
18
 
19
19
  @ComponentBase.register_type(OAuth21AppClientBase, "KeycloakOAuth21AppClient")
20
20
  class KeycloakOAuth21AppClient(OAuth21AppClientBase):
21
- """Request OAuth 2.1 tokens from Keycloak using secrets or private key JWT."""
21
+ """
22
+ Request OAuth 2.1 tokens from Keycloak using secrets or private key JWT.
23
+ """
22
24
 
23
25
  model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
24
26
 
@@ -38,10 +40,16 @@ class KeycloakOAuth21AppClient(OAuth21AppClientBase):
38
40
  return f"{self.issuer.rstrip('/')}/protocol/openid-connect/token"
39
41
 
40
42
  def _client_secret_value(self) -> Optional[str]:
41
- return self.client_secret.get_secret_value() if self.client_secret else None
43
+ return (
44
+ self.client_secret.get_secret_value()
45
+ if self.client_secret
46
+ else None
47
+ )
42
48
 
43
49
  @staticmethod
44
- def _load_private_key(jwk_payload: Mapping[str, Any], algorithm: str) -> Any:
50
+ def _load_private_key(
51
+ jwk_payload: Mapping[str, Any], algorithm: str
52
+ ) -> Any:
45
53
  serialized = json.dumps(jwk_payload)
46
54
  if algorithm.upper().startswith("ES"):
47
55
  return jwt.algorithms.ECAlgorithm.from_jwk(serialized)
@@ -86,7 +94,9 @@ class KeycloakOAuth21AppClient(OAuth21AppClientBase):
86
94
  else:
87
95
  secret = self._client_secret_value()
88
96
  if not secret:
89
- raise ValueError("client_secret or private_key_jwk must be provided")
97
+ raise ValueError(
98
+ "client_secret or private_key_jwk must be provided"
99
+ )
90
100
  auth = (self.client_id, secret)
91
101
  payload = form
92
102
  async with self.http_client_factory() as client:
@@ -18,7 +18,9 @@ class KeycloakOAuth21Login(KeycloakOIDCLoginMixin, OAuth21LoginBase):
18
18
  payload = await self._auth_payload()
19
19
  return {"url": payload["url"], "state": payload["state"]}
20
20
 
21
- async def exchange_and_identity(self, code: str, state: str) -> Mapping[str, Any]:
21
+ async def exchange_and_identity(
22
+ self, code: str, state: str
23
+ ) -> Mapping[str, Any]:
22
24
  tokens = await self._exchange_tokens(code, state)
23
25
  metadata = await self._metadata()
24
26
  claims = await self._decode_id_token(tokens, metadata)
@@ -26,6 +28,8 @@ class KeycloakOAuth21Login(KeycloakOIDCLoginMixin, OAuth21LoginBase):
26
28
  "issuer": "keycloak-oauth21",
27
29
  "sub": claims["sub"],
28
30
  "email": claims.get("email"),
29
- "name": claims.get("name") or claims.get("preferred_username") or "Unknown",
31
+ "name": claims.get("name")
32
+ or claims.get("preferred_username")
33
+ or "Unknown",
30
34
  "raw": {"tokens": tokens, "claims": claims},
31
35
  }
@@ -62,7 +62,9 @@ class KeycloakOAuthLoginMixin:
62
62
  )
63
63
  return {"url": url, "state": state, "verifier": verifier}
64
64
 
65
- async def _exchange_tokens(self, code: str, state: str) -> Mapping[str, Any]:
65
+ async def _exchange_tokens(
66
+ self, code: str, state: str
67
+ ) -> Mapping[str, Any]:
66
68
  payload = verify_state(self._state_secret_value(), state)
67
69
  metadata = await self._metadata()
68
70
  form = {
@@ -13,7 +13,9 @@ from swarmauri_base.auth_idp import OIDC10AppClientBase, RetryingAsyncClient
13
13
 
14
14
  @ComponentBase.register_type(OIDC10AppClientBase, "KeycloakOIDC10AppClient")
15
15
  class KeycloakOIDC10AppClient(OIDC10AppClientBase):
16
- """Discover Keycloak realm metadata and request machine-to-machine tokens."""
16
+ """
17
+ Discover Keycloak realm metadata and request machine-to-machine tokens.
18
+ """
17
19
 
18
20
  model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
19
21
 
@@ -47,7 +49,10 @@ class KeycloakOIDC10AppClient(OIDC10AppClientBase):
47
49
  response.raise_for_status()
48
50
  payload: Mapping[str, Any] = response.json()
49
51
  if self.discovery_cache_ttl_seconds > 0:
50
- self._discovery_cache = (payload, now + self.discovery_cache_ttl_seconds)
52
+ self._discovery_cache = (
53
+ payload,
54
+ now + self.discovery_cache_ttl_seconds,
55
+ )
51
56
  return payload
52
57
 
53
58
  async def _fetch_token(self, scope: Optional[str]) -> Tuple[str, float]:
@@ -23,8 +23,12 @@ class KeycloakOIDC10Login(KeycloakOIDCLoginMixin, OIDC10LoginBase):
23
23
  metadata = await self._metadata()
24
24
  claims = await self._decode_id_token(tokens, metadata)
25
25
  email = claims.get("email")
26
- name = claims.get("name") or claims.get("preferred_username") or "Unknown"
27
- if (not email or name == "Unknown") and metadata.get("userinfo_endpoint"):
26
+ name = (
27
+ claims.get("name") or claims.get("preferred_username") or "Unknown"
28
+ )
29
+ if (not email or name == "Unknown") and metadata.get(
30
+ "userinfo_endpoint"
31
+ ):
28
32
  profile = await self._fetch_userinfo(tokens["access_token"])
29
33
  email = profile.get("email") or email
30
34
  name = profile.get("name") or profile.get("given_name") or name
@@ -31,7 +31,11 @@ class KeycloakOIDCLoginMixin(KeycloakOAuthLoginMixin):
31
31
  response.raise_for_status()
32
32
  jwks = response.json()
33
33
  key_entry = next(
34
- (entry for entry in jwks.get("keys", []) if entry.get("kid") == kid),
34
+ (
35
+ entry
36
+ for entry in jwks.get("keys", [])
37
+ if entry.get("kid") == kid
38
+ ),
35
39
  None,
36
40
  )
37
41
  if not key_entry: