repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
f33217e
parent
c37be01
author
Eric Bower
date
2024-02-02 02:31:58 +0000 UTC
feat(auth): `/key` support to check any space
1 files changed,  +8, -2
M auth/auth.go
+8, -2
 1@@ -193,6 +193,7 @@ type sishData struct {
 2 	PublicKey     string `json:"auth_key"`
 3 	Username      string `json:"user"`
 4 	RemoteAddress string `json:"remote_addr"`
 5+	Space         string `json:"space"`
 6 }
 7 
 8 func keyHandler(w http.ResponseWriter, r *http.Request) {
 9@@ -207,7 +208,12 @@ func keyHandler(w http.ResponseWriter, r *http.Request) {
10 		return
11 	}
12 
13-	client.Logger.Infof("handle key (%s, %s, %s)", data.RemoteAddress, data.Username, data.PublicKey)
14+	// backwards compat
15+	if data.Space == "" {
16+		data.Space = "tuns"
17+	}
18+
19+	client.Logger.Infof("handle key (%s, %s, %s, %s)", data.RemoteAddress, data.Username, data.Space, data.PublicKey)
20 
21 	user, err := client.Dbpool.FindUserForKey(data.Username, data.PublicKey)
22 	if err != nil {
23@@ -216,7 +222,7 @@ func keyHandler(w http.ResponseWriter, r *http.Request) {
24 		return
25 	}
26 
27-	if !client.Dbpool.HasFeatureForUser(user.ID, "tuns") {
28+	if !client.Dbpool.HasFeatureForUser(user.ID, data.Space) {
29 		w.WriteHeader(http.StatusUnauthorized)
30 		return
31 	}