auth

package
v2.5.3 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const SlackURL = "https://slack.com"

Variables

View Source
var (
	ErrNoToken      = errors.New("no token")
	ErrNoCookies    = errors.New("no cookies")
	ErrNotSupported = errors.New("not supported")
	// ErrCancelled may be returned by auth providers, if the authentication
	// process was cancelled.
	ErrCancelled = errors.New("authentication cancelled")
)
View Source
var ErrNoProvider = errors.New("internal error:  no provider in context")

Functions

func IsClientToken added in v2.2.3

func IsClientToken(tok string) bool

IsClientToken returns true if the tok is a web-client token.

func IsDocker added in v2.5.3

func IsDocker() bool

func Save added in v2.1.0

func Save(w io.Writer, p Provider) error

Save serialises authentication information to writer. It will return ErrNoToken or ErrNoCookie if provider fails validation.

func WithContext added in v2.3.0

func WithContext(pctx context.Context, p Provider) context.Context

WithContext returns context with auth provider.

Types

type BrowserAuth

type BrowserAuth struct {
	// contains filtered or unexported fields
}

func NewBrowserAuth

func NewBrowserAuth(ctx context.Context, opts ...Option) (BrowserAuth, error)

func (BrowserAuth) Cookies

func (c BrowserAuth) Cookies() []*http.Cookie

func (BrowserAuth) HTTPClient added in v2.4.6

func (s BrowserAuth) HTTPClient() (*http.Client, error)

func (BrowserAuth) SlackToken

func (c BrowserAuth) SlackToken() string

func (BrowserAuth) Test added in v2.3.0

func (s BrowserAuth) Test(ctx context.Context) error

TestAuth attempts to authenticate with the given provider. It will return AuthError if failed.

func (BrowserAuth) Type added in v2.0.3

func (BrowserAuth) Type() Type

func (BrowserAuth) Validate

func (c BrowserAuth) Validate() error

type BrowserAuthUI added in v2.0.3

type BrowserAuthUI interface {
	// RequestWorkspace should request the workspace name from the user.
	RequestWorkspace(w io.Writer) (string, error)
	// Stop indicates that the auth flow should cleanup and exit, if it is
	// keeping the state.
	Stop()
}

type CookieFileAuth

type CookieFileAuth struct {
	// contains filtered or unexported fields
}

func NewCookieFileAuth

func NewCookieFileAuth(token string, cookieFile string) (CookieFileAuth, error)

NewCookieFileAuth creates new auth provider from token and Mozilla cookie file.

func (CookieFileAuth) Cookies

func (c CookieFileAuth) Cookies() []*http.Cookie

func (CookieFileAuth) HTTPClient added in v2.4.6

func (s CookieFileAuth) HTTPClient() (*http.Client, error)

func (CookieFileAuth) SlackToken

func (c CookieFileAuth) SlackToken() string

func (CookieFileAuth) Test added in v2.3.0

func (s CookieFileAuth) Test(ctx context.Context) error

TestAuth attempts to authenticate with the given provider. It will return AuthError if failed.

func (CookieFileAuth) Type added in v2.0.3

func (CookieFileAuth) Type() Type

func (CookieFileAuth) Validate

func (c CookieFileAuth) Validate() error

type Error added in v2.3.0

type Error struct {
	Err error
	Msg string
}

Error is the error returned by New, the underlying Err contains an API error returned by slack.AuthTest call.

func (*Error) Error added in v2.3.0

func (ae *Error) Error() string

func (*Error) Is added in v2.3.0

func (ae *Error) Is(target error) bool

func (*Error) Unwrap added in v2.3.0

func (ae *Error) Unwrap() error

type Option added in v2.3.0

type Option func(*options)

func BrowserWithAuthFlow added in v2.0.3

func BrowserWithAuthFlow(flow BrowserAuthUI) Option

func BrowserWithBrowser added in v2.3.0

