loginsrv

Unnamed repository; edit this file 'description' to name the repository.
git clone git@jamesshield.xyz:repos/loginsrv.git
Log | Files | Refs | README | LICENSE

commit 69e9dc946b49ee9790dfa1e469139e47e4443d4d
parent 478939fc7117b4e43b8fb901ca06d84f57c15efe
Author: Sebastian Mancke <s.mancke@tarent.de>
Date:   Sat, 13 May 2017 11:34:50 +0200

Merge pull request #17 from magikstm/master

Correct some mispellings and minor cleanup
Diffstat:
Mcaddy/handler.go | 3+--
Mlogin/backend.go | 2+-
Mlogin/handler.go | 4++--
Mlogin/handler_test.go | 4++--
Mlogin/provider.go | 4++--
Mlogin/simple_backend.go | 2+-
Moauth2/manager.go | 6+++---
Moauth2/oauth.go | 6+++---
Moauth2/provider.go | 6+++---
9 files changed, 18 insertions(+), 19 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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