From 7d0ddd4d77485eb28533eef3ccf1141c4ada059c Mon Sep 17 00:00:00 2001 From: LandaMm Date: Sun, 25 May 2025 16:24:52 +0200 Subject: [PATCH] feat: use config issuer for everything --- cmd/hspguard/api/api.go | 2 +- internal/auth/routes.go | 4 ++-- internal/oauth/routes.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/hspguard/api/api.go b/cmd/hspguard/api/api.go index c4fe726..8303576 100644 --- a/cmd/hspguard/api/api.go +++ b/cmd/hspguard/api/api.go @@ -55,7 +55,7 @@ func (s *APIServer) Run() error { }) router.Get("/.well-known/jwks.json", oauthHandler.WriteJWKS) - router.Get("/.well-known/openid-configuration", oauth.OpenIdConfiguration) + router.Get("/.well-known/openid-configuration", oauthHandler.OpenIdConfiguration) router.Get("/*", func(w http.ResponseWriter, r *http.Request) { path := "./dist" + r.URL.Path diff --git a/internal/auth/routes.go b/internal/auth/routes.go index 1f1f617..56f849b 100644 --- a/internal/auth/routes.go +++ b/internal/auth/routes.go @@ -93,7 +93,7 @@ func (h *AuthHandler) login(w http.ResponseWriter, r *http.Request) { UserEmail: user.Email, IsAdmin: user.IsAdmin, RegisteredClaims: jwt.RegisteredClaims{ - Issuer: "hspguard", + Issuer: h.cfg.Jwt.Issuer, Subject: user.ID.String(), IssuedAt: jwt.NewNumericDate(time.Now()), ExpiresAt: jwt.NewNumericDate(time.Now().Add(15 * time.Minute)), @@ -110,7 +110,7 @@ func (h *AuthHandler) login(w http.ResponseWriter, r *http.Request) { UserEmail: user.Email, IsAdmin: user.IsAdmin, RegisteredClaims: jwt.RegisteredClaims{ - Issuer: "hspguard", + Issuer: h.cfg.Jwt.Issuer, Subject: user.ID.String(), IssuedAt: jwt.NewNumericDate(time.Now()), ExpiresAt: jwt.NewNumericDate(time.Now().Add(30 * 24 * time.Hour)), diff --git a/internal/oauth/routes.go b/internal/oauth/routes.go index 24afd82..d287816 100644 --- a/internal/oauth/routes.go +++ b/internal/oauth/routes.go @@ -64,7 +64,7 @@ func (h *OAuthHandler) WriteJWKS(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(jwks) } -func OpenIdConfiguration(w http.ResponseWriter, r *http.Request) { +func (h *OAuthHandler) OpenIdConfiguration(w http.ResponseWriter, r *http.Request) { type Response struct { TokenEndpoint string `json:"token_endpoint"` AuthorizationEndpoint string `json:"authorization_endpoint"` @@ -80,7 +80,7 @@ func OpenIdConfiguration(w http.ResponseWriter, r *http.Request) { TokenEndpoint: "https://cb5f-2a00-10-5b00-c801-e955-5c68-63d0-b777.ngrok-free.app/api/v1/oauth/token", AuthorizationEndpoint: "https://cb5f-2a00-10-5b00-c801-e955-5c68-63d0-b777.ngrok-free.app/authorize", JwksURI: "https://cb5f-2a00-10-5b00-c801-e955-5c68-63d0-b777.ngrok-free.app/.well-known/jwks.json", - Issuer: "https://cb5f-2a00-10-5b00-c801-e955-5c68-63d0-b777.ngrok-free.app", + Issuer: h.cfg.Jwt.Issuer, EndSessionEndpoint: "https://cb5f-2a00-10-5b00-c801-e955-5c68-63d0-b777.ngrok-free.app/api/v1/oauth/logout", }); err != nil { web.Error(w, "failed to encode response", http.StatusInternalServerError)