authtoken

package
v1.3.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package authtoken provides Keycloak service-account 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 configurable expiry buffer prevents race conditions during token refresh.

Basic usage:

client := authtoken.New("https://auth.example.com", "my-realm", "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

This section is empty.

Variables

View Source
var 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 New

func New(baseURL, realm, clientID, clientSecret string, opts ...Option) *Client

func (*Client) GetToken

func (c *Client) GetToken(ctx context.Context) (string, error)

func (*Client) InvalidateToken

func (c *Client) InvalidateToken()

type Option

type Option func(*Client)

func WithGoCloakClient added in v1.3.16

func WithGoCloakClient(client *gocloak.GoCloak) Option

func WithTokenExpiryBuffer added in v1.3.16

func WithTokenExpiryBuffer(buffer time.Duration) Option

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL