Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Config ¶
Config configures the OAUTH middleware and handlers
generate the KeyPhrase with `openssl rand -hex 32`
func NewOAUTHCallbackHandler ¶
NewOAUTHCallbackHandler returns a handler that handles an OAUTH callback from the provider.
Types ¶
type AuthHolder ¶
type AuthHolder interface { // Client returns an HTTP client that uses the OAUTH2 token for communication Client(log.Logger) *http.Client // Encrypt returns the stored OAUTH2 token in encrypted form // // If any errors are experienced during token retrieval or encryption, // returns codes for the HTTP response writer are automatically set. // // # This should be called as the last step before writing a final response // // Returns: // // encrypted token: Encrypted form of the OAUTH2 token // success: If the function was successful // // Note: // // On an unsuccessful run, the HTTP status code and returned JSON are automatically written to the HTTP response // writer. Encrypt(http.ResponseWriter, log.Logger) (string, bool) }
AuthHolder holds a validated OAUTH2 token for usage outside the OAUTH2 middleware
func ExchangeLoginCookie ¶ added in v0.2.0
func ExchangeLoginCookie(w http.ResponseWriter, r *http.Request, l log.Logger) (AuthHolder, bool)
ExchangeLoginCookie retrieves encrypted authentication data from a stored cookie and exchanges it for an OAUTH2 token, validates the token, and returns it in an AuthHolder
Returns:
AuthHolder: The AuthHolder interface containing an OAUTH2.Source for token retrieval success: If the function was successful
Note:
On an unsuccessful run, the HTTP status code and returned JSON are automatically written to the HTTP response writer.
func ExchangeLoginHeader ¶
func ExchangeLoginHeader(w http.ResponseWriter, r *http.Request, l log.Logger) (AuthHolder, bool)
ExchangeLoginHeader retrieves encrypted authentication data from the Authorization header, exchanges it for an OAUTH2 token, validates the token, and returns it in an AuthHolder
Returns:
AuthHolder: The AuthHolder interface containing an OAUTH2.Source for token retrieval success: If the function was successful
Note:
On an unsuccessful run, the HTTP status code and returned JSON are automatically written to the HTTP response writer.
type Options ¶
type Options struct { // ClientID is the OAUTH2 Client ID ClientID string `json:"client_id" toml:"client_id" yaml:"client_id"` // ClientSecret is the OAUTH2 Client Secret ClientSecret string `json:"client_secret" toml:"client_secret" yaml:"client_secret"` // CookiePath is the path to set for cookies (Optional. Default: /) CookiePath string `json:"cookie_path" toml:"cookie_path" yaml:"cookie_path"` // KeyPhrase is the key phrase used for encryption KeyPhrase string `json:"key_phrase" toml:"key_phrase" yaml:"key_phrase"` // ProviderURL is the OAUTH2 Provider URL ProviderURL string `json:"provider_url" toml:"provider_url" yaml:"provider_url"` // RedirectURL is the URL that should be redirected to upon a successful OAUTH2 login RedirectURL string `json:"redirect_url" toml:"redirect_url" yaml:"redirect_url"` // Scopes are the OAUTH2 scopes to be requested Scopes []string `json:"scopes" toml:"scopes" yaml:"scopes"` // StateCookieName is the name of the cookie used for storing state information (Optional. Default: rutarState) StateCookieName string `json:"state_cookie_name" toml:"state_cookie_name" yaml:"state_cookie_name"` // StateTimeout is the amount of time, in seconds, before the state cookie times out StateTimeout int `json:"state_timeout" toml:"state_timeout" yaml:"state_timeout"` // TokenCookieName is the name of the cookie used for storing token information (Optional. Default: rutarToken) TokenCookieName string `json:"token_cookie_name" toml:"token_cookie_name" yaml:"token_cookie_name"` }
Options holds the configuration options for the OAUTH2 middleware package