feat: oauth routes

This commit is contained in:
2025-05-24 20:58:04 +02:00
parent d64c8479f8
commit d423d9ba62

49
internal/oauth/routes.go Normal file
View File

@ -0,0 +1,49 @@
package oauth
import (
"encoding/json"
"log"
"net/http"
"gitea.local/admin/hspguard/internal/web"
"github.com/go-chi/chi/v5"
)
type OAuthHandler struct{}
func NewOAuthHandler() *OAuthHandler {
return &OAuthHandler{}
}
func (h *OAuthHandler) RegisterRoutes(r chi.Router) {
r.Get("/oauth/authorize", h.authorizeEndpoint)
r.Get("/oauth/token", h.tokenEndpoint)
}
func (h *OAuthHandler) tokenEndpoint(w http.ResponseWriter, r *http.Request) {
log.Println("[OAUTH] New request to token endpoint")
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
}
func (h *OAuthHandler) authorizeEndpoint(w http.ResponseWriter, r *http.Request) {
log.Println("[OAUTH] New request to authorize endpoint")
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
}
func (h *OAuthHandler) Metadata(w http.ResponseWriter, r *http.Request) {
type Response struct {
TokenEndpoint string `json:"token_endpoint"`
AuthEndpoint string `json:"authorization_endpoint"`
}
encoder := json.NewEncoder(w)
if err := encoder.Encode(Response{
TokenEndpoint: "http://192.168.178.21:3001/api/v1/oauth/token",
AuthEndpoint: "http://192.168.178.21:5173/authorize",
}); err != nil {
web.Error(w, "failed to encode response", http.StatusInternalServerError)
}
}