auth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateNonce

func GenerateNonce() string

GenerateNonce generates a random nonce for OAuth.

Types

type DeviceCodeResponse added in v0.2.0

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 initial response from the device auth endpoint.

type DeviceFlow added in v0.2.0

type DeviceFlow struct {
	Config     DeviceFlowConfig
	HTTPClient *http.Client
}

DeviceFlow implements the OAuth 2.0 Device Authorization Grant (RFC 8628).

func NewDeviceFlow added in v0.2.0

func NewDeviceFlow(cfg DeviceFlowConfig) *DeviceFlow

NewDeviceFlow creates a device flow handler.

func (*DeviceFlow) PollForToken added in v0.2.0

func (df *DeviceFlow) PollForToken(ctx context.Context, deviceCode string) (*TokenResponse, error)

PollForToken polls the token endpoint until the user authorizes or timeout.

func (*DeviceFlow) RequestCode added in v0.2.0

func (df *DeviceFlow) RequestCode(ctx context.Context) (*DeviceCodeResponse, error)

RequestCode initiates the device flow and returns the user code + verification URL.

type DeviceFlowConfig added in v0.2.0

type DeviceFlowConfig struct {
	ClientID      string
	DeviceAuthURL string // e.g. "https://github.com/login/device/code"
	TokenURL      string // e.g. "https://github.com/login/oauth/access_token"
	Scopes        []string
	PollInterval  time.Duration
	ExpiresIn     time.Duration
}

DeviceFlowConfig holds OAuth device flow configuration.

type OAuthFlow

type OAuthFlow struct {
	Provider string
	ClientID string
}

OAuthFlow handles OAuth authentication flow.

func (*OAuthFlow) Callback

func (o *OAuthFlow) Callback(code string) (string, error)

Callback handles the OAuth callback.

func (*OAuthFlow) Start

func (o *OAuthFlow) Start() (string, error)

Start starts the OAuth flow.

type SecureStorage

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

SecureStorage handles secure token storage using OS keychain/keyring.

func NewSecureStorage

func NewSecureStorage(service string) *SecureStorage

NewSecureStorage creates a new secure storage.

func (*SecureStorage) Get

func (s *SecureStorage) Get(account string) (string, error)

Get retrieves a token from secure storage.

func (*SecureStorage) Set

func (s *SecureStorage) Set(account, token string) error

Set stores a token in secure storage.

type TokenResponse added in v0.2.0

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	Scope        string `json:"scope"`
	RefreshToken string `json:"refresh_token,omitempty"`
	ExpiresIn    int    `json:"expires_in,omitempty"`
}

TokenResponse is the final token from the OAuth flow.

type TokenStore

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

TokenStore manages authentication tokens.

func NewTokenStore

func NewTokenStore() *TokenStore

NewTokenStore creates a new token store.

func (*TokenStore) Get

func (t *TokenStore) Get(provider string) string

Get returns a token for a provider.

func (*TokenStore) Has

func (t *TokenStore) Has(provider string) bool

Has returns true if a token exists for a provider.

func (*TokenStore) Load

func (t *TokenStore) Load() error

Load loads tokens from secure storage.

func (*TokenStore) Save

func (t *TokenStore) Save() error

Save saves tokens to secure storage.

func (*TokenStore) Set

func (t *TokenStore) Set(provider, token string)

Set sets a token for a provider.

Jump to

Keyboard shortcuts

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