feat: signout endpoitn
This commit is contained in:
40
internal/auth/signout.go
Normal file
40
internal/auth/signout.go
Normal file
@ -0,0 +1,40 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"gitea.local/admin/hspguard/internal/util"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func (h *AuthHandler) signOut(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("{\"status\": \"ok\"}"))
|
||||
}()
|
||||
|
||||
jti, ok := util.GetRequestJTI(r.Context())
|
||||
if !ok {
|
||||
log.Println("WARN: No JTI found in request")
|
||||
return
|
||||
}
|
||||
|
||||
jtiId, err := uuid.Parse(jti)
|
||||
if err != nil {
|
||||
log.Printf("ERR: Failed to parse jti '%s' as v4 uuid: %v\n", jti, err)
|
||||
return
|
||||
}
|
||||
|
||||
session, err := h.repo.GetUserSessionByAccessJTI(r.Context(), &jtiId)
|
||||
if err != nil {
|
||||
log.Printf("WARN: Could not find session by jti id '%s': %v\n", jtiId.String(), err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.repo.RevokeUserSession(r.Context(), session.ID); err != nil {
|
||||
log.Printf("ERR: Failed to revoke session with '%s' id: %v\n", session.ID.String(), err)
|
||||
} else {
|
||||
log.Printf("INFO: Revoked session with jti = '%s' and session id = '%s'\n", jtiId.String(), session.ID.String())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user