auth

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAuthenticated = domain.ErrNotAuthenticated

Functions

func BuildAuthorizeURL

func BuildAuthorizeURL(authorizeURL string, cfg OAuthConfig, state string) string

Types

type Browser

type Browser interface {
	OpenURL(string) error
}

type Exchanger

type Exchanger struct {
	HTTPClient *http.Client
	TokenURL   string
	Now        func() time.Time
}

func (Exchanger) ExchangeCode

func (e Exchanger) ExchangeCode(ctx context.Context, cfg OAuthConfig, code string) (Token, error)

func (Exchanger) RefreshToken

func (e Exchanger) RefreshToken(ctx context.Context, cfg OAuthConfig, refreshToken string) (Token, error)

type FileStore

type FileStore struct {
	Path string
}

func (FileStore) DeleteClientSecret

func (s FileStore) DeleteClientSecret() error

func (FileStore) DeleteToken

func (s FileStore) DeleteToken() error

func (FileStore) LoadClientSecret

func (s FileStore) LoadClientSecret() (string, error)

func (FileStore) LoadToken

func (s FileStore) LoadToken() (Token, error)

func (FileStore) SaveClientSecret

func (s FileStore) SaveClientSecret(secret string) error

func (FileStore) SaveToken

func (s FileStore) SaveToken(token Token) error

type LoginInput

type LoginInput struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
}

type OAuthConfig

type OAuthConfig struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
}

type Service

type Service struct {
	AuthorizeURL string
	ClientID     string
	Exchanger    Exchanger
	Store        TokenStore
	Browser      Browser
	In           io.Reader
	Out          io.Writer
	StateSource  func() string
	Now          func() time.Time
	RefreshSkew  time.Duration
	Listen       func(network, address string) (net.Listener, error)
}

func (Service) AccessToken

func (s Service) AccessToken(ctx context.Context) (string, error)

func (Service) Login

func (s Service) Login(ctx context.Context, in LoginInput) (Token, error)

func (Service) Logout

func (s Service) Logout(ctx context.Context) error

func (Service) Status

func (s Service) Status(ctx context.Context) (Status, error)

type Status

type Status struct {
	Authenticated    bool
	HasRefresh       bool
	ExpiryKnown      bool
	ExpiresAtUnix    int64
	ExpiresInSeconds int64
	Expired          bool
}

type Token

type Token struct {
	AccessToken   string `json:"access_token"`
	RefreshToken  string `json:"refresh_token"`
	TokenType     string `json:"token_type"`
	Scope         string `json:"scope"`
	ExpiresIn     int64  `json:"expires_in,omitempty"`
	CreatedAtUnix int64  `json:"created_at,omitempty"`
	ExpiresAtUnix int64  `json:"expires_at,omitempty"`
}

func (Token) ExpiresAt

func (t Token) ExpiresAt() time.Time

func (Token) HasExpiry

func (t Token) HasExpiry() bool

func (Token) NeedsRefresh

func (t Token) NeedsRefresh(now time.Time, skew time.Duration) bool

type TokenStore

type TokenStore interface {
	SaveToken(Token) error
	LoadToken() (Token, error)
	DeleteToken() error
	SaveClientSecret(string) error
	LoadClientSecret() (string, error)
	DeleteClientSecret() error
}

Jump to

Keyboard shortcuts

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