Documentation
¶
Overview ¶
Package authx applies the authentication schemes of a request's auth block: it adds what a scheme needs (a key, a token, a signature) to the request just before it is sent, and reports what it added so the record can show it with the secret parts masked.
Every parameter reaches this package already rendered, so credentials come from the vault by the templates that named them; nothing here reads a secret or a file of its own accord.
Index ¶
Constants ¶
const ( // PromptOpen asks the person to open URL in a browser, sign in and approve. PromptOpen = "open" // PromptDevice asks the person to open URL on any device and enter Code. PromptDevice = "device" )
Prompt kinds.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Applied ¶
type Applied struct {
Where string // header, query or cookie
Name string
Value string
Secret bool // the value is a credential or derived from one: show it masked
}
Applied is one thing a scheme added to a request.
type Challenger ¶
Challenger is a Signer for a scheme that answers a 401: Challenge reads the response to the request sent without credentials and reports whether Apply can now authenticate it, in which case the caller sends it again.
type Env ¶
type Env struct {
// HTTP calls token endpoints (OAuth 2.0); nil uses a client with a
// timeout of its own.
HTTP *http.Client
// Now is the clock for timestamps and token expiry; nil is time.Now.
Now func() time.Time
// Tokens caches OAuth 2.0 tokens between sends; nil keeps none.
Tokens *TokenCache
// Nonce returns a random string of n characters; nil uses crypto/rand.
Nonce func(n int) string
// Prompt tells the person what to do for a grant that needs one (open a
// page, enter a code). It must return at once; nil means nobody is
// there, and such a grant waits until its context ends.
Prompt func(Prompt)
// After is a timer on the scheme's clock, for polling; nil is time.After.
After func(time.Duration) <-chan time.Time
}
Env is what the schemes need from outside.
type Prompt ¶
type Prompt struct {
Kind string
URL string
Code string // PromptDevice: the code to enter
Expires time.Time // when the request stops being valid
}
Prompt is what a grant that needs a person asks of them.
type Signer ¶
Signer adds a scheme's credentials to a request before it is sent. It may change r.Header and r.URL.
type TokenCache ¶
type TokenCache struct {
// contains filtered or unexported fields
}
TokenCache keeps OAuth 2.0 tokens between sends, so a collection run asks the token endpoint once, not for every request. It is safe for concurrent use.