Authentication Service | Kamiwaza Docs

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

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

Organization Management

Available Methods

Group Management

Available Methods

Role Management

Available Methods

Rights Management

Available Methods

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

  1. Always use secure passwords and handle credentials securely
  2. Implement proper token management (storage and refresh)
  3. Use role-based access control for granular permissions
  4. Regular audit of user permissions and access rights
  5. Clean up unused users, groups, and roles