mirror of
https://github.com/wahyd4/loginsrv.git
synced 2026-08-09 04:46:29 +10:00
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
This commit is contained in:
+1
-2
@@ -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)
|
||||
}
|
||||
|
||||
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
|
||||
+3
-3
@@ -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") != "" {
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user