Add optional API user support for token authentication
- Add user field to apiTokenAuth struct - Add WithAPITokenUser(token, user) method for custom username - Default to "jsonrpc" when no user specified (backward compatible) - Add tests for custom user and empty user scenarios Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
ef7bd74e4a
commit
10e2ecf47e
4 changed files with 93 additions and 2 deletions
|
|
@ -38,11 +38,19 @@ func NewClient(baseURL string) *Client {
|
|||
}
|
||||
|
||||
// WithAPIToken configures the client to use API token authentication.
|
||||
// Uses "jsonrpc" as the username for HTTP Basic Auth.
|
||||
func (c *Client) WithAPIToken(token string) *Client {
|
||||
c.auth = &apiTokenAuth{token: token}
|
||||
return c
|
||||
}
|
||||
|
||||
// WithAPITokenUser configures the client to use API token authentication with a custom username.
|
||||
// If user is empty, "jsonrpc" will be used as the default.
|
||||
func (c *Client) WithAPITokenUser(token, user string) *Client {
|
||||
c.auth = &apiTokenAuth{token: token, user: user}
|
||||
return c
|
||||
}
|
||||
|
||||
// WithBasicAuth configures the client to use username/password authentication.
|
||||
func (c *Client) WithBasicAuth(username, password string) *Client {
|
||||
c.auth = &basicAuth{username: username, password: password}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue