refactor: change cookie name
This commit is contained in:
@@ -160,7 +160,7 @@ func (oauth *OauthRulerMiddleware) callbackHandler(w http.ResponseWriter, r *htt
|
|||||||
}
|
}
|
||||||
// Save token to a cookie for simplicity
|
// Save token to a cookie for simplicity
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "goma.JWT",
|
Name: "goma.oauth",
|
||||||
Value: jwtToken,
|
Value: jwtToken,
|
||||||
Path: oauth.CookiePath,
|
Path: oauth.CookiePath,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -20,17 +20,15 @@ package middleware
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/jkaninda/goma-gateway/pkg/logger"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (oauth Oauth) AuthMiddleware(next http.Handler) http.Handler {
|
func (oauth Oauth) AuthMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
logger.Info("%s: %s Oauth", getRealIP(r), r.URL.Path)
|
|
||||||
oauthConf := oauth2Config(oauth)
|
oauthConf := oauth2Config(oauth)
|
||||||
// Check if the user is authenticated
|
// Check if the user is authenticated
|
||||||
token, err := r.Cookie("goma.JWT")
|
token, err := r.Cookie("goma.oauth")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If no token, redirect to OAuth provider
|
// If no token, redirect to OAuth provider
|
||||||
url := oauthConf.AuthCodeURL(oauth.State)
|
url := oauthConf.AuthCodeURL(oauth.State)
|
||||||
|
|||||||
Reference in New Issue
Block a user