From 020bb02a3824205bdf24f34d0afae4291f0cec8f Mon Sep 17 00:00:00 2001 From: magikstm Date: Sat, 13 May 2017 04:07:27 -0400 Subject: [PATCH] Correct some mispellings and minor cleanup Correct some mispellings and minor cleanup Correct some errors introduced in last commit Commit some errors introduced in last commit --- caddy/handler.go | 3 +-- login/backend.go | 2 +- login/handler.go | 4 ++-- login/handler_test.go | 4 ++-- login/provider.go | 4 ++-- login/simple_backend.go | 2 +- oauth2/manager.go | 6 +++--- oauth2/oauth.go | 6 +++--- oauth2/provider.go | 6 +++--- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/caddy/handler.go b/caddy/handler.go index ca3745b..0941a7a 100644 --- a/caddy/handler.go +++ b/caddy/handler.go @@ -27,7 +27,6 @@ func (h *CaddyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, e if strings.HasPrefix(r.URL.Path, h.config.LoginPath) { h.loginHandler.ServeHTTP(w, r) return 0, nil - } else { - return h.next.ServeHTTP(w, r) } + return h.next.ServeHTTP(w, r) } diff --git a/login/backend.go b/login/backend.go index 2efc541..f68e453 100644 --- a/login/backend.go +++ b/login/backend.go @@ -8,6 +8,6 @@ type Backend interface { // Authenticate checks the username/password against the backend. // On success it returns true and a UserInfo object which has at least the username set. // If the credentials do not match, false is returned. - // The error parameter is nil, unless a communication error with the backend occured. + // The error parameter is nil, unless a communication error with the backend occurred. Authenticate(username, password string) (bool, model.UserInfo, error) } diff --git a/login/handler.go b/login/handler.go index 6f23a0e..d90ceed 100644 --- a/login/handler.go +++ b/login/handler.go @@ -90,7 +90,7 @@ func (h *Handler) handleOauth(w http.ResponseWriter, r *http.Request) { if authenticated { logging.Application(r.Header). - WithField("username", userInfo.Sub).Info("sucessfully authenticated") + WithField("username", userInfo.Sub).Info("successfully authenticated") h.respondAuthenticated(w, r, userInfo) return } @@ -153,7 +153,7 @@ func (h *Handler) handleLogin(w http.ResponseWriter, r *http.Request) { if authenticated { logging.Application(r.Header). - WithField("username", username).Info("sucessfully authenticated") + WithField("username", username).Info("successfully authenticated") h.respondAuthenticated(w, r, userInfo) return } diff --git a/login/handler_test.go b/login/handler_test.go index 0297042..d5ff1bc 100644 --- a/login/handler_test.go +++ b/login/handler_test.go @@ -374,9 +374,9 @@ func tokenAsMap(tokenString string) (map[string]interface{}, error) { if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid { return map[string]interface{}(claims), nil - } else { - return nil, errors.New("token not valid") } + + return nil, errors.New("token not valid") } type errorTestBackend string diff --git a/login/provider.go b/login/provider.go index c84ba57..36dadd2 100644 --- a/login/provider.go +++ b/login/provider.go @@ -19,7 +19,7 @@ func GetProvider(providerName string) (Provider, bool) { return p, exist } -// GetProvider returns the metainfo for a provider +// GetProviderDescription returns the metainfo for a provider func GetProviderDescription(providerName string) (*ProviderDescription, bool) { p, exist := providerDescription[providerName] return p, exist @@ -28,7 +28,7 @@ func GetProviderDescription(providerName string) (*ProviderDescription, bool) { // ProviderList returns the names of all registered provider func ProviderList() []string { list := make([]string, 0, len(provider)) - for k, _ := range provider { + for k := range provider { list = append(list, k) } return list diff --git a/login/simple_backend.go b/login/simple_backend.go index 2e2f1c4..978f7bb 100644 --- a/login/simple_backend.go +++ b/login/simple_backend.go @@ -27,7 +27,7 @@ func SimpleBackendFactory(config map[string]string) (Backend, error) { return NewSimpleBackend(userPassword), nil } -// Simple backend, working on a map of username password pairs +// SimpleBackend working on a map of username password pairs type SimpleBackend struct { userPassword map[string]string } diff --git a/oauth2/manager.go b/oauth2/manager.go index 99bc7cf..c8c3d0a 100644 --- a/oauth2/manager.go +++ b/oauth2/manager.go @@ -8,7 +8,7 @@ import ( "strings" ) -// The manager has the responsibility to handle the user user requests in an oauth flow. +// Manager has the responsibility to handle the user user requests in an oauth flow. // It has to pick the right configuration and start the oauth redirecting. type Manager struct { configs map[string]Config @@ -31,7 +31,7 @@ func NewManager() *Manager { // Return parameters: // startedFlow - true, if this was the initial call to start the oauth flow // authenticated - if the authentication was successful or not -// userInfo - the user info from the provider in case of a succesful authentication +// userInfo - the user info from the provider in case of a successful authentication // err - an error func (manager *Manager) Handle(w http.ResponseWriter, r *http.Request) ( startedFlow bool, @@ -84,7 +84,7 @@ func (manager *Manager) getConfigNameFromPath(path string) string { return parts[len(parts)-1] } -// Add a configuration for a provider +// AddConfig for a provider func (manager *Manager) AddConfig(providerName string, opts map[string]string) error { p, exist := GetProvider(providerName) diff --git a/oauth2/oauth.go b/oauth2/oauth.go index 72393bb..5069950 100644 --- a/oauth2/oauth.go +++ b/oauth2/oauth.go @@ -42,7 +42,7 @@ type Config struct { Provider Provider } -// Token represents the crendentials used to authorize +// TokenInfo represents the credentials used to authorize // the requests to access protected resources on the OAuth 2.0 // provider's backend. type TokenInfo struct { @@ -65,7 +65,7 @@ type JsonError struct { const stateCookieName = "oauthState" const defaultTimeout = 5 * time.Second -// Starts the flow by redirecting the user to the login provider. +// StartFlow by redirecting the user to the login provider. // A state parameter to protect against cross-site request forgery attacks is randomly generated and stored in a cookie func StartFlow(cfg Config, w http.ResponseWriter) { values := make(url.Values) @@ -88,7 +88,7 @@ func StartFlow(cfg Config, w http.ResponseWriter) { w.WriteHeader(http.StatusFound) } -// Check the authentication after coming back from the oauth flow. +// Authenticate after coming back from the oauth flow. // Verify the state parameter againt the state cookie from the request. func Authenticate(cfg Config, r *http.Request) (TokenInfo, error) { if r.FormValue("error") != "" { diff --git a/oauth2/provider.go b/oauth2/provider.go index c45c0bf..5d25e1a 100644 --- a/oauth2/provider.go +++ b/oauth2/provider.go @@ -24,7 +24,7 @@ type Provider struct { var provider = map[string]Provider{} -// Register an Oauth provider +// RegisterProvider an Oauth provider func RegisterProvider(p Provider) { provider[p.Name] = p } @@ -34,7 +34,7 @@ func UnRegisterProvider(name string) { delete(provider, name) } -// Return a provider +// GetProvider returns a provider func GetProvider(providerName string) (Provider, bool) { p, exist := provider[providerName] return p, exist @@ -43,7 +43,7 @@ func GetProvider(providerName string) (Provider, bool) { // ProviderList returns the names of all registered provider func ProviderList() []string { list := make([]string, 0, len(provider)) - for k, _ := range provider { + for k := range provider { list = append(list, k) } return list