Documentation
¶
Overview ¶
Package auth implements the CLI authentication flows.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Logout ¶
Logout revokes the token family on the server and deletes the keychain entry for c.Email(). Dispatched through c.Post so a near-expiry token still gets one refresh attempt before the revoke call — otherwise a stale-but-refreshable session would spuriously log the "server returned 401" warning below instead of just working.
Types ¶
type DeviceCodeResponse ¶
type DeviceCodeResponse struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
DeviceCodeResponse is the JSON returned by /api/cli/device/code.
type LoginResult ¶
LoginResult holds the result of a successful login.
func DeviceLogin ¶
func DeviceLogin(ctx context.Context, gatewayURL string) (*LoginResult, error)
DeviceLogin performs the device-code grant flow (RFC 8628) for headless environments. Used by `relay login --device`.
func Login ¶
func Login(ctx context.Context, gatewayURL string) (*LoginResult, error)
Login performs the PKCE loopback flow:
- Generate code_verifier + challenge (S256)
- Start local loopback server on random port
- Open browser to /api/cli/authorize
- Wait for callback (max 120s)
- Exchange code at /api/cli/token
- Store token in OS keychain
type WhoamiResponse ¶
type WhoamiResponse struct {
Email string `json:"email"`
GoogleSub string `json:"googleSub"`
Services []string `json:"services"`
IssuedAt string `json:"issuedAt"`
Groups []string `json:"groups,omitempty"`
}
WhoamiResponse is the JSON returned by /api/cli/whoami.
func Whoami ¶
func Whoami(c *client.Client, full bool) (*WhoamiResponse, error)
Whoami calls /api/cli/whoami and returns the user info. If full is true, requests groups via ?groups=true. Dispatched through c.Get so an expired/near-expiry OAuth session transparently refreshes (see internal/client's Do) instead of failing outright.