Documentation
¶
Overview ¶
Package authtoken provides OAuth2 client-credentials token management with automatic caching and refresh.
The client uses an RWMutex with double-check locking to efficiently cache tokens across concurrent requests, automatically refreshing expired tokens. A 30-second expiry buffer prevents race conditions during token refresh.
Basic usage:
client := authtoken.New(
"https://auth.example.com/oauth/token",
"client-id",
"client-secret",
)
token, err := client.GetToken(ctx)
if err != nil {
return err
}
// Use token for API requests
The client is safe for concurrent use. Call InvalidateToken() to force a token refresh on the next request.
Index ¶
Constants ¶
View Source
const (
DefaultTimeout = 10 * time.Second
)
Variables ¶
View Source
var ( ErrTokenRequestFailed = errors.New("authtoken: token request failed") ErrNoAccessToken = errors.New("authtoken: no access token in response") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) InvalidateToken ¶
func (c *Client) InvalidateToken()
Click to show internal directories.
Click to hide internal directories.