Documentation ¶
Index ¶
- func ConfigCookies(path string, stateName string, tokenName string)
- func ConfigKeyPhrase(keyPhrase string) error
- func ConfigOAUTH(providerURL string, clientID string, clientSecret string, redirectURL string, ...) error
- func ConfigStateTimeout(timeout int)
- func NewOAUTHCallbackHandler(l log.Logger) http.Handler
- func NewOAUTHStartHandler(l log.Logger) http.Handler
- type AuthHolder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigCookies ¶ added in v0.6.0
ConfigCookies handles configurations of cookies
Note:
- path refers the path set in the cookie
- stateName is the name of the cookie that will hold the encrypted state during the beginning of an OAUTH Login
- tokenName is the name of the cookie that will hold the encrypted OAUTH token after a successful OAUTH login
func ConfigKeyPhrase ¶ added in v0.6.0
ConfigKeyPhrase validates the provided key phrase and then stores it for usage.
This key phrase is used for encrypting and decrypting the OAUTH2 token that is stored client side.
Generate the KeyPhrase with `openssl rand -hex 32`
func ConfigOAUTH ¶ added in v0.6.0
func ConfigOAUTH(providerURL string, clientID string, clientSecret string, redirectURL string, scopes []string) error
ConfigOAUTH configures the OAUTH2 handlers
providerURL is the URL for the OAUTH2 Provider * Example: https://accounts.google.com clientID is the OAUTH2 client ID provided by the OAUTH provider clientSecret is the OAUTH2 client secret provided by the OAUTH provider sRedirectURL is the URL to redirect users to after the OAUTH2 login flow scopes are the OAUTH2 scopes that will be requested during the OAUTH2 flow
func ConfigStateTimeout ¶ added in v0.6.0
func ConfigStateTimeout(timeout int)
ConfigStateTimeout sets the timeout to be used for honoring state token expiration
The default is 300 seconds (5 minutes) if no timeout is provided
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.