Skip to content

feat: Add OAuth 2.0 authentication support to Rust SDK#455

Open
huacnlee wants to merge 1 commit intomainfrom
oauth2
Open

feat: Add OAuth 2.0 authentication support to Rust SDK#455
huacnlee wants to merge 1 commit intomainfrom
oauth2

Conversation

@huacnlee
Copy link
Contributor

@huacnlee huacnlee commented Mar 1, 2026

Summary

  • Adds OAuth 2.0 as the recommended authentication method for the Rust SDK
  • Implements new oauth feature with authorization flow support
  • Updates signature logic to support both OAuth 2.0 (Bearer token) and legacy (HMAC) modes
  • Provides comprehensive documentation and examples for OAuth usage

Key Changes

  • New OAuth API: Config::from_oauth(client_id, access_token) constructor
  • Feature-gated dependencies: oauth2, open, anyhow, url (behind oauth feature)
  • Smart authentication: Automatically detects OAuth vs legacy mode based on token format
  • No breaking changes: Full backward compatibility with existing API key authentication
  • Documentation: Updated README with OAuth registration, authorization flow, and usage examples

Authentication Modes

  1. OAuth 2.0 (Recommended): Uses Bearer tokens, no HMAC signatures required
  2. Legacy API Key: Existing environment variable based authentication still supported

Test plan

  • Verify OAuth feature compiles with cargo build --features oauth
  • Test OAuth authorization flow with client registration
  • Confirm Bearer token authentication works without HMAC signatures
  • Validate legacy mode still works with environment variables
  • Check backward compatibility (default build without oauth feature)

🤖 Generated with Claude Code

This commit introduces OAuth 2.0 as the recommended authentication method for the LongPort OpenAPI Rust SDK.

Key changes:
- Add new `oauth` feature with OAuth 2.0 authorization flow
- Implement `Config::from_oauth()` and `HttpClientConfig::from_oauth()` constructors
- Update signature logic to skip HMAC signing in OAuth 2.0 mode (Bearer token)
- Add comprehensive OAuth documentation and examples to README
- Add dependencies: oauth2, open, anyhow, url (feature-gated)
- Maintain backward compatibility with legacy API key authentication

OAuth 2.0 benefits:
- More secure (no shared secret)
- Simpler integration (no signature calculation)
- Token-based authentication
- Better suited for modern applications

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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