remoteauth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const HashPrefix = "sha256:"

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(doc *UsersFile, principal, token string) error

func FindDefaultRemote

func FindDefaultRemote(cfg *remoteapi.AuthConfig) (*remoteapi.RemoteConfig, bool)

func GenerateKey

func GenerateKey() (string, error)

GenerateKey returns a 32-byte random HMAC key as hex.

func GenerateToken

func GenerateToken() (string, error)

func HashToken

func HashToken(token string) string

func LoadAuthConfig

func LoadAuthConfig(path string) (*remoteapi.AuthConfig, error)

func LoadKey

func LoadKey(path string) ([]byte, error)

LoadKey reads a JWT HMAC key from a file. The file must be at least 32 bytes.

func SaveAuthConfig

func SaveAuthConfig(path string, cfg *remoteapi.AuthConfig) error

func SaveUsers

func SaveUsers(path string, doc *UsersFile) error

func UpsertRemote

func UpsertRemote(cfg *remoteapi.AuthConfig, remote remoteapi.RemoteConfig)

func UpsertUser

func UpsertUser(doc *UsersFile, user User)

func VerifyToken

func VerifyToken(token, hash string) bool

Types

type Identity

type Identity struct {
	Principal string
	Role      string
	JTI       string
}

Identity is the verified actor from a JWT. Principal always comes from sub.

type Issuer

type Issuer struct {
	DB  *store.DB
	Key []byte
}

Issuer mints self-issued JWTs and persists jti rows.

func (Issuer) Issue

func (i Issuer) Issue(principal, role string, ttl time.Duration) (string, Identity, error)

Issue creates a principal (if needed), records jti, and returns a signed JWT.

type StoreVerifier

type StoreVerifier struct {
	DB  *store.DB
	Key []byte
}

StoreVerifier checks signature, expiry, principal, and jti revocation against the DB.

func (StoreVerifier) Verify

func (v StoreVerifier) Verify(token string) (Identity, error)

type User

type User struct {
	Principal string   `json:"principal"`
	TokenHash string   `json:"token_hash"`
	Scopes    []string `json:"scopes,omitempty"`
}

type UsersFile

type UsersFile struct {
	SchemaVersion int    `json:"schema_version"`
	Users         []User `json:"users"`
}

func LoadUsers

func LoadUsers(path string) (*UsersFile, error)

type Verifier

type Verifier interface {
	Verify(token string) (Identity, error)
}

Verifier validates a bearer token. Implementations can later be swapped for OIDC.

Jump to

Keyboard shortcuts

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