tokens

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessID

type AccessID struct {
	Access       scyauth.Token
	AccessExpiry time.Time
	IDToken      string
	IDExpiry     time.Time
	Issuer       string
	Scopes       []string
}

AccessID holds access and id tokens with independent expiries.

type Key

type Key struct {
	Authority authority.AuthAuthority
	Subject   string
	Audience  string
}

Key identifies a token set for a user and audience under a given authority.

type MemoryRefreshStore

type MemoryRefreshStore struct {
	// contains filtered or unexported fields
}

MemoryRefreshStore is an in-memory RefreshStore useful for tests or ephemeral sessions. Note: This store does not encrypt at rest; use only when policy allows non-persistent storage.

func NewMemoryRefreshStore

func NewMemoryRefreshStore() *MemoryRefreshStore

func (*MemoryRefreshStore) Delete

func (m *MemoryRefreshStore) Delete(k Key) error

func (*MemoryRefreshStore) Get

func (m *MemoryRefreshStore) Get(k Key) (Refresh, bool, error)

func (*MemoryRefreshStore) Set

func (m *MemoryRefreshStore) Set(k Key, r Refresh) error

type Refresh

type Refresh struct {
	Token  Secret
	Expiry time.Time
}

Refresh holds a refresh token and its expiry, if provided.

type RefreshStore

type RefreshStore interface {
	Get(k Key) (Refresh, bool, error)
	Set(k Key, r Refresh) error
	Delete(k Key) error
}

RefreshStore persists refresh tokens securely (e.g., OS keychain or encrypted file). Implementations must ensure encryption at rest and never log secrets.

type Secret

type Secret struct {
	// contains filtered or unexported fields
}

Secret holds sensitive bytes that can be zeroized when cleared. Avoid storing tokens as strings to enable zeroization.

func FromString

func FromString(s string) Secret

FromString creates a Secret from a string copy.

func (Secret) Bytes

func (s Secret) Bytes() []byte

Bytes returns a copy of the secret bytes.

func (*Secret) Clear

func (s *Secret) Clear()

Clear zeroizes the underlying bytes.

func (Secret) IsEmpty

func (s Secret) IsEmpty() bool

IsEmpty reports whether the secret is empty.

func (Secret) String

func (s Secret) String() string

String returns a copy as string.

type StoragePolicy

type StoragePolicy struct {
	AccessInMemoryOnly bool // default: true
	IDInMemoryOnly     bool // default: true
	RefreshEncrypted   bool // default: true (persist via RefreshStore)
}

StoragePolicy controls how tokens are stored.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store keeps access/id tokens in-memory and delegates refresh tokens to RefreshStore.

func NewStore

func NewStore(refresh RefreshStore, policy StoragePolicy) (*Store, error)

NewStore constructs a Store with the provided refresh store and policy. Validates required dependencies.

func (*Store) ClearAll

func (s *Store) ClearAll()

ClearAll removes all in-memory tokens and attempts to delete refresh tokens via store.

func (*Store) DeleteAccessID

func (s *Store) DeleteAccessID(k Key)

DeleteAccessID removes and zeroizes access/id tokens for the key.

func (*Store) DeleteRefresh

func (s *Store) DeleteRefresh(k Key) error

DeleteRefresh removes refresh token from the refresh store.

func (*Store) GetAccessID

func (s *Store) GetAccessID(k Key) (AccessID, bool)

GetAccessID retrieves non-expired access/id tokens. Returns false if missing or expired per type.

func (*Store) GetRefresh

func (s *Store) GetRefresh(k Key) (Refresh, bool, error)

GetRefresh retrieves the refresh token from the refresh store.

func (*Store) InvalidateAccess

func (s *Store) InvalidateAccess(k Key)

InvalidateAccess clears only the access token and its expiry, keeping ID token if present.

func (*Store) Logout

func (s *Store) Logout(k Key) error

Logout clears both access/id tokens and refresh token for the given key.

func (*Store) SetAccessID

func (s *Store) SetAccessID(k Key, v AccessID)

SetAccessID stores access and id tokens with expiries in memory.

func (*Store) SetRefresh

func (s *Store) SetRefresh(k Key, r Refresh) error

SetRefresh persists the refresh token if policy allows; otherwise keeps it in memory via mem map.

Jump to

Keyboard shortcuts

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