Documentation
¶
Overview ¶
Package oauthflow runs the browser half of an OAuth 2.0 authorization code + PKCE login for a public client. It is shared by msgraph and gmail.
Two modes:
- loopback: listen on 127.0.0.1 (and ::1) at a random port, redirect to http://localhost:<port>/callback, and catch the code when the browser comes back. Needs a browser on the same machine.
- manual: for headless use (kubectl exec). The redirect goes to a port nobody listens on; the browser shows a connection error and the user pastes the address-bar URL (…/callback?code=…&state=…) on stdin.
Either way the state is checked and the PKCE verifier is returned for the token exchange, which the provider does with its own library.
Index ¶
Constants ¶
const DefaultCallbackPath = "/callback"
Variables ¶
This section is empty.
Functions ¶
func OpenBrowser ¶
OpenBrowser opens url with the platform's default handler.
func ParseRedirect ¶
ParseRedirect extracts the code from a pasted redirect URL (or just its query string) and checks the state.
Types ¶
type Params ¶
type Params struct {
// AuthorizeURL builds the provider's authorize URL.
AuthorizeURL func(redirectURI, state, codeChallenge string) string
Manual bool
CallbackPath string // default DefaultCallbackPath
Stdin io.Reader
// OnPrompt is called once the URL is ready, before waiting.
OnPrompt func(Prompt) error
// OpenBrowser, when set, is called in loopback mode; failure is ignored
// (the URL has been printed anyway).
OpenBrowser func(url string) error
}