#73 setup password hashing with argin2id and update some infra
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Failing after 59s

This commit is contained in:
Tim
2024-08-10 00:14:38 +02:00
parent 2f1b4fc8a7
commit 0df0e7f6f9
15 changed files with 139 additions and 344 deletions

42
api/utils/auth.go Normal file
View File

@@ -0,0 +1,42 @@
package utils
import (
// "context"
"errors"
// "log"
"net/http"
)
type UserId string
func GetUserOrWriteInResponse(w http.ResponseWriter, r *http.Request) (UserId, error) {
tokenStr := r.Header.Get("Authorization")
if (tokenStr == "") || (len(tokenStr) < len("Bearer ")) {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return "", errors.New("Unauthorized")
}
tokenStr = tokenStr[len("Bearer "):]
// token, err := verifyToken(tokenStr)
// if err != nil {
// log.Println(err)
// http.Error(w, "Unauthorized", http.StatusUnauthorized)
// return "", errors.New("Unauthorized")
// }
// return UserId(token.UID), nil
return UserId("xxx"), nil
}
// func verifyToken(token string) (*auth.Token, error) {
// if app == nil {
// setup()
// }
//
// client, err := app.Auth(context.Background())
// if err != nil {
// log.Fatalf("error getting Auth client: %v\n", err)
// }
// return client.VerifyIDToken(context.Background(), token)
// }