Documentation ¶
Index ¶
- Constants
- func TokenSource(ctx context.Context, clientID, clientSecret string, opts ...Option) oauth2.TokenSource
- type AuthCodeURLHandler
- type AuthCodeURLHandlerFunc
- type Option
- func WithAuthCodeURLHandler(val AuthCodeURLHandler) Option
- func WithCallbackAddr(val string) Option
- func WithDebug(val io.Writer) Option
- func WithEndpoint(val oauth2.Endpoint) Option
- func WithIgnoreErrors() Option
- func WithRedirectURL(val string) Option
- func WithScope(val ...string) Option
- func WithoutOpen() Option
Constants ¶
const DefaultCallbackAddr = ":4445"
DefaultCallbackAddr is the default address:host on which a local http.Server will be started. It can be overridden using WithCallbackAddr.
const DefaultRedirectURL = "http://localhost:4445/callback"
DefaultRedirectURL is the default RedirectURL that the oauth2 flow will use. It can be overridden using WithRedirectURL.
Variables ¶
This section is empty.
Functions ¶
func TokenSource ¶
func TokenSource(ctx context.Context, clientID, clientSecret string, opts ...Option) oauth2.TokenSource
TokenSource returns an oauth2.TokenSource that will provide tokens using the three legged oauth2 flow.
Types ¶
type AuthCodeURLHandler ¶
type AuthCodeURLHandler interface {
AuthCodeURL(string)
}
An AuthCodeURLHandler is asynchronously passed the AuthCodeURL when Token() is called
type AuthCodeURLHandlerFunc ¶
type AuthCodeURLHandlerFunc func(string)
The AuthCodeURLHandlerFunc type is an adapter to allow the use of ordinary functions as AuthCodeURLHandlers. If f is a function with the appropriate signature, AuthCodeURLHandlerFunc(f) is a Handler that calls f.
func (AuthCodeURLHandlerFunc) AuthCodeURL ¶
func (f AuthCodeURLHandlerFunc) AuthCodeURL(u string)
AuthCodeURL calls f(u)
type Option ¶
type Option func(*userAccreditor)
An Option is used to configure the oauth2 user credential flow.
func WithAuthCodeURLHandler ¶
func WithAuthCodeURLHandler(val AuthCodeURLHandler) Option
WithAuthCodeURLHandler returns an Option that will cause the passed in handler to be called in a new goroutine with the value of the URL that should be opened. This allows programmatic user authentication (e.g. without interacting with the browser). Overrides WithoutOpen().
func WithCallbackAddr ¶
WithCallbackAddr returns an Option that specifies the address:host on which a local http.Server will be configured to listen for the redirect. It should be reachable by going to the RedirectURL.
func WithDebug ¶
WithDebug returns an option that causes incoming http.Requests to the callback server to be logged to the writer.
func WithEndpoint ¶
WithEndpoint returns an Option that specifies the oauth2 endpoint that will be used to get tokens. By default it uses zapi.Endpoint.
func WithIgnoreErrors ¶
func WithIgnoreErrors() Option
WithIgnoreErrors returns an Option that prevents redirect uris from the server containing errors from stopping the listener server. This should only be used for testing.
func WithRedirectURL ¶
WithRedirectURL returns an Option that specifies the RedirectURL that will be used by the oauth2 flow. The client must be configured on the oauth2 server to permit this value or else the flow will fail.
func WithScope ¶
WithScope returns an Option that specifies the scopes that will be requested for the token. If not specified, zapi.DefaultScopes will be used.
func WithoutOpen ¶
func WithoutOpen() Option
WithoutOpen returns an Option that will prevent a browser window from being opened automatically and will instead direct the user to open the url emitted on stderr.