Documentation ¶
Overview ¶
Package auth contains all the possible ways to authenticate against the Elastic Cloud API. Although there are different ways, the recommended authentication mechanism are API Keys, manageable via the UI or API Key management APIs.
Index ¶
- Variables
- type APIKey
- type GenericHolder
- type RefreshTokenParams
- type TokenHandler
- type UserLogin
- func (t *UserLogin) AuthRequest(req *http.Request) *http.Request
- func (t *UserLogin) AuthenticateRequest(c runtime.ClientRequest, r strfmt.Registry) error
- func (t *UserLogin) Login(c *client.Rest) error
- func (t *UserLogin) RefreshToken(params RefreshTokenParams) error
- func (t *UserLogin) RefreshTokenOnce(c *client.Rest) error
- func (t *UserLogin) Validate() error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoTokenAvailable should be returned by any implementations which // fail to find any persisted token for the user. ErrNoTokenAvailable = errors.New("auth: no persisted token available for the user") )
Functions ¶
This section is empty.
Types ¶
type APIKey ¶
type APIKey string
APIKey represents an APIKey used in the Authorization header as means of authentication. It is the preferred method of authentication.
func (APIKey) AuthRequest ¶
AuthRequest adds the Authorization header to an http.Request
func (APIKey) AuthenticateRequest ¶
AuthenticateRequest authenticates a runtime.ClientRequest. Implements the runtime.ClientAuthInfoWriter interface.
type GenericHolder ¶
type GenericHolder struct {
// contains filtered or unexported fields
}
GenericHolder is a simple implementation of TokenHandler which persists the token in an inmemory struct field which is guarded by a RWMutex.
func (*GenericHolder) Load ¶
func (t *GenericHolder) Load() (string, error)
Load returns a persisted token scoped to the current authenticated user.
func (*GenericHolder) Update ¶
func (t *GenericHolder) Update(s string) error
Update replaces the token with a new one.
type RefreshTokenParams ¶
type RefreshTokenParams struct { Client *client.Rest Frequency time.Duration ErrorDevice io.Writer InterruptChannel chan os.Signal }
RefreshTokenParams is used to refresh a bearer token, which is necessary before its validity expires.
func (*RefreshTokenParams) Validate ¶
func (params *RefreshTokenParams) Validate() error
Validate ensures that the parameters are valid.
type TokenHandler ¶
type TokenHandler interface { // Load returns a persisted token scoped to the current authenticated user. Load() (string, error) // Update replaces the token with a new one. Update(string) error // Token returns current token. Token() string }
TokenHandler is an interface which abstracts the application management of JWT Bearer tokens. Lightweight on purpose to allow loose implementations.
type UserLogin ¶
type UserLogin struct {
Username, Password string
Holder TokenHandler
}
UserLogin uses a user's username and password to login against the Login API Endpoint. Doing so obtains a JWT token which is then persisted in the token field, guarded by a mutex. This is a form of user authentication, but API Keys are still the preferred authentication mechanism.
func NewUserLogin ¶
NewUserLogin creates a UserLogin from a username and password. It does not automatically login against the API until Auth() is called.
func (*UserLogin) AuthRequest ¶
AuthRequest adds the Authorization header to an http.Request
func (*UserLogin) AuthenticateRequest ¶
AuthenticateRequest authenticates a runtime.ClientRequest. Implements the runtime.ClientAuthInfoWriter interface using the JWT Bearer token.
func (*UserLogin) Login ¶
Login calls the authentication/login endpoint with a username and password persisting the returned token.
func (*UserLogin) RefreshToken ¶
func (t *UserLogin) RefreshToken(params RefreshTokenParams) error
RefreshToken creates a goroutine which will run in the background refreshing the token every Frequency. It does not refresh the token until the first period has passed.
func (*UserLogin) RefreshTokenOnce ¶
RefreshTokenOnce refreshRefreshTokenOncees the current JWT token once.