Skip to content

Add bearer token authentication to HyperSync client#14

Draft
JasoonS wants to merge 1 commit intomainfrom
claude/add-api-token-auth-aNmUi
Draft

Add bearer token authentication to HyperSync client#14
JasoonS wants to merge 1 commit intomainfrom
claude/add-api-token-auth-aNmUi

Conversation

@JasoonS
Copy link
Contributor

@JasoonS JasoonS commented Feb 16, 2026

Summary

This PR implements required bearer token authentication for the HyperSync client. All HTTP requests to the HyperSync server now include an Authorization: Bearer <token> header, and client creation fails if no token is provided.

Key Changes

  • Authentication enforcement: Modified BearerToken field in options.Node from optional pointer to required string
  • Validation: Added Validate() method to Node struct that checks for required BearerToken and Endpoint fields
  • Client initialization: Updated NewClient() to validate options before creating a client, returning an error if validation fails
  • Header management: Introduced setHeaders() method in Client to consistently apply Content-Type and Authorization headers across all HTTP requests (DoQuery, Do, and DoArrow functions)
  • Documentation: Added authentication section to README with configuration example and usage instructions
  • Test coverage: Added comprehensive test suite (client_auth_test.go) covering:
    • Bearer token requirement validation
    • Endpoint requirement validation
    • Bearer token transmission on requests
    • Options validation for both valid and invalid configurations
  • Examples: Updated all example files to read bearer token from HYPERSYNC_BEARER_TOKEN environment variable
  • Test fixtures: Updated existing tests to include BearerToken in test configurations

Implementation Details

  • The bearer token is now sent as Authorization: Bearer <token> on all HTTP requests to the HyperSync API
  • Validation occurs at client creation time, providing early feedback for missing credentials
  • The setHeaders() method centralizes header management, ensuring consistency across different request types
  • All examples demonstrate the recommended pattern of reading the token from environment variables

https://claude.ai/code/session_018BC1bRoMssshsxRzNm2Knd

- Change BearerToken from optional (*string) to required (string) in options.Node
- Add Node.Validate() and Options.Validate() to enforce BearerToken and Endpoint are set
- Add setHeaders() helper that sets Content-Type and Authorization: Bearer headers
- Apply bearer token header to DoQuery, Do, and DoArrow request functions
- Add dedicated unit tests for token validation and header transmission
- Update all examples and existing tests with BearerToken field
- Document authentication requirement in README

https://claude.ai/code/session_018BC1bRoMssshsxRzNm2Knd
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.

2 participants