iam-client 0.1.1__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.
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: iam-client
3
+ Version: 0.1.1
4
+ Summary: IAM client for services
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: requests>=2.31.0
8
+ Requires-Dist: pydantic>=2.5.0
9
+
10
+ # iam-client
11
+
12
+ A lightweight, production-ready **IAM client SDK** for backend services.
13
+
14
+ This package allows backend services to securely communicate with the
15
+ Identity and Access Management (IAM) system using **service credentials**.
16
+
17
+ ---
18
+
19
+ ## ✨ Features
20
+
21
+ - Service-to-service authentication
22
+ - Automatic service token retrieval
23
+ - Token introspection
24
+ - Fetch user details by user ID
25
+ - Clean, minimal Python API
26
+ - Designed for FastAPI backends
27
+
28
+ ---
29
+
30
+ ## 📦 Installation
31
+
32
+ ### Install directly from GitHub
33
+
34
+ ```bash
35
+ pip install git+https://github.com/YOUR_ORG/iam-client.git
36
+ ```
37
+
38
+
39
+ ### Install directly from GitHub
40
+
41
+ ```bash
42
+ pip install git+https://github.com/YOUR_ORG/iam-client.git@v0.1.0
43
+ ```
44
+
45
+
46
+ ## ✨ Configuration
47
+ Set the following environment variables in the consuming backend service:
48
+ ```
49
+ IAM_BASE_URL=https://iam.xyz.com
50
+ TENANT_SLUG=xyz
51
+ IAM_CLIENT_ID=xyz-backend
52
+ IAM_CLIENT_SECRET=super-secret
53
+ ```
54
+
55
+ ## ✨ Usage
56
+ ### Create IAM client (once per service)
57
+ ```
58
+ from iam_client.client import IAMClient
59
+
60
+ iam = IAMClient(
61
+ base_url="https://iam.xyz.com",
62
+ tenant_slug="xyz",
63
+ client_id="xyz-backend",
64
+ client_secret="super-secret",
65
+ )
66
+ ```
@@ -0,0 +1,57 @@
1
+ # iam-client
2
+
3
+ A lightweight, production-ready **IAM client SDK** for backend services.
4
+
5
+ This package allows backend services to securely communicate with the
6
+ Identity and Access Management (IAM) system using **service credentials**.
7
+
8
+ ---
9
+
10
+ ## ✨ Features
11
+
12
+ - Service-to-service authentication
13
+ - Automatic service token retrieval
14
+ - Token introspection
15
+ - Fetch user details by user ID
16
+ - Clean, minimal Python API
17
+ - Designed for FastAPI backends
18
+
19
+ ---
20
+
21
+ ## 📦 Installation
22
+
23
+ ### Install directly from GitHub
24
+
25
+ ```bash
26
+ pip install git+https://github.com/YOUR_ORG/iam-client.git
27
+ ```
28
+
29
+
30
+ ### Install directly from GitHub
31
+
32
+ ```bash
33
+ pip install git+https://github.com/YOUR_ORG/iam-client.git@v0.1.0
34
+ ```
35
+
36
+
37
+ ## ✨ Configuration
38
+ Set the following environment variables in the consuming backend service:
39
+ ```
40
+ IAM_BASE_URL=https://iam.xyz.com
41
+ TENANT_SLUG=xyz
42
+ IAM_CLIENT_ID=xyz-backend
43
+ IAM_CLIENT_SECRET=super-secret
44
+ ```
45
+
46
+ ## ✨ Usage
47
+ ### Create IAM client (once per service)
48
+ ```
49
+ from iam_client.client import IAMClient
50
+
51
+ iam = IAMClient(
52
+ base_url="https://iam.xyz.com",
53
+ tenant_slug="xyz",
54
+ client_id="xyz-backend",
55
+ client_secret="super-secret",
56
+ )
57
+ ```
File without changes
@@ -0,0 +1,52 @@
1
+ import requests
2
+ from typing import Optional
3
+ from .schemas import IAMUser, TokenIntrospection
4
+ from .exceptions import IAMUnauthorized, IAMUnavailable
5
+
6
+
7
+ class IAMClient:
8
+ def __init__(
9
+ self,
10
+ base_url: str,
11
+ tenant_slug: str,
12
+ client_id: str,
13
+ client_secret: str,
14
+ timeout: int = 5,
15
+ ):
16
+ self.base_url = base_url.rstrip("/")
17
+ self.tenant_slug = tenant_slug
18
+ self.client_id = client_id
19
+ self.client_secret = client_secret
20
+ self.timeout = timeout
21
+ self._client_token: Optional[str] = None
22
+
23
+ def _get_client_token(self) -> str:
24
+ resp = requests.post(
25
+ f"{self.base_url}/auth/client-token",
26
+ json={
27
+ "tenant_slug": self.tenant_slug,
28
+ "client_id": self.client_id,
29
+ "client_secret": self.client_secret,
30
+ },
31
+ timeout=self.timeout,
32
+ )
33
+
34
+ if resp.status_code != 200:
35
+ raise IAMUnauthorized("Failed to get client token")
36
+
37
+ return resp.json()["access_token"]
38
+
39
+ def _headers(self):
40
+ if not self._client_token:
41
+ self._client_token = self._get_client_token()
42
+ return {"Authorization": f"Bearer {self._client_token}"}
43
+
44
+ def get_user(self, user_id: str) -> IAMUser:
45
+ resp = requests.get(
46
+ f"{self.base_url}/users/{user_id}",
47
+ headers=self._headers(),
48
+ timeout=self.timeout,
49
+ )
50
+ if resp.status_code != 200:
51
+ raise IAMUnavailable("Failed to fetch user")
52
+ return IAMUser(**resp.json())
@@ -0,0 +1,10 @@
1
+ class IAMError(Exception):
2
+ pass
3
+
4
+
5
+ class IAMUnauthorized(IAMError):
6
+ pass
7
+
8
+
9
+ class IAMUnavailable(IAMError):
10
+ pass
@@ -0,0 +1,21 @@
1
+ from pydantic import BaseModel
2
+ from typing import List
3
+ import uuid
4
+
5
+
6
+ class IAMUser(BaseModel):
7
+ id: uuid.UUID
8
+ tenant_id: uuid.UUID
9
+ email: str | None
10
+ phone: str | None
11
+ roles: List[str]
12
+ is_active: bool
13
+
14
+
15
+ class TokenIntrospection(BaseModel):
16
+ active: bool
17
+ sub: uuid.UUID
18
+ tenant_id: uuid.UUID
19
+ client_id: uuid.UUID
20
+ roles: List[str]
21
+ scopes: List[str]
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: iam-client
3
+ Version: 0.1.1
4
+ Summary: IAM client for services
5
+ Requires-Python: >=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: requests>=2.31.0
8
+ Requires-Dist: pydantic>=2.5.0
9
+
10
+ # iam-client
11
+
12
+ A lightweight, production-ready **IAM client SDK** for backend services.
13
+
14
+ This package allows backend services to securely communicate with the
15
+ Identity and Access Management (IAM) system using **service credentials**.
16
+
17
+ ---
18
+
19
+ ## ✨ Features
20
+
21
+ - Service-to-service authentication
22
+ - Automatic service token retrieval
23
+ - Token introspection
24
+ - Fetch user details by user ID
25
+ - Clean, minimal Python API
26
+ - Designed for FastAPI backends
27
+
28
+ ---
29
+
30
+ ## 📦 Installation
31
+
32
+ ### Install directly from GitHub
33
+
34
+ ```bash
35
+ pip install git+https://github.com/YOUR_ORG/iam-client.git
36
+ ```
37
+
38
+
39
+ ### Install directly from GitHub
40
+
41
+ ```bash
42
+ pip install git+https://github.com/YOUR_ORG/iam-client.git@v0.1.0
43
+ ```
44
+
45
+
46
+ ## ✨ Configuration
47
+ Set the following environment variables in the consuming backend service:
48
+ ```
49
+ IAM_BASE_URL=https://iam.xyz.com
50
+ TENANT_SLUG=xyz
51
+ IAM_CLIENT_ID=xyz-backend
52
+ IAM_CLIENT_SECRET=super-secret
53
+ ```
54
+
55
+ ## ✨ Usage
56
+ ### Create IAM client (once per service)
57
+ ```
58
+ from iam_client.client import IAMClient
59
+
60
+ iam = IAMClient(
61
+ base_url="https://iam.xyz.com",
62
+ tenant_slug="xyz",
63
+ client_id="xyz-backend",
64
+ client_secret="super-secret",
65
+ )
66
+ ```
@@ -0,0 +1,11 @@
1
+ README.md
2
+ pyproject.toml
3
+ iam_client/__init__.py
4
+ iam_client/client.py
5
+ iam_client/exceptions.py
6
+ iam_client/schemas.py
7
+ iam_client.egg-info/PKG-INFO
8
+ iam_client.egg-info/SOURCES.txt
9
+ iam_client.egg-info/dependency_links.txt
10
+ iam_client.egg-info/requires.txt
11
+ iam_client.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ requests>=2.31.0
2
+ pydantic>=2.5.0
@@ -0,0 +1,2 @@
1
+ dist
2
+ iam_client
@@ -0,0 +1,17 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "iam-client"
7
+ version = "0.1.1"
8
+ description = "IAM client for services"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = [
12
+ "requests>=2.31.0",
13
+ "pydantic>=2.5.0"
14
+ ]
15
+
16
+ [tool.setuptools.packages.find]
17
+ where = ["."]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+