Revert "too much effort into the garbage"

This reverts commit a2e84379a9.
This commit is contained in:
bel
2024-03-10 10:41:35 -06:00
parent a2e84379a9
commit 6ae4b401b1
5 changed files with 58 additions and 128 deletions

View File

@@ -2,13 +2,12 @@ package server
import (
"fmt"
"net/http"
"net/url"
"strings"
"gitea.inhome.blapointe.com/local/oauth2"
"gitea.inhome.blapointe.com/local/router"
"gitea.inhome.blapointe.com/local/storage"
"net/http"
"net/url"
"strings"
"github.com/google/uuid"
)
@@ -56,9 +55,9 @@ func (s *Server) authorize(w http.ResponseWriter, r *http.Request) {
func (s *Server) genAuth(scope, user string) {
access := uuid.New().String()
token := uuid.New().String()
s.store.Set(user, []byte(access), ACCESS)
s.store.Set(user, []byte(user), ACCESS)
s.store.Set(access, []byte(user), ACCESS)
s.store.Set(scope+"."+access, []byte(token), TOKEN)
}
func (s *Server) getAccess(scope, user string) (string, bool) {
@@ -70,10 +69,7 @@ func (s *Server) getAccess(scope, user string) (string, bool) {
return string(access), err == nil
}
func (s *Server) verifyAccess(access string) error {
_, err := s.store.Get(access, ACCESS)
if err != nil {
return fmt.Errorf("access not found: %s", access)
}
return nil
func (s *Server) getToken(scope, access string) (string, bool) {
token, err := s.store.Get(scope+"."+access, TOKEN)
return string(token), err == nil
}