pveauth

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2017 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

type Config struct {
	// Username
	Username string

	// Password
	Password string

	TicketURL string
}

func (*Config) Client

func (c *Config) Client(ctx context.Context, t *Ticket) *http.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

func (c *Config) PasswordCredentialsTicket(ctx context.Context) (*Ticket, error)

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

func (t *Ticket) SetAuthHeader(r *http.Request)

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.

func (*Ticket) Valid

func (t *Ticket) Valid() bool

Valid reports whether t is non-nil, has an AccessTicket, and is not expired.

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

func (t *Transport) CancelRequest(req *http.Request)

CancelRequest cancels an in-flight request by closing its connection.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip authorizes and authenticates the request with an access ticket. If no ticket exists or ticket is expired, tries to refresh/fetch a new ticket.

Directories

Path Synopsis
Package internal contains support packages for oauth2 package.
Package internal contains support packages for oauth2 package.

Jump to

Keyboard shortcuts

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