Documentation
¶
Overview ¶
Package keychain provides secure storage for OAuth tokens using platform-native secure storage mechanisms (macOS Keychain, Linux secret-tool) with file fallback.
Index ¶
- Variables
- func DeleteToken() error
- func GetToken() (*oauth2.Token, error)
- func HasStoredToken() bool
- func IsSecureStorage() bool
- func MigrateFromFile(tokenFilePath string) error
- func NewPersistentTokenSource(ctx context.Context, config *oauth2.Config, initial *oauth2.Token) oauth2.TokenSource
- func SetToken(token *oauth2.Token) error
- type PersistentTokenSource
- type StorageBackend
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTokenNotFound indicates no token exists in storage ErrTokenNotFound = errors.New("no token found in secure storage") )
Functions ¶
func HasStoredToken ¶
func HasStoredToken() bool
HasStoredToken returns true if a token exists in secure storage
func IsSecureStorage ¶
func IsSecureStorage() bool
IsSecureStorage returns true if using secure storage (keychain/secret-tool)
func MigrateFromFile ¶
MigrateFromFile migrates token.json to secure storage if it exists
func NewPersistentTokenSource ¶
func NewPersistentTokenSource(ctx context.Context, config *oauth2.Config, initial *oauth2.Token) oauth2.TokenSource
NewPersistentTokenSource creates a TokenSource that persists refreshed tokens. When the underlying oauth2 package refreshes an expired token, this wrapper detects the change and saves the new token to secure storage.
Types ¶
type PersistentTokenSource ¶
type PersistentTokenSource struct {
// contains filtered or unexported fields
}
PersistentTokenSource wraps a TokenSource and persists refreshed tokens. This solves the problem where oauth2's automatic token refresh doesn't persist the new token to storage.
type StorageBackend ¶
type StorageBackend string
StorageBackend represents where tokens are stored
const ( BackendKeychain StorageBackend = "Keychain" // macOS Keychain BackendSecretTool StorageBackend = "secret-tool" // Linux libsecret BackendFile StorageBackend = "config file" // File fallback )
StorageBackend constants define where OAuth tokens are persisted.
func GetStorageBackend ¶
func GetStorageBackend() StorageBackend
GetStorageBackend returns the current storage backend being used