Documentation
¶
Overview ¶
Package auth is an internal package that provides authentication utilities.
IMPORTANT: This package is not meant to be used directly by consumers of the SDK and is subject to change without notice.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Credentials ¶
Credentials represents a named source of authentication headers.
type Option ¶
type Option func(*cachedTokenProvider)
func WithAsyncRefresh ¶
WithAsyncRefresh enables or disables the asynchronous token refresh.
func WithCachedToken ¶
WithCachedToken sets the initial token to be used by a cached token source.
type Token ¶
type Token struct {
// Value is the raw value to sign requests with. It typically is an
// access token but can represent other types of tokens (e.g. ID tokens).
Value string
// Type is the type of token. If Type is empty, the token type is
// assumed to be "Bearer".
Type string
// Expiry is the time at which the token expires. If Expiry is zero, the
// token is considered to be valid indefinitely.
Expiry time.Time
}
Token represents a token that can be used to sign requests.
type TokenCredentials ¶
type TokenCredentials interface {
TokenProvider
Credentials
}
func NewTokenCredentials ¶
func NewTokenCredentials(name string, p TokenProvider) TokenCredentials
NewTokenCredentials returns TokenCredentials with the given name that use the given TokenProvider to return authentication headers.
type TokenProvider ¶
type TokenProvider interface {
// Token returns a token or an error. The returned Token should be
// considered immutable and should not be modified.
Token(context.Context) (*Token, error)
}
A TokenProvider is anything that can return a token.
func NewCachedTokenProvider ¶
func NewCachedTokenProvider(ts TokenProvider, opts ...Option) TokenProvider
NewCachedTokenProvider wraps a TokenProvider to cache the tokens it returns. By default, the cache will refresh tokens asynchronously a few minutes before they expire.
The token cache is safe for concurrent use by multiple goroutines and will guarantee that only one token refresh is triggered at a time.
The token cache does not take care of retries in case the token source returns and error; it is the responsibility of the provided token source to handle retries appropriately.
If the TokenProvider is already a cached token source (obtained by calling this function), it is returned as is.
func NewRetryingTokenProvider ¶
func NewRetryingTokenProvider(inner TokenProvider, opts ...ops.Option) TokenProvider
NewRetryingTokenProvider wraps a TokenProvider with retry logic for transient failures.
By default, the return TokenProvider will retry on transient error failures (network errors, timeouts, ...) as well as the following HTTP status codes:
- 429 Too Many Requests
- 502 Bad Gateway
- 503 Service Unavailable
- 504 Gateway Timeout
The provided options are applied after the defaults, allowing callers to override the default timeout and retry behavior.
type TokenProviderFn ¶
TokenProviderFn is an adapter to allow the use of ordinary functions as TokenProvider.
Example:
ts := TokenProviderFn(func(ctx context.Context) (*Token, error) {
return &Token{}, nil
})
Directories
¶
| Path | Synopsis |
|---|---|
|
Package oidc provides utilities for working with OIDC ID tokens.
|
Package oidc provides utilities for working with OIDC ID tokens. |
|
Package transport provides a HTTP transport that automatically adds authentication headers to outgoing requests.
|
Package transport provides a HTTP transport that automatically adds authentication headers to outgoing requests. |