Skip to content

Add APS OAuth 2.0 Authentication Client - #5

Merged
LeonardNoh merged 2 commits into
voidbox-ai:mainfrom
LeonardNoh:main
Oct 22, 2025
Merged

Add APS OAuth 2.0 Authentication Client#5
LeonardNoh merged 2 commits into
voidbox-ai:mainfrom
LeonardNoh:main

Conversation

@LeonardNoh

Copy link
Copy Markdown
Contributor

Summary

Implement complete APS Authentication API client with OAuth 2.0 support, token management, and HTTP client utilities.

What's New

  • OAuth 2.0 Flows: 2-legged (Client Credentials) and 3-legged (Authorization Code with PKCE)
  • Token Management: Automatic caching, refresh, revoke, and logout
  • Token Storage: Abstract interface with thread-safe in-memory implementation
  • HTTP Client: Retry logic, pagination helper, presigned/signed URL upload support
  • Complete Scopes: All APS OAuth scopes including OpenID, Data Management, Buckets, ACC, Design Automation
  • Comprehensive Examples: Working smoke tests demonstrating all API flows

Key Features

  • ✅ PKCE (RFC 7636) support for enhanced security
  • ✅ Automatic token expiration handling with 30s skew
  • ✅ Flexible caching strategy with scope-based keys
  • ✅ Thread-safe token storage with RLock
  • ✅ Multiple response modes: json/text/raw/stream
  • ✅ Auto-refresh for 3-legged tokens

Files Changed

  • src/pyaps/auth/client.py (486 lines) - Main OAuth client implementation
  • src/pyaps/auth/token_store.py (105 lines) - Token storage abstraction
  • src/pyaps/auth/example.py (316 lines) - Comprehensive usage examples
  • src/pyaps/http/client.py (193 lines) - HTTP client with APS-specific helpers

Testing

Run the examples to see all features in action:

export APS_CLIENT_ID='your_client_id'
export APS_CLIENT_SECRET='your_client_secret'
python3 -m pyaps.auth.example
Example Usage
from pyaps.auth.client import AuthClient, Scopes
from pyaps.auth.token_store import InMemoryTokenStore

# 2-legged OAuth
client = AuthClient(
    client_id="...",
    client_secret="...",
    store=InMemoryTokenStore()
)
token = client.two_legged.get_token([Scopes.DATA_READ, Scopes.BUCKET_READ])

# 3-legged OAuth with PKCE
verifier, challenge = client.three_legged.generate_pkce_pair()
auth_url = client.three_legged.build_authorize_url(
    scopes=[Scopes.DATA_READ, Scopes.USER_PROFILE_READ],
    code_challenge=challenge
)
# After user authorizes...
token = client.three_legged.exchange_code(code, code_verifier=verifier)
Total Changes
5 files changed
1,100+ lines added
0 lines deleted

Implement 2-legged/3-legged OAuth flows with PKCE, token management (cache/refresh/revoke), and HTTP client with retry/pagination support.
Add comprehensive smoke test examples demonstrating all OAuth flows: 2-legged/3-legged with PKCE, token management, user profile, and available scopes.
@LeonardNoh
LeonardNoh merged commit 5b7ae59 into voidbox-ai:main Oct 22, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant