Documentation
¶
Overview ¶
Package auth handles authentication and OAuth flows.
Index ¶
- Variables
- func ErrorMessage(err error) string
- func GeneratePKCE() (*pkceParams, error)
- func NewCallbackServer(ctx context.Context, path string) (*callbackServer, error)
- func NewOAuthClient(cfg *config.OAuthConfig) *oauthClient
- func OpenBrowser(ctx context.Context, urlStr string) error
- type FileStore
- func (s *FileStore) DeleteToken() error
- func (s *FileStore) LoadToken() (*Token, error)
- func (s *FileStore) LoadTokenForLogout() (*Token, error)
- func (s *FileStore) Path() string
- func (s *FileStore) PrepareLogin() error
- func (s *FileStore) SaveToken(token *Token) error
- func (s *FileStore) Source() string
- type IntrospectResponse
- type Store
- type Token
- type WritableStore
Constants ¶
This section is empty.
Variables ¶
var ( ErrStoreUnavailable = errors.New("credential storage unavailable") // ErrConfigMismatch indicates that stored credentials target another configuration. ErrConfigMismatch = errors.New("authentication configuration mismatch") // ErrAuthRequired indicates that authentication is required. ErrAuthRequired = errors.New("authentication required") // ErrInvalidInput indicates invalid input to an auth function. ErrInvalidInput = errors.New("invalid input") )
Functions ¶
func ErrorMessage ¶
ErrorMessage removes classification sentinels from user-facing diagnostics.
func GeneratePKCE ¶
func GeneratePKCE() (*pkceParams, error)
GeneratePKCE generates new PKCE parameters for an OAuth flow.
func NewCallbackServer ¶
NewCallbackServer creates a new callback server.
func NewOAuthClient ¶
func NewOAuthClient(cfg *config.OAuthConfig) *oauthClient
NewOAuthClient creates a new OAuth client.
Types ¶
type FileStore ¶
type FileStore struct {
// contains filtered or unexported fields
}
FileStore stores OAuth credentials separately from ordinary configuration. Reads reject nonregular files and check that the opened file still matches the path. Except for logout and Windows, group or other permissions are rejected. Windows relies on filesystem access controls instead of Unix mode checks. Malformed file diagnostics do not include secret input.
func (*FileStore) DeleteToken ¶
DeleteToken removes a regular credential file, ignoring a missing file.
func (*FileStore) LoadTokenForLogout ¶
LoadTokenForLogout reads a regular credential file without checking permissions.
func (*FileStore) PrepareLogin ¶
PrepareLogin rejects known storage failures before browser authentication. The temporary probe does not replace existing credentials.
type IntrospectResponse ¶
type IntrospectResponse struct {
Active bool `json:"active"`
Username string `json:"username,omitempty"`
Scope string `json:"scope,omitempty"`
Exp int64 `json:"exp,omitempty"`
Iat int64 `json:"iat,omitempty"`
}
IntrospectResponse represents the token introspection response.
type Store ¶
type Store interface {
LoadToken() (*Token, error)
SaveToken(*Token) error
DeleteToken() error
Source() string
}
Store is the selected credential source. Environment credentials are read-only.
type Token ¶
type Token struct {
External bool `json:"-"`
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
TokenType string `json:"token_type"`
ExpiresAt time.Time `json:"expires_at"`
Scope string `json:"scope,omitempty"`
IssuedAt time.Time `json:"issued_at"`
BaseURL string `json:"base_url"`
}
Token holds OAuth credentials, expiry, issue time, scope, and the issuing base URL. External tokens have no local expiry or refresh metadata and the External marker is not serialized.
func RequireAuthFrom ¶
RequireAuthFrom loads credentials and checks their configured destination.
func (*Token) IsExpired ¶
IsExpired reports whether the expiry is less than 30 seconds away or past.
func (*Token) IsExpiringSoon ¶
IsExpiringSoon reports whether the expiry is strictly before now plus within. It does not special-case external tokens or a zero expiry.
func (*Token) TimeUntilExpiry ¶
TimeUntilExpiry returns the duration until the token expires.
type WritableStore ¶
WritableStore supports the persistent authentication lifecycle. Logout may read an insecure regular file solely to revoke its credentials.
func NewWritableStore ¶
func NewWritableStore() (WritableStore, error)
NewWritableStore selects persistent storage without relying on display labels.