#73 setup password hashing with argin2id and update some infra
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Failing after 59s
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Failing after 59s
This commit is contained in:
42
api/utils/auth.go
Normal file
42
api/utils/auth.go
Normal 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)
|
||||
// }
|
||||
Reference in New Issue
Block a user