oauthflow

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const DefaultCallbackPath = "/callback"

Variables

This section is empty.

Functions

func OpenBrowser

func OpenBrowser(u string) error

OpenBrowser opens url with the platform's default handler.

func ParseRedirect

func ParseRedirect(pasted, wantState string) (string, error)

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
}

type Prompt

type Prompt struct {
	Mode         string `json:"mode"` // loopback | manual
	AuthorizeURL string `json:"authorize_url"`
	RedirectURI  string `json:"redirect_uri"`
	Instructions string `json:"instructions"`
}

Prompt is printed (as JSON) so a person or agent can complete the login.

type Result

type Result struct {
	Code         string
	RedirectURI  string
	CodeVerifier string
}

func Run

func Run(ctx context.Context, p Params) (*Result, error)

Run performs the browser step and returns the authorization code.

Jump to

Keyboard shortcuts

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