refactor: change cookie name

This commit is contained in:
2024-11-08 18:19:26 +01:00
parent bd20895306
commit 2012ac69a3
2 changed files with 2 additions and 4 deletions

View File

@@ -160,7 +160,7 @@ func (oauth *OauthRulerMiddleware) callbackHandler(w http.ResponseWriter, r *htt
}
// Save token to a cookie for simplicity
http.SetCookie(w, &http.Cookie{
Name: "goma.JWT",
Name: "goma.oauth",
Value: jwtToken,
Path: oauth.CookiePath,
})

View File

@@ -20,17 +20,15 @@ package middleware
import (
"fmt"
"github.com/golang-jwt/jwt"
"github.com/jkaninda/goma-gateway/pkg/logger"
"net/http"
"time"
)
func (oauth Oauth) AuthMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logger.Info("%s: %s Oauth", getRealIP(r), r.URL.Path)
oauthConf := oauth2Config(oauth)
// Check if the user is authenticated
token, err := r.Cookie("goma.JWT")
token, err := r.Cookie("goma.oauth")
if err != nil {
// If no token, redirect to OAuth provider
url := oauthConf.AuthCodeURL(oauth.State)