Documentation
¶
Index ¶
- func DeleteToken(host string) error
- func DeviceLogin(host string, ios *iostreams.IOStreams) (string, error)
- func GetToken(host string) (string, error)
- func ReadTokenFromStdin(ios *iostreams.IOStreams) (string, error)
- func SetToken(host, token string) error
- type AuthMethod
- type ResolvedToken
- type TokenInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteToken ¶
DeleteToken removes the stored token for the given host from the OS keychain. Returns nil if no token exists for that host.
func DeviceLogin ¶
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 ¶
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 ¶
ReadTokenFromStdin reads a token from ios.In, trims whitespace, and returns it.
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. hosts.yml token field 3. OS keyring (legacy fallback -- tokens are migrated to hosts.yml on login) 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 ¶
FetchTokenInfo queries the server for session details using the given token. For session tokens, calls /api/auth/get-session. For API keys (kh_ prefix), validates via /api/workflows and returns basic info.