neko/internal/session/auth.go
2020-11-27 19:59:54 +01:00

27 lines
480 B
Go

package session
import (
"fmt"
"net/http"
"demodesk/neko/internal/types"
)
func (manager *SessionManagerCtx) Authenticate(r *http.Request) (types.Session, error) {
id, secret, ok := r.BasicAuth()
if !ok {
return nil, fmt.Errorf("no authentication provided")
}
session, ok := manager.Get(id)
if !ok {
return nil, fmt.Errorf("member not found")
}
if !session.VerifySecret(secret) {
return nil, fmt.Errorf("invalid password provided")
}
return session, nil
}