provider

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MockAuthCodeURL = "http://localhost/authorize"
	MockTokenURL    = "http://localhost/token"
)

Variables

View Source
var (
	ErrNoSuchProvider        = errors.New("provider: no provider with the given name")
	ErrNoProviderWithVersion = errors.New("provider: version not supported")
	ErrNoOptions             = errors.New("provider: options provided but none accepted")
)
View Source
var GlobalRegistry = NewRegistry()
View Source
var MockEndpoint = oauth2.Endpoint{
	AuthURL:  MockAuthCodeURL,
	TokenURL: MockTokenURL,
}

Functions

func ErrorMockExchange

func ErrorMockExchange(_ string) (*oauth2.Token, error)

func RandomMockExchange

func RandomMockExchange(_ string) (*oauth2.Token, error)

Types

type AuthCodeURLConfig

type AuthCodeURLConfig interface {
	AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
}

AuthCodeURLConfig is the component of *oauth2.Config required for generating authorization code URLs.

type AuthCodeURLConfigBuilder

type AuthCodeURLConfigBuilder interface {
	// WithRedirectURL sets the redirect URL for the config.
	WithRedirectURL(redirectURL string) AuthCodeURLConfigBuilder

	// WithScopes sets the scopes for the config.
	WithScopes(scopes ...string) AuthCodeURLConfigBuilder

	// Build creates an AuthCodeURLConfig from the current configuration.
	Build() AuthCodeURLConfig
}

AuthCodeURLConfigBuilder creates AuthCodeURLConfigs.

type ExchangeConfig

type ExchangeConfig interface {
	Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
	TokenSource(ctx context.Context, t *oauth2.Token) oauth2.TokenSource
}

ExchangeConfig is the component of *oauth2.Config required to exchange an authorization code for a token.

type ExchangeConfigBuilder

type ExchangeConfigBuilder interface {
	// WithHTTPClient uses the given HTTP client to perform the exchange.
	WithHTTPClient(client *http.Client) ExchangeConfigBuilder

	// WithRedirectURL sets the redirect URL for the config.
	WithRedirectURL(redirectURL string) ExchangeConfigBuilder

	// Build creates an ExchangeConfig from the current configuration.
	Build() ExchangeConfig
}

ExchangeConfigBuilder creates ExchangeConfigs.

type FactoryFunc

type FactoryFunc func(vsn int, opts map[string]string) (Provider, error)

func MockFactory

func MockFactory(opts ...MockOption) FactoryFunc

type MockClient

type MockClient struct {
	ID     string
	Secret string
}

type MockExchangeFunc

type MockExchangeFunc func(code string) (*oauth2.Token, error)

func AmendTokenMockExchange

func AmendTokenMockExchange(get MockExchangeFunc, amend func(token *oauth2.Token) error) MockExchangeFunc

func ExpiringMockExchange

func ExpiringMockExchange(fn MockExchangeFunc, duration time.Duration) MockExchangeFunc

func IncrementMockExchange

func IncrementMockExchange(prefix string) MockExchangeFunc

func RefreshableMockExchange

func RefreshableMockExchange(fn MockExchangeFunc, step func(i int) (time.Duration, error)) MockExchangeFunc

func RestrictMockExchange

func RestrictMockExchange(m map[string]MockExchangeFunc) MockExchangeFunc

func StaticMockExchange

func StaticMockExchange(token *oauth2.Token) MockExchangeFunc

type MockOption

type MockOption func(m *mock)

func MockWithExchange

func MockWithExchange(client MockClient, fn MockExchangeFunc) MockOption

func MockWithExpectedOptionValue

func MockWithExpectedOptionValue(opt, value string) MockOption

func MockWithVersion

func MockWithVersion(vsn int) MockOption

type OptionError

type OptionError struct {
	Option  string
	Message string
}

func (*OptionError) Error

func (oe *OptionError) Error() string

type Provider

type Provider interface {
	// Version is the revision of this provider vis-a-vis the options it
	// supports.
	Version() int

	// NewAuthCodeURLConfigBuilder creates a config builder automatically scoped
	// to this provider with the specified options.
	NewAuthCodeURLConfigBuilder(clientID string) AuthCodeURLConfigBuilder

	// NewExchangeConfigBuilder creates a new config builder for token exchange.
	NewExchangeConfigBuilder(clientID, clientSecret string) ExchangeConfigBuilder
}

Provider represents an integration with a particular OAuth provider using the authorization code grant.

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) MustRegister

func (r *Registry) MustRegister(name string, factory FactoryFunc)

func (*Registry) New

func (r *Registry) New(name string, opts map[string]string) (Provider, error)

New looks up a provider with the given name and configures it according to the specified options.

func (*Registry) NewAt

func (r *Registry) NewAt(name string, vsn int, opts map[string]string) (Provider, error)

NewAt looks up a provider with the given name at the given version and configures it according to the specified options.

func (*Registry) Register

func (r *Registry) Register(name string, factory FactoryFunc) error

Register registers a new provider using the name and factory specified.

Jump to

Keyboard shortcuts

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