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

remoteauth

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProvisionAuto inserts a user principal the first time a valid token is seen.
	ProvisionAuto = "auto"
	// ProvisionAllowlist rejects principals that were not created ahead of time.
	ProvisionAllowlist = "allowlist"
)
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 FreshAccessToken added in v1.1.0

func FreshAccessToken(ctx context.Context, remote remoteapi.RemoteConfig) (string, error)

FreshAccessToken returns the stored bearer, refreshing an OIDC access token that expires within a minute. The refresh token is not included in the result.

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 LoginOIDC added in v1.1.0

LoginOIDC performs the loopback PKCE flow and stores the remote. The refresh token is written to disk and is never returned to the server.

func OpenBrowser added in v1.1.0

func OpenBrowser(url string) error

OpenBrowser starts the OS URL handler. Failure is not fatal; the URL is also printed.

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 Discovery added in v1.1.0

type Discovery struct {
	Issuer                string `json:"issuer"`
	AuthorizationEndpoint string `json:"authorization_endpoint"`
	TokenEndpoint         string `json:"token_endpoint"`
	JWKSURI               string `json:"jwks_uri"`
}

Discovery is the subset of an OpenID provider metadata document the CLI and the server both need.

func Discover added in v1.1.0

func Discover(ctx context.Context, client *http.Client, issuer string) (Discovery, error)

Discover loads the issuer's OpenID metadata.

type DispatchVerifier added in v1.1.0

type DispatchVerifier struct {
	Invite *StoreVerifier
	OIDC   *OIDCVerifier
}

DispatchVerifier routes HS256 invite tokens and RS256/ES256 OIDC tokens. The HMAC key is never used on an OIDC token.

func (DispatchVerifier) Verify added in v1.1.0

func (d DispatchVerifier) Verify(token string) (Identity, error)

Verify implements Verifier.

type Identity

type Identity struct {
	Principal string
	Role      string
	JTI       string
}

Identity is the verified actor. Invite tokens take the principal from sub. OIDC tokens take it from the configured principal claim.

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 OIDCConfig added in v1.1.0

type OIDCConfig struct {
	Issuer         string
	Audience       string
	JWKSURL        string
	PrincipalClaim string
	AllowClaim     string
	AllowValue     string
	RoleClaim      string
	OrgValue       string
	Provision      string
}

OIDCConfig is generic OIDC access-token verification. It does not name a vendor.

func (*OIDCConfig) Prepare added in v1.1.0

func (c *OIDCConfig) Prepare() error

Prepare applies defaults and rejects a configuration that would admit every account at the issuer. A claim gate or an allowlist is required.

type OIDCLoginRequest added in v1.1.0

type OIDCLoginRequest struct {
	Issuer         string
	ClientID       string
	Server         string
	Name           string
	DataDir        string
	PrincipalClaim string
	CAFile         string
	ServerName     string
	MakeDefault    bool
	// Scopes are requested in addition to openid and profile. Blank entries and
	// duplicates are dropped. offline_access is not included unless listed here.
	Scopes []string
	// OpenBrowser is called with the authorization URL. Nil prints the URL and
	// tries the OS opener. Tests can complete the redirect themselves.
	OpenBrowser func(url string) error
	Timeout     time.Duration
	HTTP        *http.Client
}

OIDCLoginRequest is a public-client authorization-code login with PKCE.

type OIDCVerifier added in v1.1.0

type OIDCVerifier struct {
	DB     *store.DB
	Config OIDCConfig
	HTTP   *http.Client
	// contains filtered or unexported fields
}

OIDCVerifier checks RS256/ES256 access tokens against an IdP JWKS.

func NewOIDCVerifier added in v1.1.0

func NewOIDCVerifier(db *store.DB, cfg OIDCConfig) (*OIDCVerifier, error)

NewOIDCVerifier validates cfg and returns a verifier. JWKS is fetched on first use.

func (*OIDCVerifier) Verify added in v1.1.0

func (v *OIDCVerifier) Verify(token string) (Identity, error)

Verify validates an OIDC access token and resolves the local principal.

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. StoreVerifier checks invite JWTs. OIDCVerifier checks IdP access tokens. DispatchVerifier accepts both.

func NewVerifier added in v1.1.0

func NewVerifier(db *store.DB, jwtKeyFile string, cfg OIDCConfig) (Verifier, error)

NewVerifier builds the invite verifier, the OIDC verifier, or both. jwtKeyFile may be empty only when cfg.Issuer is set.

Jump to

Keyboard shortcuts

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