Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var HTTPClient internal.ContextKey
HTTPClient is the context key to use with golang.org/x/net/context's WithValue function to associate an *http.Client value with a context.
Functions ¶
func NewClient ¶
func NewClient(ctx context.Context, src TicketSource) *http.Client
NewClient creates an *http.Client from a Context and TicketSource. The returned client is not valid beyond the lifetime of the context.
As a special case, if src is nil, a non-OAuth2 client is returned using the provided context. This exists to support related OAuth2 packages.
Types ¶
type Config ¶
func (*Config) Client ¶
Client returns an HTTP client using the provided ticket. The ticket will auto-refresh as necessary. The underlying HTTP transport will be obtained using the provided context. The returned client and its Transport should not be modified.
func (*Config) PasswordCredentialsTicket ¶
PasswordCredentialsTicket converts a resource owner username and password pair into a ticket.
The HTTP client to use is derived from the context. If nil, http.DefaultClient is used.
func (*Config) TicketSource ¶
func (c *Config) TicketSource(ctx context.Context, t *Ticket) TicketSource
TicketSource returns a TicketSource that returns t until t expires, automatically refreshing it as necessary using the provided context.
Most users will use Config.Client instead.
type Ticket ¶
type Ticket struct { // Ticket is the ticket that authorizes and authenticates // the requests. Ticket string `json:"ticket"` // CSRFPreventionToken is used for all write requests. CSRFPreventionToken string `json:"CSRFPreventionToken"` // Username Username string `json:"username"` }
Ticket represents the crendentials used to authorize the requests to access protected resources on the PVE server.
Most users of this package should not access fields of Ticket directly.
func (*Ticket) SetAuthHeader ¶
SetAuthHeader sets the Authorization header to r using the access ticket in t.
This method is unnecessary when using Transport or an HTTP Client returned by this package.
type TicketSource ¶
type TicketSource interface { // Ticket returns a ticket or an error. // Ticket must be safe for concurrent use by multiple goroutines. // The returned Ticket must not be modified. Ticket() (*Ticket, error) }
A TicketSource is anything that can return a ticket.
func ReuseTicketSource ¶
func ReuseTicketSource(t *Ticket, src TicketSource) TicketSource
ReuseTicketSource returns a TicketSource which repeatedly returns the same ticket as long as it's valid, starting with t. When its cached ticket is invalid, a new ticket is obtained from src.
ReuseTicketSource is typically used to reuse tickets from a cache (such as a file on disk) between runs of a program, rather than obtaining new tickets unnecessarily.
The initial ticket t may be nil, in which case the TicketSource is wrapped in a caching version if it isn't one already. This also means it's always safe to wrap ReuseTicketSource around any other TicketSource without adverse effects.
type Transport ¶
type Transport struct { // Source supplies the ticket to add to outgoing requests' // Authorization headers. Source TicketSource // Base is the base RoundTripper used to make HTTP requests. // If nil, http.DefaultTransport is used. Base http.RoundTripper // contains filtered or unexported fields }
Transport is an http.RoundTripper that makes OAuth 2.0 HTTP requests, wrapping a base RoundTripper and adding an Authorization header with a ticket from the supplied Sources.
Transport is a low-level mechanism. Most code will use the higher-level Config.Client method instead.
func (*Transport) CancelRequest ¶
CancelRequest cancels an in-flight request by closing its connection.