Documentation
¶
Index ¶
- func AuthFilePath() string
- func KeysFilePath() string
- type App
- type ChatKeyStore
- type ChatKeys
- type OAuth1Token
- type OAuth2Token
- type Token
- type TokenStore
- func (s *TokenStore) AddApp(name, clientID, clientSecret string) error
- func (s *TokenStore) ClearAll() error
- func (s *TokenStore) ClearAllForApp(appName string) error
- func (s *TokenStore) ClearBearerToken() error
- func (s *TokenStore) ClearBearerTokenForApp(appName string) error
- func (s *TokenStore) ClearOAuth1Tokens() error
- func (s *TokenStore) ClearOAuth1TokensForApp(appName string) error
- func (s *TokenStore) ClearOAuth2Token(username string) error
- func (s *TokenStore) ClearOAuth2TokenForApp(appName, username string) error
- func (s *TokenStore) GetActiveAppName(explicit string) string
- func (s *TokenStore) GetApp(name string) *App
- func (s *TokenStore) GetAppRedirectURI(name string) (string, error)
- func (s *TokenStore) GetBearerToken() *Token
- func (s *TokenStore) GetBearerTokenForApp(appName string) *Token
- func (s *TokenStore) GetDefaultApp() string
- func (s *TokenStore) GetDefaultUser(appName string) string
- func (s *TokenStore) GetFirstOAuth2Token() *Token
- func (s *TokenStore) GetFirstOAuth2TokenForApp(appName string) *Token
- func (s *TokenStore) GetFirstOAuth2TokenRecordForApp(appName string) (string, *Token)
- func (s *TokenStore) GetOAuth1Tokens() *Token
- func (s *TokenStore) GetOAuth1TokensForApp(appName string) *Token
- func (s *TokenStore) GetOAuth2Token(username string) *Token
- func (s *TokenStore) GetOAuth2TokenForApp(appName, username string) *Token
- func (s *TokenStore) GetOAuth2Usernames() []string
- func (s *TokenStore) GetOAuth2UsernamesForApp(appName string) []string
- func (s *TokenStore) HasBearerToken() bool
- func (s *TokenStore) HasOAuth1Tokens() bool
- func (s *TokenStore) ListApps() []string
- func (s *TokenStore) RemoveApp(name string) error
- func (s *TokenStore) ResolveApp(name string) *App
- func (s *TokenStore) SaveBearerToken(token string) error
- func (s *TokenStore) SaveBearerTokenForApp(appName, token string) error
- func (s *TokenStore) SaveOAuth1Tokens(accessToken, tokenSecret, consumerKey, consumerSecret string) error
- func (s *TokenStore) SaveOAuth1TokensForApp(appName, accessToken, tokenSecret, consumerKey, consumerSecret string) error
- func (s *TokenStore) SaveOAuth2Token(username, accessToken, refreshToken string, expirationTime uint64) error
- func (s *TokenStore) SaveOAuth2TokenForApp(appName, username, accessToken, refreshToken string, expirationTime uint64) error
- func (s *TokenStore) SetAppRedirectURI(name, redirectURI string) error
- func (s *TokenStore) SetDefaultApp(name string) error
- func (s *TokenStore) SetDefaultUser(appName, username string) error
- func (s *TokenStore) UpdateApp(name, clientID, clientSecret string) error
- type TokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthFilePath ¶ added in v1.3.0
func AuthFilePath() string
AuthFilePath returns the token-store file inside the resolved ~/.xurl directory (migrating any legacy layout first).
func KeysFilePath ¶ added in v1.3.0
func KeysFilePath() string
KeysFilePath returns the chat-key file inside the resolved ~/.xurl directory.
Types ¶
type App ¶
type App struct {
ClientID string `yaml:"client_id"`
ClientSecret string `yaml:"client_secret"`
RedirectURI string `yaml:"redirect_uri,omitempty"`
DefaultUser string `yaml:"default_user,omitempty"`
OAuth2Tokens map[string]Token `yaml:"oauth2_tokens,omitempty"`
OAuth1Token *Token `yaml:"oauth1_token,omitempty"`
BearerToken *Token `yaml:"bearer_token,omitempty"`
}
App holds the credentials and tokens for a single registered X API application.
type ChatKeyStore ¶ added in v1.3.0
type ChatKeyStore struct {
Users map[string]*ChatKeys `yaml:"users"`
// contains filtered or unexported fields
}
ChatKeyStore persists XChat private keys per user id in a YAML file (~/.xurl/keys.yml by default), following the same conventions as the token store: 0600 permissions and $HOME resolution.
func NewChatKeyStore ¶ added in v1.3.0
func NewChatKeyStore() *ChatKeyStore
NewChatKeyStore loads (or initializes) the chat key store at ~/.xurl/keys.yml.
func NewChatKeyStoreWithPath ¶ added in v1.3.0
func NewChatKeyStoreWithPath(path string) *ChatKeyStore
NewChatKeyStoreWithPath loads (or initializes) a chat key store at the given path.
func (*ChatKeyStore) DeleteKeys ¶ added in v1.3.0
func (s *ChatKeyStore) DeleteKeys(userID string) error
DeleteKeys removes keys for a user id and persists the store.
func (*ChatKeyStore) FilePath ¶ added in v1.3.0
func (s *ChatKeyStore) FilePath() string
FilePath returns the location of the backing file.
func (*ChatKeyStore) GetKeys ¶ added in v1.3.0
func (s *ChatKeyStore) GetKeys(userID string) *ChatKeys
GetKeys returns the stored keys for a user id, or nil if absent.
func (*ChatKeyStore) LoadErr ¶ added in v1.3.0
func (s *ChatKeyStore) LoadErr() error
LoadErr reports whether an existing key file failed to load (e.g. corrupt YAML). Callers must treat this as fatal rather than as an empty store.
type ChatKeys ¶ added in v1.3.0
type ChatKeys struct {
PrivateKeysB64 string `yaml:"private_keys_b64"`
KeyVersion string `yaml:"key_version"`
}
ChatKeys holds one user's XChat private key material. PrivateKeysB64 is the base64 encoding of the chat-xdk ExportKeys blob (identity key, or identity||signing); KeyVersion is the version the matching public key is registered under on the account.
type OAuth1Token ¶
type OAuth1Token struct {
AccessToken string `yaml:"access_token" json:"access_token"`
TokenSecret string `yaml:"token_secret" json:"token_secret"`
ConsumerKey string `yaml:"consumer_key" json:"consumer_key"`
ConsumerSecret string `yaml:"consumer_secret" json:"consumer_secret"`
}
Represents OAuth1 authentication tokens
type OAuth2Token ¶
type OAuth2Token struct {
AccessToken string `yaml:"access_token" json:"access_token"`
RefreshToken string `yaml:"refresh_token" json:"refresh_token"`
ExpirationTime uint64 `yaml:"expiration_time" json:"expiration_time"`
}
Represents OAuth2 authentication tokens
type Token ¶
type Token struct {
Type TokenType `yaml:"type" json:"type"`
Bearer string `yaml:"bearer,omitempty" json:"bearer,omitempty"`
OAuth2 *OAuth2Token `yaml:"oauth2,omitempty" json:"oauth2,omitempty"`
OAuth1 *OAuth1Token `yaml:"oauth1,omitempty" json:"oauth1,omitempty"`
}
Token represents an authentication token
type TokenStore ¶
type TokenStore struct {
Apps map[string]*App `yaml:"apps"`
DefaultApp string `yaml:"default_app"`
FilePath string `yaml:"-"`
}
Manages authentication tokens across multiple apps.
func NewTokenStore ¶
func NewTokenStore() *TokenStore
Creates a new TokenStore, loading from ~/.xurl/auth.yml (migrating a legacy single-file ~/.xurl on first use).
func NewTokenStoreWithCredentials ¶
func NewTokenStoreWithCredentials(clientID, clientSecret string) *TokenStore
NewTokenStoreWithCredentials creates a TokenStore and backfills the given client credentials into any app that has tokens but no stored client ID/secret (e.g. apps authenticated with CLIENT_ID / CLIENT_SECRET coming from env vars), so later refreshes work without the env vars present.
func (*TokenStore) AddApp ¶
func (s *TokenStore) AddApp(name, clientID, clientSecret string) error
AddApp registers a new application. If it's the only app it becomes default.
func (*TokenStore) ClearAll ¶
func (s *TokenStore) ClearAll() error
ClearAll clears all tokens from the resolved app.
func (*TokenStore) ClearAllForApp ¶
func (s *TokenStore) ClearAllForApp(appName string) error
ClearAllForApp clears all tokens from the named app.
func (*TokenStore) ClearBearerToken ¶
func (s *TokenStore) ClearBearerToken() error
ClearBearerToken clears the bearer token from the resolved app.
func (*TokenStore) ClearBearerTokenForApp ¶
func (s *TokenStore) ClearBearerTokenForApp(appName string) error
ClearBearerTokenForApp clears the bearer token from the named app.
func (*TokenStore) ClearOAuth1Tokens ¶
func (s *TokenStore) ClearOAuth1Tokens() error
ClearOAuth1Tokens clears OAuth1 tokens from the resolved app.
func (*TokenStore) ClearOAuth1TokensForApp ¶
func (s *TokenStore) ClearOAuth1TokensForApp(appName string) error
ClearOAuth1TokensForApp clears OAuth1 tokens from the named app.
func (*TokenStore) ClearOAuth2Token ¶
func (s *TokenStore) ClearOAuth2Token(username string) error
ClearOAuth2Token clears an OAuth2 token for a username from the resolved app.
func (*TokenStore) ClearOAuth2TokenForApp ¶
func (s *TokenStore) ClearOAuth2TokenForApp(appName, username string) error
ClearOAuth2TokenForApp clears an OAuth2 token for a username from the named app.
func (*TokenStore) GetActiveAppName ¶
func (s *TokenStore) GetActiveAppName(explicit string) string
GetActiveAppName returns the name of the active app (explicit or default).
func (*TokenStore) GetApp ¶
func (s *TokenStore) GetApp(name string) *App
GetApp returns an app by name.
func (*TokenStore) GetAppRedirectURI ¶ added in v1.1.0
func (s *TokenStore) GetAppRedirectURI(name string) (string, error)
GetAppRedirectURI gets the stored redirect URI for an existing app.
func (*TokenStore) GetBearerToken ¶
func (s *TokenStore) GetBearerToken() *Token
GetBearerToken gets the bearer token from the resolved app.
func (*TokenStore) GetBearerTokenForApp ¶
func (s *TokenStore) GetBearerTokenForApp(appName string) *Token
GetBearerTokenForApp gets the bearer token from the named app.
func (*TokenStore) GetDefaultApp ¶
func (s *TokenStore) GetDefaultApp() string
GetDefaultApp returns the default app name.
func (*TokenStore) GetDefaultUser ¶
func (s *TokenStore) GetDefaultUser(appName string) string
GetDefaultUser returns the default OAuth2 user for the named (or default) app.
func (*TokenStore) GetFirstOAuth2Token ¶
func (s *TokenStore) GetFirstOAuth2Token() *Token
GetFirstOAuth2Token gets the first OAuth2 token from the resolved app.
func (*TokenStore) GetFirstOAuth2TokenForApp ¶
func (s *TokenStore) GetFirstOAuth2TokenForApp(appName string) *Token
GetFirstOAuth2TokenForApp gets the default user's token, or the first OAuth2 token from the named app.
func (*TokenStore) GetFirstOAuth2TokenRecordForApp ¶ added in v1.1.0
func (s *TokenStore) GetFirstOAuth2TokenRecordForApp(appName string) (string, *Token)
GetFirstOAuth2TokenRecordForApp gets the preferred OAuth2 token key and token from the named app.
func (*TokenStore) GetOAuth1Tokens ¶
func (s *TokenStore) GetOAuth1Tokens() *Token
GetOAuth1Tokens gets OAuth1 tokens from the resolved app.
func (*TokenStore) GetOAuth1TokensForApp ¶
func (s *TokenStore) GetOAuth1TokensForApp(appName string) *Token
GetOAuth1TokensForApp gets OAuth1 tokens from the named app.
func (*TokenStore) GetOAuth2Token ¶
func (s *TokenStore) GetOAuth2Token(username string) *Token
GetOAuth2Token gets an OAuth2 token for a username from the resolved app.
func (*TokenStore) GetOAuth2TokenForApp ¶
func (s *TokenStore) GetOAuth2TokenForApp(appName, username string) *Token
GetOAuth2TokenForApp gets an OAuth2 token for a username from the named app.
func (*TokenStore) GetOAuth2Usernames ¶
func (s *TokenStore) GetOAuth2Usernames() []string
GetOAuth2Usernames gets all OAuth2 usernames from the resolved app.
func (*TokenStore) GetOAuth2UsernamesForApp ¶
func (s *TokenStore) GetOAuth2UsernamesForApp(appName string) []string
GetOAuth2UsernamesForApp gets all OAuth2 usernames from the named app.
func (*TokenStore) HasBearerToken ¶
func (s *TokenStore) HasBearerToken() bool
HasBearerToken checks if a bearer token exists in the resolved app.
func (*TokenStore) HasOAuth1Tokens ¶
func (s *TokenStore) HasOAuth1Tokens() bool
HasOAuth1Tokens checks if OAuth1 tokens exist in the resolved app.
func (*TokenStore) ListApps ¶
func (s *TokenStore) ListApps() []string
ListApps returns sorted app names.
func (*TokenStore) RemoveApp ¶
func (s *TokenStore) RemoveApp(name string) error
RemoveApp removes a registered application and its tokens.
func (*TokenStore) ResolveApp ¶
func (s *TokenStore) ResolveApp(name string) *App
ResolveApp returns the app for the given name, or the default app.
func (*TokenStore) SaveBearerToken ¶
func (s *TokenStore) SaveBearerToken(token string) error
SaveBearerToken saves a bearer token into the resolved app.
func (*TokenStore) SaveBearerTokenForApp ¶
func (s *TokenStore) SaveBearerTokenForApp(appName, token string) error
SaveBearerTokenForApp saves a bearer token into the named app.
func (*TokenStore) SaveOAuth1Tokens ¶
func (s *TokenStore) SaveOAuth1Tokens(accessToken, tokenSecret, consumerKey, consumerSecret string) error
SaveOAuth1Tokens saves OAuth1 tokens into the resolved app.
func (*TokenStore) SaveOAuth1TokensForApp ¶
func (s *TokenStore) SaveOAuth1TokensForApp(appName, accessToken, tokenSecret, consumerKey, consumerSecret string) error
SaveOAuth1TokensForApp saves OAuth1 tokens into the named app.
func (*TokenStore) SaveOAuth2Token ¶
func (s *TokenStore) SaveOAuth2Token(username, accessToken, refreshToken string, expirationTime uint64) error
SaveOAuth2Token saves an OAuth2 token into the resolved app.
func (*TokenStore) SaveOAuth2TokenForApp ¶
func (s *TokenStore) SaveOAuth2TokenForApp(appName, username, accessToken, refreshToken string, expirationTime uint64) error
SaveOAuth2TokenForApp saves an OAuth2 token into the named app.
func (*TokenStore) SetAppRedirectURI ¶ added in v1.1.0
func (s *TokenStore) SetAppRedirectURI(name, redirectURI string) error
SetAppRedirectURI sets the redirect URI of an existing app.
func (*TokenStore) SetDefaultApp ¶
func (s *TokenStore) SetDefaultApp(name string) error
SetDefaultApp sets the default application by name.
func (*TokenStore) SetDefaultUser ¶
func (s *TokenStore) SetDefaultUser(appName, username string) error
SetDefaultUser sets the default OAuth2 user for the named (or default) app.
func (*TokenStore) UpdateApp ¶
func (s *TokenStore) UpdateApp(name, clientID, clientSecret string) error
UpdateApp updates the credentials of an existing application.