@@ -14,6 +14,7 @@ var (
|
|||||||
JWT_SECRET = ""
|
JWT_SECRET = ""
|
||||||
ALLOWED_ORIGINS = []string{}
|
ALLOWED_ORIGINS = []string{}
|
||||||
AUTHORIZER_URL = ""
|
AUTHORIZER_URL = ""
|
||||||
|
APP_URL = ""
|
||||||
PORT = "8080"
|
PORT = "8080"
|
||||||
REDIS_URL = ""
|
REDIS_URL = ""
|
||||||
IS_PROD = false
|
IS_PROD = false
|
||||||
|
@@ -69,6 +69,6 @@ func VerifyEmailHandler() gin.HandlerFunc {
|
|||||||
db.Mgr.SaveSession(sessionData)
|
db.Mgr.SaveSession(sessionData)
|
||||||
}()
|
}()
|
||||||
utils.SetCookie(c, accessToken)
|
utils.SetCookie(c, accessToken)
|
||||||
c.Redirect(http.StatusTemporaryRedirect, claim.Host)
|
c.Redirect(http.StatusTemporaryRedirect, claim.RedirectURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,8 @@ func GinContextToContextMiddleware() gin.HandlerFunc {
|
|||||||
func CORSMiddleware() gin.HandlerFunc {
|
func CORSMiddleware() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
origin := c.Request.Header.Get("Origin")
|
origin := c.Request.Header.Get("Origin")
|
||||||
|
constants.APP_URL = origin
|
||||||
|
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
|
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
|
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
|
||||||
|
@@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/enum"
|
"github.com/authorizerdev/authorizer/server/enum"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
@@ -76,6 +77,8 @@ func VerifyEmail(ctx context.Context, params model.VerifyEmailInput) (*model.Aut
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gc.Request.Header.Set("origin", constants.APP_URL)
|
||||||
|
|
||||||
utils.SetCookie(gc, accessToken)
|
utils.SetCookie(gc, accessToken)
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
@@ -11,13 +10,11 @@ import (
|
|||||||
func SetCookie(gc *gin.Context, token string) {
|
func SetCookie(gc *gin.Context, token string) {
|
||||||
secure := true
|
secure := true
|
||||||
httpOnly := true
|
httpOnly := true
|
||||||
origin := gc.Request.Header.Get("Origin")
|
origin := constants.APP_URL
|
||||||
|
|
||||||
host := GetHostName(constants.AUTHORIZER_URL)
|
host := GetHostName(constants.AUTHORIZER_URL)
|
||||||
originHost := GetHostName(origin)
|
originHost := GetHostName(origin)
|
||||||
|
|
||||||
log.Println("=> cookie host", host, origin)
|
|
||||||
|
|
||||||
gc.SetSameSite(http.SameSiteNoneMode)
|
gc.SetSameSite(http.SameSiteNoneMode)
|
||||||
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", host, secure, httpOnly)
|
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", host, secure, httpOnly)
|
||||||
gc.SetCookie(constants.COOKIE_NAME+"-client", token, 3600, "/", originHost, secure, httpOnly)
|
gc.SetCookie(constants.COOKIE_NAME+"-client", token, 3600, "/", originHost, secure, httpOnly)
|
||||||
@@ -35,7 +32,7 @@ func GetCookie(gc *gin.Context) (string, error) {
|
|||||||
func DeleteCookie(gc *gin.Context) {
|
func DeleteCookie(gc *gin.Context) {
|
||||||
secure := true
|
secure := true
|
||||||
httpOnly := true
|
httpOnly := true
|
||||||
origin := gc.Request.Header.Get("Origin")
|
origin := constants.APP_URL
|
||||||
|
|
||||||
if !constants.IS_PROD {
|
if !constants.IS_PROD {
|
||||||
secure = false
|
secure = false
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// function to get hostname
|
// GetHostName function to get hostname
|
||||||
func GetHostName(auth_url string) string {
|
func GetHostName(auth_url string) string {
|
||||||
u, err := url.Parse(auth_url)
|
u, err := url.Parse(auth_url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -8,8 +8,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UserInfo struct {
|
type UserInfo struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
|
RedirectURL string `json:"redirect_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomClaim struct {
|
type CustomClaim struct {
|
||||||
@@ -28,7 +29,7 @@ func CreateVerificationToken(email string, tokenType string) (string, error) {
|
|||||||
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
ExpiresAt: time.Now().Add(time.Minute * 30).Unix(),
|
||||||
},
|
},
|
||||||
tokenType,
|
tokenType,
|
||||||
UserInfo{Email: email, Host: constants.AUTHORIZER_URL},
|
UserInfo{Email: email, Host: constants.AUTHORIZER_URL, RedirectURL: constants.APP_URL},
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.SignedString([]byte(constants.JWT_SECRET))
|
return t.SignedString([]byte(constants.JWT_SECRET))
|
||||||
|
Reference in New Issue
Block a user