auth

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package auth implements GitHub authentication for the Hive desktop app: the Wails auth service, its live (device flow + PAT) and mock backends, and the wire types the onboarding UI consumes. Desktop-only code lives under internal/desktop; the GitHub client itself is internal/github.

Index

Constants

View Source
const (
	StateUnauthenticated = "unauthenticated"
	StateAuthenticated   = "authenticated"
)

Auth states on the wire. Strings, not enums: the frontend narrows them.

View Source
const EnvGitHubClientID = "HIVE_GITHUB_CLIENT_ID"

EnvGitHubClientID overrides the OAuth app client ID used by the device flow, e.g. to test against a different OAuth app registration.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Status(ctx context.Context) Status
	StartDeviceFlow(ctx context.Context) (DeviceFlowInfo, error)
	CancelDeviceFlow()
	SetToken(ctx context.Context, token string) (Status, error)
	SignOut() error
}

Backend implements authentication for Service. liveAuth talks to GitHub; mockAuth drives deterministic onboarding for tests and e2e.

func NewLiveBackend

func NewLiveBackend(client *github.Client, tokens github.TokenStore, onChange func()) Backend

func NewMockBackend

func NewMockBackend(authenticated bool, onChange func()) Backend

type DeviceFlowInfo

type DeviceFlowInfo struct {
	UserCode        string `json:"userCode"`
	VerificationURI string `json:"verificationUri"`
}

DeviceFlowInfo is the pending device authorization the onboarding screen renders: the user opens VerificationURI and enters UserCode.

type Service

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

Service is the Wails service exposing authentication to the frontend. State changes are pushed via the auth:updated event; the frontend re-reads Status on receipt.

func NewService

func NewService(backend Backend) *Service

func (*Service) CancelDeviceFlow

func (s *Service) CancelDeviceFlow()

func (*Service) SetToken

func (s *Service) SetToken(token string) (Status, error)

func (*Service) SignOut

func (s *Service) SignOut() error

func (*Service) StartDeviceFlow

func (s *Service) StartDeviceFlow() (DeviceFlowInfo, error)

func (*Service) Status

func (s *Service) Status() Status

type Status

type Status struct {
	State     string `json:"state"` // StateUnauthenticated | StateAuthenticated
	Login     string `json:"login"`
	Name      string `json:"name"`
	AvatarURL string `json:"avatarUrl"`
	// Message carries a user-facing problem description (invalid stored
	// token, device flow failure) without changing the state machine.
	Message string `json:"message"`
}

Status is the authentication state shown to the frontend.

Jump to

Keyboard shortcuts

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