authclient

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: BSD-3-Clause, MIT Imports: 10 Imported by: 0

Documentation

Overview

Package authclient is a minimal HTTP client for the CLI session and profile endpoints that lsh uses during login/logout. These endpoints are not in the generated go-swagger client, so we keep a small, dependency-free wrapper here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID    string `json:"id"`
	Token string `json:"token"`
	Name  string `json:"name"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Latitude API for auth-related endpoints.

func New

func New(baseURL, userAgent, apiVersion string) *Client

New builds a Client. baseURL should include scheme and host (e.g. "https://api.latitude.sh"). apiVersion is sent as the API-Version header on every request, matching what the generated SDK does.

func (*Client) CreateSession

func (c *Client) CreateSession(ctx context.Context, req CreateSessionRequest) (*Session, error)

CreateSession opens a new CLI login session. Unauthenticated.

func (*Client) GetCurrentTeam

func (c *Client) GetCurrentTeam(ctx context.Context, token string) (*Team, error)

GetCurrentTeam returns the team bound to the token's membership. GET /team is server-side scoped to current_user_membership, so the returned list contains exactly one entry for a valid token.

func (*Client) GetUserProfile

func (c *Client) GetUserProfile(ctx context.Context, token string) (*UserProfile, error)

GetUserProfile validates the token and returns user/team context. Used by `lsh login --with-token <T>`. Note: the Rails resource does not return the team in this payload; use GetCurrentTeam to fetch it.

func (*Client) ListProjects

func (c *Client) ListProjects(ctx context.Context, token string) ([]Project, error)

ListProjects returns every project accessible to the token's team. Used by the interactive project picker when a command needs a project but the user did not pass --project. It pages through the API (which defaults to 20 per page) so teams with many projects are fully listed.

func (*Client) PollSession

func (c *Client) PollSession(ctx context.Context, id, secret string) (*Session, error)

PollSession reads the session with the secret. Returns the Session (with credential fields when status=approved) or HTTPError. Callers treat 410 (gone) and 404 (not found) as terminal.

func (*Client) RevokeAPIKey

func (c *Client) RevokeAPIKey(ctx context.Context, token, keyID string) error

RevokeAPIKey deletes an API key by id. Used by `lsh auth logout` on sessions created via the browser flow.

type CreateSessionRequest

type CreateSessionRequest struct {
	ClientName    string `json:"client_name,omitempty"`
	ClientVersion string `json:"client_version,omitempty"`
}

CreateSessionRequest is the body of POST /auth/cli_sessions.

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
}

HTTPError is returned when the API responds with a non-2xx status.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Project

type Project struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

Project is the subset of fields the interactive project picker needs.

type Session

type Session struct {
	ID           string  `json:"id"`
	Secret       string  `json:"secret,omitempty"`
	UserCode     string  `json:"user_code,omitempty"`
	AuthorizeURL string  `json:"authorize_url,omitempty"`
	ExpiresAt    string  `json:"expires_at,omitempty"`
	Status       string  `json:"status,omitempty"`
	APIKey       *APIKey `json:"api_key,omitempty"`
	Team         *Team   `json:"team,omitempty"`
	User         *User   `json:"user,omitempty"`
}

Session is the public payload returned by the API on create and on the secret-gated poll (with the credential fields populated).

type Team

type Team struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	Slug string `json:"slug"`
}

type User

type User struct {
	ID    string `json:"id"`
	Email string `json:"email"`
}

type UserProfile

type UserProfile struct {
	ID    string `json:"id"`
	Email string `json:"email"`
	Team  Team   `json:"team"`
}

UserProfile is the subset of GET /user/profile that lsh uses to validate a token and to populate config after a --with-token login.

Jump to

Keyboard shortcuts

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