auth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteToken

func DeleteToken(host string) error

DeleteToken removes the stored token for the given host from the OS keychain. Returns nil if no token exists for that host.

func DeviceLogin

func DeviceLogin(host string, ios *iostreams.IOStreams) (string, error)

DeviceLogin implements the Device Authorization Grant (RFC 8628). It requests a device code, prints the verification URL and user code, then polls until the user authorises or the code expires.

func GetToken

func GetToken(host string) (string, error)

GetToken retrieves the token for the given host from the OS keychain. Returns an empty string (and nil error) if no token is stored for the host.

func ReadTokenFromStdin

func ReadTokenFromStdin(ios *iostreams.IOStreams) (string, error)

ReadTokenFromStdin reads a token from ios.In, trims whitespace, and returns it.

func SetToken

func SetToken(host, token string) error

SetToken stores a token for the given host in the OS keychain.

Types

type AuthMethod

type AuthMethod string

AuthMethod describes how the token was resolved.

const (
	AuthMethodAPIKey AuthMethod = "api-key"
	AuthMethodToken  AuthMethod = "token"
	AuthMethodNone   AuthMethod = "none"
)

type ResolvedToken

type ResolvedToken struct {
	Token  string
	Method AuthMethod
	Host   string
}

ResolvedToken holds a resolved token and its source.

func ResolveToken

func ResolveToken(host string) (ResolvedToken, error)

ResolveToken resolves the auth token for host using the priority chain: 1. KH_API_KEY environment variable 2. OS keyring 3. hosts.yml token field Returns a ResolvedToken with Method set to AuthMethodNone if no token found.

type TokenInfo

type TokenInfo struct {
	UserID    string
	Email     string
	Name      string
	OrgID     string
	OrgName   string
	Role      string
	ExpiresAt time.Time
	Method    AuthMethod
}

TokenInfo holds session details fetched from the server.

func FetchTokenInfo

func FetchTokenInfo(host, token string) (TokenInfo, error)

FetchTokenInfo queries the server for session details using the given token. Returns TokenInfo on success, or an error if the token is invalid.

Jump to

Keyboard shortcuts

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