func BrowserWithBrowser(b browser.Browser) Option

func BrowserWithTimeout added in v2.4.4

func BrowserWithTimeout(d time.Duration) Option

func BrowserWithVerbose added in v2.5.0

func BrowserWithVerbose(b bool) Option

func BrowserWithWorkspace added in v2.0.3

func BrowserWithWorkspace(name string) Option

type Provider

type Provider interface {
	// SlackToken should return the Slack Token value.
	SlackToken() string
	// Cookies should return a set of Slack Session cookies.
	Cookies() []*http.Cookie
	// Validate should return error, in case the token or cookies cannot be
	// retrieved.
	Validate() error
	// Test tests if credentials are valid.
	Test(ctx context.Context) error
	// Client returns an authenticated HTTP client
	HTTPClient() (*http.Client, error)
}

Provider is the Slack Authentication provider.

func FromContext added in v2.3.0

func FromContext(ctx context.Context) (Provider, error)

FromContext returns the auth provider from the context.

type RodAuth added in v2.5.0

type RodAuth struct {
	// contains filtered or unexported fields
}

RodAuth is an authentication provider that uses a headless or interactive browser to authenticate with Slack, depending on the user's choice. It uses rod library to drive the browser via the CDP protocol.

User can choose between:

  • Email/password login - will be done headlessly
  • SSO authentication - will open the browser and let the user do the thing.
  • Cancel - will cancel the login flow.

Headless login is a bit fragile. If it fails, user should be advised to login interactively by choosing SSO auth type.

func NewRODAuth added in v2.5.0

func NewRODAuth(ctx context.Context, opts ...Option) (RodAuth, error)

NewRODAuth constructs new RodAuth provider.

func (RodAuth) Cookies added in v2.5.0

func (c RodAuth) Cookies() []*http.Cookie

func (RodAuth) HTTPClient added in v2.5.0

func (s RodAuth) HTTPClient() (*http.Client, error)

func (RodAuth) SlackToken added in v2.5.0

func (c RodAuth) SlackToken() string

func (RodAuth) Test added in v2.5.0

func (s RodAuth) Test(ctx context.Context) error

TestAuth attempts to authenticate with the given provider. It will return AuthError if failed.

func (RodAuth) Type added in v2.5.0

func (p RodAuth) Type() Type

func (RodAuth) Validate added in v2.5.0

func (c RodAuth) Validate() error

type Type added in v2.0.3

type Type uint8

Type is the auth type.

const (
	TypeInvalid    Type = iota // Invalid
	TypeValue                  // Value
	TypeCookieFile             // Cookie File
	TypeBrowser                // EZ-Login 3000
	TypeRod                    // EZ-Login 3001
)

All supported auth types.

func (Type) String added in v2.3.0

func (i Type) String() string

type ValueAuth

type ValueAuth struct {
	// contains filtered or unexported fields
}

ValueAuth stores Slack credentials.

func Load added in v2.1.0

func Load(r io.Reader) (ValueAuth, error)

Load deserialises JSON data from reader and returns a ValueAuth, that can be used to authenticate Slackdump. It will return ErrNoToken or ErrNoCookie if the authentication information is missing.

func NewValueAuth

func NewValueAuth(token string, cookie string) (ValueAuth, error)

func (ValueAuth) Cookies

func (c ValueAuth) Cookies() []*http.Cookie

func (ValueAuth) HTTPClient added in v2.4.6

func (s ValueAuth) HTTPClient() (*http.Client, error)

func (ValueAuth) SlackToken

func (c ValueAuth) SlackToken() string

func (ValueAuth) Test added in v2.3.0

func (s ValueAuth) Test(ctx context.Context) error

TestAuth attempts to authenticate with the given provider. It will return AuthError if failed.

func (ValueAuth) Type added in v2.0.3

func (ValueAuth) Type() Type

func (ValueAuth) Validate

func (c ValueAuth) Validate() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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