Documentation
¶
Overview ¶
Package auth contains various implementations for authenticating with Cerberus. These implementations can be used standalone from the main Cerberus client to get a login token or manage authentication without having to set up a full client
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AWSAuth ¶
type AWSAuth struct {
// contains filtered or unexported fields
}
AWSAuth uses AWS roles and authentication to authenticate to Cerberus
func NewAWSAuth ¶
NewAWSAuth returns an AWSAuth given a valid URL, ARN, and region. If the CERBERUS_URL environment variable is set, it will be used over anything passed to this function. It also expects you to have valid AWS credentials configured either by environment variable or through a credentials config file
func (*AWSAuth) GetHeaders ¶
GetHeaders returns the headers needed to authenticate against Cerberus. This will return an error if the token is expired or non-existent
func (*AWSAuth) GetToken ¶
GetToken returns a token if it already exists and is not expired. Otherwise, it authenticates using the provided ARN and region and then returns the token. If there are any errors during authentication,
func (*AWSAuth) IsAuthenticated ¶
IsAuthenticated returns whether or not the current token is set and is not expired
type Auth ¶
type Auth interface { // GetToken should either return an existing token or perform all authentication steps // necessary to get a new token. It takes a file object as an argument as a place to // read an OTP for MFA flow GetToken(*os.File) (string, error) // IsAuthenticated should return whether or not there is a valid token. A valid token // is one that exists and is not expired IsAuthenticated() bool // Refresh uses the current valid token to retrieve a new one Refresh() error // Logout revokes the current token Logout() error // GetHeaders is a helper for any client using the authentication strategy. // It returns a basic set of headers asking for a JSON response and has // the authorization header set with the proper token GetHeaders() (http.Header, error) GetURL() *url.URL }
The Auth interface describes the methods that all authentication providers must satisfy
type TokenAuth ¶
type TokenAuth struct {
// contains filtered or unexported fields
}
TokenAuth uses a preexisting token to authenticate to Cerberus
func NewTokenAuth ¶
NewTokenAuth takes a Cerberus URL and valid token and returns a new TokenAuth. There is no checking done on whether or not the token is valid, so the function expects the a valid token. The URL and token can also be set using the CERBERUS_URL and CERBERUS_TOKEN environment variables. These will always take precedence over any arguments to the function
func (*TokenAuth) GetHeaders ¶
GetHeaders returns HTTP headers used for requests if the method is currently authenticated. Returns an error otherwise
func (*TokenAuth) GetToken ¶
GetToken returns the token passed when creating the TokenAuth. Nil should be passed as the argument to the function. The argument exists for compatibility with the Auth interface
func (*TokenAuth) IsAuthenticated ¶
IsAuthenticated always returns true if there is a token. If Logout has been called, it will return false
type UserAuth ¶
type UserAuth struct {
// contains filtered or unexported fields
}
UserAuth uses username and password authentication to authenticate against Cerberus
func NewUserAuth ¶
NewUserAuth returns a new UserAuth object given a valid Cerberus URL, username, and password
func (*UserAuth) GetHeaders ¶
GetHeaders is a helper for any client using the authentication strategy. It returns a basic set of headers asking for a JSON response and has the authorization header set with the proper token
func (*UserAuth) GetToken ¶
GetToken returns an existing token or performs all authentication steps necessary to get a new token. This should be called to authenticate the client once it has been setup
func (*UserAuth) IsAuthenticated ¶
IsAuthenticated returns whether or not there is a valid token. A valid token is one that exists and is not expired