🔐 goiam-python
Installation
Bash
pip install goiam-python
# or
poetry add goiam-python
# or
pipenv install goiam-python
Usage
Initialize the SDK
Python
from goiam import new_service
service = new_service(
base_url="https://go-iam.example.com",
client_id="your-client-id",
secret="your-secret"
)
Verify Authentication Code
Python
try:
token = service.verify("auth-code")
print(f"Access Token: {token}")
except Exception as error:
print(f"Failed to verify code: {error}")
Fetch Current User Information
Python
try:
user = service.me(token)
print(f"User: {user.name} ({user.email})")
except Exception as error:
print(f"Failed to fetch user information: {error}")
Create a Resource
Python
from goiam import Resource
resource = Resource(
id="resource-id",
name="Resource Name",
description="Resource Description",
key="resource-key",
enabled=True,
project_id="project-id",
created_by="creator",
updated_by="updater"
)
try:
service.create_resource(resource, token)
print("Resource created successfully")
except Exception as error:
print(f"Failed to create resource: {error}")
Classes
User
Python
class User:
def __init__(self, data: Dict[str, Any]):
self.id: str = data.get("id", "")
self.project_id: str = data.get("project_id", "")
self.name: str = data.get("name", "")
self.email: str = data.get("email", "")
self.phone: str = data.get("phone", "")
self.enabled: bool = data.get("enabled", False)
self.profile_pic: str = data.get("profile_pic", "")
self.expiry: Optional[str] = data.get("expiry")
self.roles: Dict[str, "UserRole"] = {
k: UserRole(v) for k, v in data.get("roles", {}).items()
}
self.resources: Dict[str, "UserResource"] = {
k: UserResource(v) for k, v in data.get("resources", {}).items()
}
self.policies: Dict[str, str] = data.get("policies", {})
self.created_at: Optional[str] = data.get("created_at")
self.created_by: str = data.get("created_by", "")
self.updated_at: Optional[str] = data.get("updated_at")
self.updated_by: str = data.get("updated_by", "")
class UserPolicy:
def __init__(self, data: Dict[str, Any]):
self.name: str = data.get("name", "")
self.mapping: UserPolicyMapping = UserPolicyMapping(data.get("mapping", {}))
class UserPolicyMapping:
def __init__(self, data: Dict[str, Any]):
self.arguments: Dict[str, UserPolicyMappingValue] = {
k: UserPolicyMappingValue(v) for k, v in data.get("arguments", {}).items()
}
class UserPolicyMappingValue:
def __init__(self, data: Dict[str, Any]):
self.static: str = data.get("static", "")
class UserRole:
def __init__(self, data: Dict[str, Any]):
self.id: str = data.get("id", "")
self.name: str = data.get("name", "")
class UserResource:
def __init__(self, data: Dict[str, Any]):
self.role_ids: Dict[str, bool] = data.get("role_ids", {})
self.policy_ids: Dict[str, bool] = data.get("policy_ids", {})
self.key: str = data.get("key", "")
self.name: str = data.get("name", "")
Resource
Python
class Resource:
def __init__(self,
id: str = '',
name: str = '',
description: str = '',
key: str = '',
enabled: bool = True,
project_id: str = '',
created_by: str = '',
updated_by: str = '',
created_at: Optional[str] = None,
updated_at: Optional[str] = None,
deleted_at: Optional[str] = None):
# ...
Error Handling
Python
try:
result = service.verify("code")
# Handle success
except Exception as error:
print(f"API Error: {error}")
# Handle error