Documentation
¶
Index ¶
- Constants
- Variables
- func ErrorMockExchange(_ string) (*oauth2.Token, error)
- func RandomMockExchange(_ string) (*oauth2.Token, error)
- type AuthCodeURLConfig
- type AuthCodeURLConfigBuilder
- type ExchangeConfig
- type ExchangeConfigBuilder
- type FactoryFunc
- type MockClient
- type MockExchangeFunc
- func AmendTokenMockExchange(get MockExchangeFunc, amend func(token *oauth2.Token) error) MockExchangeFunc
- func ExpiringMockExchange(fn MockExchangeFunc, duration time.Duration) MockExchangeFunc
- func IncrementMockExchange(prefix string) MockExchangeFunc
- func RefreshableMockExchange(fn MockExchangeFunc, step func(i int) (time.Duration, error)) MockExchangeFunc
- func RestrictMockExchange(m map[string]MockExchangeFunc) MockExchangeFunc
- func StaticMockExchange(token *oauth2.Token) MockExchangeFunc
- type MockOption
- type OptionError
- type Provider
- type Registry
- func (r *Registry) MustRegister(name string, factory FactoryFunc)
- func (r *Registry) New(name string, opts map[string]string) (Provider, error)
- func (r *Registry) NewAt(name string, vsn int, opts map[string]string) (Provider, error)
- func (r *Registry) Register(name string, factory FactoryFunc) error
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 ¶
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 ¶
func MockFactory ¶
func MockFactory(opts ...MockOption) FactoryFunc
type MockClient ¶
type MockExchangeFunc ¶
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 ¶
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 ¶
New looks up a provider with the given name and configures it according to the specified options.
Click to show internal directories.
Click to hide internal directories.