mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
add group lenth check
This commit is contained in:
parent
c2d51a2257
commit
3b58e887ed
2 changed files with 9 additions and 6 deletions
|
|
@ -90,11 +90,11 @@ type UserInfo struct {
|
|||
UserName string `json:"username"`
|
||||
}
|
||||
|
||||
func (a *Auth) Authenticate(w http.ResponseWriter, r *http.Request) []Group {
|
||||
func (a *Auth) Authenticate(w http.ResponseWriter, r *http.Request) ([]Group, error) {
|
||||
cookie, err := a.readCookie(r)
|
||||
if err != nil {
|
||||
http.Redirect(w, r, "/signin", http.StatusTemporaryRedirect)
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
if cookie.Token.Expiry.Before(time.Now().Add(a.refreshWithin)) {
|
||||
err = a.refreshToken(w, cookie)
|
||||
|
|
@ -102,11 +102,14 @@ func (a *Auth) Authenticate(w http.ResponseWriter, r *http.Request) []Group {
|
|||
//log error
|
||||
if cookie.Token.Expiry.Before(time.Now()) {
|
||||
http.Redirect(w, r, "/signin", http.StatusTemporaryRedirect)
|
||||
return nil
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return cookie.GroupMembership
|
||||
if len(cookie.GroupMembership) == 0 {
|
||||
return nil, errors.New("user is not part of any groups in identity provider")
|
||||
}
|
||||
return cookie.GroupMembership, nil
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3395,8 +3395,8 @@ func (h *Handler) handleCheckAuthentication(w http.ResponseWriter, r *http.Reque
|
|||
http.Error(w, "Trying to authenticate but authentication is off.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
groups := h.auth.Authenticate(w, r)
|
||||
if groups == nil {
|
||||
groups, err := h.auth.Authenticate(w, r)
|
||||
if groups == nil || err != nil {
|
||||
w.Header().Add("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue