Authentication Service | Kamiwaza Docs
Documentation for Kamiwaza 0.8.0
This is documentation for Kamiwaza 0.8.0, which is no longer actively maintained. For the current GA release, see 1.0.1.
Overview
The Authentication Service (AuthService) provides comprehensive user authentication and authorization functionality for the Kamiwaza AI Platform. Located in kamiwaza_client/services/auth.py, this service handles user management, token-based authentication, and role-based access control (RBAC).
Key Features
- User Authentication (token-based)
- Local User Management
- Organization Management
- Role-Based Access Control (RBAC)
- Group Management
- Permission Management
Authentication Methods
Token-Based Authentication
# Login to get access token
token = client.auth.login_for_access_token(
username="user@example.com",
password="secure_password"
)
# Verify token
user = client.auth.verify_token(authorization="Bearer <token>")
Local Authentication
# Create local user
user = client.auth.create_local_user(LocalUserCreate(
username="newuser",
email="user@example.com",
password="securepass"
))
# Login locally
token = client.auth.login_local(username="newuser", password="securepass")
User Management
Available Methods
create_local_user(user: LocalUserCreate) -> User: Create a new local userlist_users() -> List[User]: List all users in the systemread_users_me(authorization: str): Get current user's informationread_user(user_id: UUID) -> User: Get specific user informationupdate_user(user_id: UUID, user: UserUpdate) -> User: Update user detailsdelete_user(user_id: UUID): Delete a userread_own_permissions(token: str) -> UserPermissions: Get current user's permissions
Organization Management
Available Methods
create_organization(org: OrganizationCreate) -> Organization: Create new organizationread_organization(org_id: UUID) -> Organization: Get organization detailsupdate_organization(org_id: UUID, org: OrganizationUpdate) -> Organization: Update organizationdelete_organization(org_id: UUID): Delete an organization
Group Management
Available Methods
create_group(group: GroupCreate) -> Group: Create new groupread_group(group_id: UUID) -> Group: Get group detailsupdate_group(group_id: UUID, group: GroupUpdate) -> Group: Update groupdelete_group(group_id: UUID): Delete a groupadd_user_to_group(user_id: UUID, group_id: UUID): Add user to groupremove_user_from_group(user_id: UUID, group_id: UUID): Remove user from group
Role Management
Available Methods
create_role(role: RoleCreate) -> Role: Create new roleread_role(role_id: UUID) -> Role: Get role detailsupdate_role(role_id: UUID, role: RoleUpdate) -> Role: Update roledelete_role(role_id: UUID): Delete a roleassign_role_to_group(group_id: UUID, role_id: UUID): Assign role to groupremove_role_from_group(group_id: UUID, role_id: UUID): Remove role from group
Rights Management
Available Methods
create_right(right: RightCreate) -> Right: Create new rightread_right(right_id: UUID) -> Right: Get right detailsupdate_right(right_id: UUID, right: RightUpdate) -> Right: Update rightdelete_right(right_id: UUID): Delete a rightassign_right_to_role(role_id: UUID, right_id: UUID): Assign right to roleremove_right_from_role(role_id: UUID, right_id: UUID): Remove right from role
Error Handling
The service includes built-in error handling for common authentication scenarios:
try:
token = client.auth.login_for_access_token(username="user", password="pass")
except AuthenticationError:
# Handle authentication failures
except APIError as e:
# Handle API errors
print(f"Operation failed: {e}")
Best Practices
- Always use secure passwords and handle credentials securely
- Implement proper token management (storage and refresh)
- Use role-based access control for granular permissions
- Regular audit of user permissions and access rights
- Clean up unused users, groups, and roles