Skip to main content

Python SDK for GAuth API - GearVN Authentication Service

Project description

GAuth SDK for Python

Python SDK for GAuth API - GearVN Authentication Service.

Installation

pip install gauthsdk

Or install from source:

pip install -e .

Quick Start

from gauthsdk import Client

# Initialize client with API Key (for S2S operations)
client = Client(
    api_key="gvn_sk_your_api_key_here",
    base_url="http://localhost:3000",
)

# Get user by ID
user = client.users.get("user-uuid")
print(f"User: {user.full_name()}")
print(f"Email: {user.email}")
print(f"Role: {user.role}")

# List users with pagination
result = client.users.list(page=1, limit=20)
for user in result.users:
    print(f"- {user.email}: {user.status}")
print(f"Total users: {result.paging.total}")

# Validate JWT token
claims = client.validate_token("user_jwt_token")
print(f"User ID: {claims.sub}")
print(f"Tenant ID: {claims.tenant_id}")
print(f"Role: {claims.role}")

Features

Users API

# Get user by ID
user = client.users.get("user-uuid")

# List users with filters
result = client.users.list(
    page=1,
    limit=20,
    status="active",
    role="user",
    search="john",
)

# List user sessions
sessions = client.users.list_sessions("user-uuid")
for session in sessions:
    print(f"Session: {session.id}, Created: {session.created_at}")

# Revoke a session
client.users.revoke_session("user-uuid", "session-uuid")

Auth API

For auth operations (login, register, etc.), you need to set tenant_id:

client = Client(
    api_key="gvn_sk_...",
    tenant_id="tenant-uuid",
    base_url="http://localhost:3000",
)

# Login
tokens = client.auth.login("user@example.com", "password")
print(f"Access Token: {tokens.access_token}")
print(f"Refresh Token: {tokens.refresh_token}")

# Refresh token
new_tokens = client.auth.refresh_token(tokens.refresh_token)
print(f"New Access Token: {new_tokens.access_token}")

# Validate token
claims = client.auth.validate_token(tokens.access_token)
print(f"User: {claims.sub}")

Error Handling

from gauthsdk import Client, APIError

client = Client(api_key="gvn_sk_...")

try:
    user = client.users.get("invalid-uuid")
except APIError as e:
    print(f"Error {e.code}: {e.message}")

    if e.is_not_found():
        print("User not found")
    elif e.is_unauthorized():
        print("Invalid API key")
    elif e.is_forbidden():
        print("Insufficient permissions")
    elif e.is_rate_limited():
        print("Too many requests, please slow down")

Configuration

Parameter Description Default
api_key API Key for authentication (X-API-Key header) None
base_url Base URL for the API http://localhost:3000
tenant_id Tenant ID for multi-tenant operations None
timeout Request timeout in seconds 30

Requirements

  • Python 3.8+
  • requests library

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gauthsdk-0.3.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gauthsdk-0.3.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file gauthsdk-0.3.0.tar.gz.

File metadata

  • Download URL: gauthsdk-0.3.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for gauthsdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 25dfa4fac222f65e4524fda3f63c29d9694d1f24a13e6fa397aa25b88cba893c
MD5 82e0e32bcfbf828b9d0d922af30457b8
BLAKE2b-256 52272b8c03adaf9fc300b93c5eed9032b5685bef3693de7029475eeb866d287a

See more details on using hashes here.

File details

Details for the file gauthsdk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: gauthsdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for gauthsdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7de152d5553f60c20603fe2c69d4e8e77c1f074671eda64e6197c44607203be
MD5 cc3e8e92ad8919521f0a207445053dd7
BLAKE2b-256 28780053cc1ff58bf61c227175b907be1733188fc3a1e14a892e494d7df30688

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page