auth

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Overview

Package auth implements the CLI authentication flows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Logout

func Logout(c *client.Client) error

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

type LoginResult struct {
	Email        string
	AccessToken  string
	RefreshToken string
	ExpiresIn    int
}

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:

  1. Generate code_verifier + challenge (S256)
  2. Start local loopback server on random port
  3. Open browser to /api/cli/authorize
  4. Wait for callback (max 120s)
  5. Exchange code at /api/cli/token
  6. 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.

Jump to

Keyboard shortcuts

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