auth

package
v3.0.0-pre-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const RODHeadlessTimeout = 40 * time.Second

RODHeadlessTimeout is the default timeout for the headless login flow. It is a net time of headless browser interaction, without the browser starting time.

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

func IsClientToken(tok string) bool

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

func IsDocker

func IsDocker() bool

func IsInvalidAuthErr

func IsInvalidAuthErr(err error) bool

func ParseDotEnv

func ParseDotEnv(filename string) (string, string, error)

func Save

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

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

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

func (BrowserAuth) SlackToken

func (c BrowserAuth) SlackToken() string

func (BrowserAuth) Test

func (s BrowserAuth) Test(ctx context.Context) (*slack.AuthTestResponse, error)

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

func (BrowserAuth) Validate

func (c BrowserAuth) Validate() error

type BrowserAuthUI

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

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

func (CookieFileAuth) SlackToken

func (c CookieFileAuth) SlackToken() string

func (CookieFileAuth) Test

func (s CookieFileAuth) Test(ctx context.Context) (*slack.AuthTestResponse, error)

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

func (CookieFileAuth) Validate

func (c CookieFileAuth) Validate() error

type Error

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

func (ae *Error) Error() string

func (*Error) Is

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

func (*Error) Unwrap

func (ae *Error) Unwrap() error

type Option

type Option func(*options)

func BrowserWithAuthFlow

func BrowserWithAuthFlow(flow BrowserAuthUI) Option

func BrowserWithBrowser

func BrowserWithBrowser(b browser.Browser) Option

func BrowserWithTimeout

func BrowserWithTimeout(d time.Duration) Option

func BrowserWithVerbose

func BrowserWithVerbose(b bool) Option

func BrowserWithWorkspace

func BrowserWithWorkspace(name string) Option

func RODWithRODHeadlessTimeout

func RODWithRODHeadlessTimeout(d time.Duration) Option

RODWithRODHeadlessTimeout sets the timeout for the headless browser interaction. It is a net time of headless browser interaction, without the browser starting time.

func RODWithUserAgent

func RODWithUserAgent(ua string) Option

RODWithUserAgent sets the user agent string for the headless browser.

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) (*slack.AuthTestResponse, error)
	// Client returns an authenticated HTTP client
	HTTPClient() (*http.Client, error)
}

Provider is the Slack Authentication provider.

func FromContext

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

FromContext returns the auth provider from the context.

type RodAuth

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

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

NewRODAuth constructs new RodAuth provider.

func (RodAuth) Cookies

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

func (RodAuth) HTTPClient

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

func (RodAuth) SlackToken

func (c RodAuth) SlackToken() string

func (RodAuth) Test

func (s RodAuth) Test(ctx context.Context) (*slack.AuthTestResponse, error)

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

func (RodAuth) Validate

func (c RodAuth) Validate() error

type ValueAuth

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

ValueAuth stores Slack credentials.

func Load

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 NewValueCookiesAuth

func NewValueCookiesAuth(token string, cookies []*http.Cookie) (ValueAuth, error)

func (ValueAuth) Cookies

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

func (ValueAuth) HTTPClient

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

func (ValueAuth) SlackToken

func (c ValueAuth) SlackToken() string

func (ValueAuth) Test

func (s ValueAuth) Test(ctx context.Context) (*slack.AuthTestResponse, error)

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

func (ValueAuth) Validate

func (c ValueAuth) Validate() error

Directories

Path Synopsis
pwcompat
Package pwcompat provides a compatibility layer, so when the playwright-go team decides to break compatibility again, there's a place to write a workaround.
Package pwcompat provides a compatibility layer, so when the playwright-go team decides to break compatibility again, there's a place to write a workaround.

Jump to

Keyboard shortcuts

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