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 AuthCodeFlowSuccessResponse = `<html><body>OK<script>window.close()</script></body></html>`
AuthCodeFlowSuccessResponse is a default response body on authorization success.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthCodeFlow ¶
type AuthCodeFlow struct {
Config oauth2.Config // OAuth2 config.
AuthCodeOptions []oauth2.AuthCodeOption // OAuth2 options.
SkipOpenBrowser bool // If set, skip opening browser.
// 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 success.
// Default to AuthCodeFlowSuccessResponse.
LocalServerSuccessResponse 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
}
AuthCodeFlow provides the flow with OAuth 2.0 Authorization Code Grant. See https://tools.ietf.org/html/rfc6749#section-4.1
func (*AuthCodeFlow) GetToken ¶
GetToken performs the Authorization Grant Flow and returns a token got from the provider.
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.
Click to show internal directories.
Click to hide internal directories.