Browse Source

update project authz to account for token

Alexander Belanger 5 years ago
parent
commit
290ce60fbb
1 changed files with 16 additions and 11 deletions
  1. 16 11
      server/router/middleware/auth.go

+ 16 - 11
server/router/middleware/auth.go

@@ -187,23 +187,28 @@ func (auth *Auth) DoesUserHaveProjectAccess(
 		// first check for token
 		// first check for token
 		tok := auth.getTokenFromRequest(r)
 		tok := auth.getTokenFromRequest(r)
 
 
+		var userID uint
+
 		if tok != nil && tok.ProjectID == uint(projID) {
 		if tok != nil && tok.ProjectID == uint(projID) {
 			next.ServeHTTP(w, r)
 			next.ServeHTTP(w, r)
 			return
 			return
-		}
-
-		session, err := auth.store.Get(r, auth.cookieName)
+		} else if tok != nil {
+			userID = tok.IBy
+		} else {
+			session, err := auth.store.Get(r, auth.cookieName)
 
 
-		if err != nil {
-			http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
-			return
-		}
+			if err != nil {
+				http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
+				return
+			}
 
 
-		userID, ok := session.Values["user_id"].(uint)
+			sessionUserID, ok := session.Values["user_id"]
+			userID = sessionUserID.(uint)
 
 
-		if !ok {
-			http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
-			return
+			if !ok {
+				http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
+				return
+			}
 		}
 		}
 
 
 		// get the project
 		// get the project