Help us shape the future of Go! Take the 2026 Go Developer Survey

token

package
v0.1.310 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package token manages the on-disk cache of Chainguard OIDC access and refresh tokens, organized by audience and optional alias.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	AllKinds = []Kind{KindAccess, KindRefresh}
)

Functions

func Delete

func Delete(kind Kind, audience string, opts ...Option) error

Delete removes the token for the given audience, if it exists. No error is returned if the token doesn't exist.

func DeleteAll

func DeleteAll() error

DeleteAll removes all Chainguard tokens and empty audience directories.

func ListAudiences added in v0.1.164

func ListAudiences() ([]string, error)

ListAudiences returns the set of audiences for which an access token (KindAccess) currently exists in the local token cache.

Audiences are recovered from each token's "aud" claim rather than from the on-disk directory name, since the directory name is a lossy encoding of the audience (e.g. "/" is replaced with "-"). The returned slice is sorted and de-duplicated. Files that cannot be read or parsed as tokens are skipped.

func Load

func Load(kind Kind, audience string, opts ...Option) ([]byte, error)

Load returns the token for the given audience if it exists, or an error if it doesn't.

func Path

func Path(kind Kind, audience string, opts ...Option) (string, error)

Path is the filepath of the token for the given audience.

func RemainingLife

func RemainingLife(kind Kind, audience string, less time.Duration, opts ...Option) time.Duration

RemainingLife returns the amount of time remaining before the token for the given audience expires. Returns 0 for expired and non-existent tokens.

func Save

func Save(token []byte, kind Kind, audience string, opts ...Option) error

Save saves the given token to cache/audience

Types

type Kind added in v0.1.10

type Kind string
const (
	KindAccess  Kind = "oidc-token"
	KindRefresh Kind = "refresh-token"
)

type Option added in v0.1.44

type Option func(*token)

func WithAlias added in v0.1.44

func WithAlias(a string) Option

WithAlias allows callers to organize tokens into subdirectories under an audience to manage multiple tokens for the same audience without overwriting.

Example

ExampleWithAlias demonstrates creating an Option that sets a token alias.

package main

import (
	"fmt"

	"chainguard.dev/sdk/auth/token"
)

func main() {
	opt := token.WithAlias("my-alias")
	fmt.Println(opt != nil)
}
Output:
true

Jump to

Keyboard shortcuts

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