Documentation
¶
Index ¶
- func BrowserLogin(host string, ios *iostreams.IOStreams) (string, error)
- 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 BrowserLogin ¶
BrowserLogin starts a localhost OAuth callback server, opens the browser to authenticate via GitHub OAuth, captures the session token from the callback, stores it in the keyring, and returns the token.
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. Returns an error if the input is empty after trimming.
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 ¶
FetchTokenInfo queries the server for session details using the given token. Returns TokenInfo on success, or an error if the token is invalid.