Documentation
¶
Overview ¶
Package oauth2cli provides better user experience on OAuth 2.0 and OpenID Connect (OIDC) on CLI. It allows simple and easy user interaction with Authorization Code Grant Flow and a local server.
Index ¶
Constants ¶
View Source
const DefaultLocalServerSuccessHTML = `<html><body>OK<script>window.close()</script></body></html>`
DefaultLocalServerSuccessHTML is a default response body on authorization success.
Variables ¶
This section is empty.
Functions ¶
func GetToken ¶ added in v1.4.0
GetToken performs Authorization Code Grant Flow and returns a token got from the provider. See https://tools.ietf.org/html/rfc6749#section-4.1
This does the following steps:
- Start a local server at the port.
- Open a browser and navigate it to the local server.
- Wait for the user authorization.
- Receive a code via an authorization response (HTTP redirect).
- Exchange the code and a token.
- Return the code.
Types ¶
type Config ¶ added in v1.4.0
type Config struct {
OAuth2Config oauth2.Config
AuthCodeOptions []oauth2.AuthCodeOption
// If true, skip opening the browser.
SkipOpenBrowser bool
// Candidates of a port which the local server binds to.
// If multiple ports are given, it will try the ports in order.
// If nil or an empty slice is given, it will allocate a free port.
LocalServerPort []int
// Response HTML body on authorization completed.
// Default to DefaultLocalServerSuccessHTML.
LocalServerSuccessHTML string
// Called when the local server is started. Default to none.
ShowLocalServerURL func(url string)
// Middleware for the local server. Default to none.
LocalServerMiddleware func(h http.Handler) http.Handler
}
Config represents a config for GetToken.
Click to show internal directories.
Click to hide internal directories.