forked from authentricity/authentricity
authz: add ability to require specific group
This commit is contained in:
parent
20f0f6c047
commit
15eece9f46
|
@ -5,7 +5,7 @@ buildGoModule rec {
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
vendorSha256 = "sha256-fskmRb9zXLGkL0sJ4P1/sNjzZkUZhAguOCSN1etQ2tU=";
|
vendorSha256 = "sha256-yJHwZLNlZHB9Jo+Xo9c1wy00faiY4oURyYbhNx3yMK8=";
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
description = "Simple distributed authentication system";
|
description = "Simple distributed authentication system";
|
||||||
|
|
|
@ -13,17 +13,40 @@ func (s *Service) authGet(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := w.Header()
|
if err := r.ParseForm(); err != nil {
|
||||||
headers.Add("X-Webauth-UserID", tok.Subject())
|
zap.S().Errorf("Error parsing request parameters: %v", err)
|
||||||
headers.Add("X-Webauth-User", tok.PreferredUsername())
|
s.renderBadRequest(w, r)
|
||||||
headers.Add("X-Webauth-Email", tok.Email())
|
return
|
||||||
|
}
|
||||||
|
|
||||||
groups, err := getTokenGroupIDs(tok)
|
groups, err := getTokenGroupIDs(tok)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zap.S().Errorf("Error getting groups from token: %v", err)
|
zap.S().Errorf("Error getting groups from token: %v", err)
|
||||||
} else {
|
s.renderError(w)
|
||||||
headers["X-Webauth-Groups"] = groups
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if reqGroup := r.FormValue("required_group"); reqGroup != "" {
|
||||||
|
found := false
|
||||||
|
for _, g := range groups {
|
||||||
|
if g == reqGroup {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
zap.S().Debug("User %s doesn't have required group %s", tok.Subject(), reqGroup)
|
||||||
|
s.renderForbidden(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
headers := w.Header()
|
||||||
|
headers.Add("X-Webauth-UserID", tok.Subject())
|
||||||
|
headers.Add("X-Webauth-User", tok.PreferredUsername())
|
||||||
|
headers.Add("X-Webauth-Email", tok.Email())
|
||||||
|
headers["X-Webauth-Groups"] = groups
|
||||||
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue