gtslib_auth_keyring

package module
v0.0.0-...-79e827a Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: AGPL-3.0-or-later Imports: 21 Imported by: 0

README

gtslib-auth-keyring

Build Status Go Report Card Go Reference

GoToSocial client auth with keyring support

ALPHA SOFTWARE just like GoToSocial. Uses go-keyring.

import (
  "log/slog"

  auth "git.coopcloud.tech/decentral1se/gtslib-auth-keyring"
)

func main() {
  if err := auth.Login("foo@bar.zone"); err != nil {
    slog.Error("unable to login", "error", err)
  }
}

ACK

Made possible by the good work of slurp.

License

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PrefNotFound = errors.New("preference value not found")

PrefNotFound represents an error in which no preference is found.

Functions

func GetDefaultUser

func GetDefaultUser() (string, error)

GetDefaultUser retrieves the default user.

func GetInstanceClientID

func GetInstanceClientID(instance string) (string, error)

GetInstanceClientID retrieves the instance client ID.

func GetUserInstance

func GetUserInstance(user string) (string, error)

GetUserInstance gets the user instance.

func Login

func Login(user string, opts ...Option) error

Login authenticates the user and saves the credentials in the system keychain.

func Ptr

func Ptr[T any](v T) *T

func SavePrefs

func SavePrefs(prefs *Prefs) error

SavePrefs creates on-disk preferences or overwrites existing ones.

func SetDefaultUser

func SetDefaultUser(user string) error

SetDefaultUser sets the default user.

func SetInstanceClientID

func SetInstanceClientID(instance string, clientID string) error

SetInstanceClientID sets the instance client ID.

func SetUserInstance

func SetUserInstance(user string, instance string) error

SetUserInstance sets the user instance.

Types

type Client

type Client struct {
	Client *apiclient.GoToSocialSwaggerDocumentation
	Auth   runtime.ClientAuthInfoWriter
	// contains filtered or unexported fields
}

Client is a GtS API client with attached authentication credentials and rate limiter. Credentials may be no-op.

func NewAuthClient

func NewAuthClient(user string) (*Client, error)

NewAuthClient creates a new authentication client.

func (*Client) Wait

func (c *Client) Wait() error

type Config

type Config struct {
	Name    string // client name
	Website string // client website
}

Config is a client configuration.

func NewConfig

func NewConfig(opts ...Option) *Config

NewConfig creates a new client config.

type Option

type Option func(c *Config)

Option with operates on a client config.

func WithName

func WithName(name string) Option

WithName sets a client name.

func WithWebsite

func WithWebsite(website string) Option

WithWebsite sets a client website.

type Prefs

type Prefs struct {
	// Instances is a map of instance names to instance preferences.
	Instances map[string]PrefsInstance `json:"instances,omitempty"`

	// Users is a map of user usernames@domains to instance data.
	Users map[string]PrefsUser `json:"users,omitempty"`

	// DefaultUser is the username@domain of the last user we successfully
	// authenticated as, if there is one.
	DefaultUser string `json:"default_user,omitempty"`
}

Prefs stores persisted preferences.

func LoadPrefs

func LoadPrefs() (*Prefs, error)

LoadPrefs returns preferences from disk or an empty prefs object if there are none stored or accessible.

type PrefsInstance

type PrefsInstance struct {
	// ClientID is the OAuth2 client ID on this instance.
	ClientID string `json:"client_id"`
}

PrefsInstance stores preferences for a given instance. OAuth2 app secrets are stored in the system keychain.

type PrefsUser

type PrefsUser struct {
	// Instance is the name of the instance that the user is on.
	Instance string `json:"instance"`
}

PrefsUser stores preferences for a given user. User access tokens are stored in the system keychain.

Jump to

Keyboard shortcuts

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