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.1.0.tar.gz (8.6 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.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gauthsdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0877198cbc84252bdec0e711497cf3630942b2e58bb2f4c6825515d38e071723
MD5 01a19647c20eac5c37f956258c88c601
BLAKE2b-256 b7fb37b44e33bc62b5d5d048d1f50bcf09aff3bfee07efc73f3f92af59e0e44d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for gauthsdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e4bbce92dc2d010e17abcb32e1935f31a21f994e922ae4613c4e4e334084dc55
MD5 58b9db7f6265864bc039270886ad955e
BLAKE2b-256 eff40b9e4011ac6e31bd6edbf17bef5b456b188cecba856f67a58282d41e478c

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