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

authtoken

package
v1.99.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package authtoken implements the one-time session token store used by yarilo-auth to hand off authenticated sessions to backend pods without replaying credentials.

Flow:

  1. Login pod authenticates the client via the yarilo-auth AUTH command.
  2. On success yarilo-auth issues a token (Store.Issue) and returns it in the OK response as "token=<hex>".
  3. Login pod forwards the token to the backend in the preamble (XCLIENT TOKEN=<hex>).
  4. Backend calls yarilo-auth VERIFY <id> <token>.
  5. Store.Validate consumes the token (one-time) and returns the bound username and session ID so the backend can enter authenticated state without running passdb again.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisStore added in v1.66.0

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

RedisStore is a Redis-backed one-time token store. GETDEL provides atomic consume; Redis TTL replaces the background sweeper.

func NewRedis added in v1.66.0

func NewRedis(client *redis.Client, ttl time.Duration) *RedisStore

NewRedis returns a RedisStore. The caller owns the client lifecycle; Close is a no-op.

func (*RedisStore) Close added in v1.66.0

func (s *RedisStore) Close()

Close is a no-op; the caller manages the Redis client lifecycle.

func (*RedisStore) Issue added in v1.66.0

func (s *RedisStore) Issue(username, sessionID, service string) (string, error)

func (*RedisStore) Validate added in v1.66.0

func (s *RedisStore) Validate(tok string) (username, sessionID, service string, ok bool)

type Store

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

Store issues and validates one-time session tokens. Each token is a 32-byte random value encoded as a 64-char hex string. It is valid for the configured TTL and consumed on the first successful Validate call.

The background sweeper purges tokens that expire before they are consumed (e.g. backend died mid-handshake).

func New

func New(ttl time.Duration) *Store

New returns a ready-to-use Store. ttl ≤ 0 defaults to 60 s.

func (*Store) Close

func (s *Store) Close()

Close stops the background sweeper.

func (*Store) Issue

func (s *Store) Issue(username, sessionID, service string) (string, error)

Issue generates a token bound to username, sessionID, and service. The caller must propagate the token to the backend before the TTL elapses.

func (*Store) Validate

func (s *Store) Validate(tok string) (username, sessionID, service string, ok bool)

Validate consumes tok and returns the associated username, sessionID, and service. Returns ("", "", "", false) when the token is unknown, already used, or expired.

Jump to

Keyboard shortcuts

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