auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package auth handles the Swile session: importing it from a browser's cookie store, persisting it, and refreshing the access token when it expires.

cantine never handles a password and never touches the two-factor flow. The user signs in on team.swile.co as usual; we borrow the session their browser already holds.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSession = errors.New("aucune session : lance `cantine auth import`")

ErrNoSession means nothing usable is stored yet.

Functions

func Clear

func Clear() error

Clear forgets the stored session.

func StorageLocation

func StorageLocation() string

StorageLocation describes where the session lives, for `auth status`.

Types

type Session

type Session struct {
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	ExpiresAt    time.Time `json:"expires_at"`
	Email        string    `json:"email"`
	Source       string    `json:"source"` // browser it was imported from
}

Session is a Swile OAuth session. It is the only credential cantine holds.

func ImportFromBrowser

func ImportFromBrowser(ctx context.Context, browser, profile string) (*Session, error)

ImportFromBrowser reads the Swile session cookies out of a browser's cookie store. browser is a name such as "chrome" or "firefox"; an empty string means "search every browser and take the freshest session". profile, when set, points at one specific Chromium profile directory (or Cookies file) instead of searching.

The cookies are non-HttpOnly, which is what makes this possible at all.

func Load

func Load() (*Session, error)

Load reads the stored session.

func (*Session) EnsureFresh

func (s *Session) EnsureFresh(ctx context.Context) error

EnsureFresh refreshes the token if needed and persists the result.

func (*Session) Expired

func (s *Session) Expired() bool

Expired reports whether the access token is gone or about to be.

func (*Session) Refresh

func (s *Session) Refresh(ctx context.Context) error

Refresh exchanges the refresh token for a fresh access token.

Swile rotates the refresh token but does not invalidate the previous one, so refreshing here does not sign the user out of their browser.

func (*Session) Save

func (s *Session) Save() error

Save writes the session to the OS keyring, falling back to a 0600 file when no keyring is available (headless Linux, containers).

func (*Session) TTL

func (s *Session) TTL() time.Duration

TTL is how much life the access token has left.

Jump to

Keyboard shortcuts

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