auth

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 24 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth keeps the Slack tokens: login, refresh and the Keychain.

Index

Constants

View Source
const UserScopes = "search:read,channels:history,groups:history,im:history,mpim:history," +
	"channels:read,groups:read,im:read,mpim:read,users:read,users:read.email," +
	"chat:write,im:write,reactions:read,reactions:write,files:read"

UserScopes is the scope list Login asks for.

Variables

View Source
var (
	// ErrNotFound is a Keychain item that is absent.
	ErrNotFound = errors.New("no such keychain item")
	// ErrNotLoggedIn is a Store with no token.
	ErrNotLoggedIn = errors.New("not logged in to Slack")
)

Functions

This section is empty.

Types

type Keychain

type Keychain interface {
	Get(service, account string) ([]byte, error) // ErrNotFound when absent
	Set(service, account string, secret []byte) error
	Delete(service, account string) error
}

type Login

type Login struct {
	ClientID, RedirectHost string
	Port                   int
	Scopes                 string
	Open                   func(url string) error
	Client                 *slack.Client
	Now                    func() time.Time
}

func (Login) Run

func (l Login) Run(ctx context.Context) (Token, error)

Run sets Granted = Now(), Scopes from the exchange.

type SecurityKeychain

type SecurityKeychain struct {
	Bin string
	// Meter hears of each security spawn; nil meters none.
	Meter func(op string, failed bool, took time.Duration)
}

SecurityKeychain shells out to Bin (default "/usr/bin/security"). Set writes through `security -i` with `add-generic-password -U -s <svc> -a <acct> -X <hex secret>` on stdin; the secret never reaches argv.

func (SecurityKeychain) Delete

func (k SecurityKeychain) Delete(service, account string) error

func (SecurityKeychain) Get

func (k SecurityKeychain) Get(service, account string) ([]byte, error)

func (SecurityKeychain) Set

func (k SecurityKeychain) Set(service, account string, secret []byte) error

type Store

type Store struct {
	Keychain Keychain
	Service  string
	LockPath string // default <os.UserCacheDir()>/<Service>.lock, so every process using one service shares the lock
	Client   *slack.Client
	ClientID string
	Now      func() time.Time
	Log      func(format string, args ...any) // names the service, never a token
	// contains filtered or unexported fields
}

func (*Store) AppToken

func (s *Store) AppToken() (string, error)

AppToken reads account "app"; ErrNotLoggedIn when absent.

func (*Store) Delete

func (s *Store) Delete() error

Delete deletes the user token only.

func (*Store) DeleteAppToken

func (s *Store) DeleteAppToken() error

func (*Store) Load

func (s *Store) Load() (Token, error)

Load returns the user token; ErrNotLoggedIn when absent.

func (*Store) Save

func (s *Store) Save(tok Token) error

func (*Store) SaveAppToken

func (s *Store) SaveAppToken(token string) error

SaveAppToken refuses a value that is not an app-level token.

func (*Store) Token

func (s *Store) Token(ctx context.Context) (string, error)

Token implements slack.TokenSource; refreshes within 5 min of expiry under an flock on LockPath.

type Token

type Token struct {
	Team, User      string // ids
	TeamName        string
	Access, Refresh string
	Expires         time.Time
	Granted         time.Time // when the user approved the grant (login); zero is unknown
	Scopes          []string  // granted user scopes, from the exchange or X-OAuth-Scopes
}

Jump to

Keyboard shortcuts

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