fix: handle signup token
This commit is contained in:
parent
78b5b33a3d
commit
d1973c1f8f
|
@ -8,7 +8,7 @@ ENV VERSION="${VERSION}"
|
||||||
RUN apk add build-base &&\
|
RUN apk add build-base &&\
|
||||||
cd server && \
|
cd server && \
|
||||||
go mod download && \
|
go mod download && \
|
||||||
go build && \
|
make clean && make && \
|
||||||
chmod 777 server
|
chmod 777 server
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
|
@ -93,12 +93,6 @@ func InitEnv() {
|
||||||
panic("Database type is required")
|
panic("Database type is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if constants.AUTHORIZER_DOMAIN == "" {
|
|
||||||
panic("Authroizer domain is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("=> Authorizer domain=", constants.AUTHORIZER_DOMAIN)
|
|
||||||
|
|
||||||
if constants.JWT_TYPE == "" {
|
if constants.JWT_TYPE == "" {
|
||||||
constants.JWT_TYPE = "HS256"
|
constants.JWT_TYPE = "HS256"
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/99designs/gqlgen/graphql/handler"
|
"github.com/99designs/gqlgen/graphql/handler"
|
||||||
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
"github.com/authorizerdev/authorizer/server/graph"
|
"github.com/authorizerdev/authorizer/server/graph"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/generated"
|
"github.com/authorizerdev/authorizer/server/graph/generated"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -14,6 +15,9 @@ func GraphqlHandler() gin.HandlerFunc {
|
||||||
h := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
|
h := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
|
||||||
|
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
if constants.AUTHORIZER_DOMAIN == "" {
|
||||||
|
constants.AUTHORIZER_DOMAIN = "https://" + c.Request.Host
|
||||||
|
}
|
||||||
h.ServeHTTP(c.Writer, c.Request)
|
h.ServeHTTP(c.Writer, c.Request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func Signup(ctx context.Context, params model.SignUpInput) (*model.AuthResponse,
|
||||||
if constants.DISABLE_EMAIL_VERICATION == "true" {
|
if constants.DISABLE_EMAIL_VERICATION == "true" {
|
||||||
user.EmailVerifiedAt = time.Now().Unix()
|
user.EmailVerifiedAt = time.Now().Unix()
|
||||||
}
|
}
|
||||||
_, err = db.Mgr.SaveUser(user)
|
user, err = db.Mgr.SaveUser(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
"github.com/authorizerdev/authorizer/server/constants"
|
||||||
|
@ -11,8 +12,10 @@ func SetCookie(gc *gin.Context, token string) {
|
||||||
secure := true
|
secure := true
|
||||||
httpOnly := true
|
httpOnly := true
|
||||||
|
|
||||||
|
host := GetDomainName(gc.Request.Host)
|
||||||
|
log.Println("=> host", host)
|
||||||
gc.SetSameSite(http.SameSiteNoneMode)
|
gc.SetSameSite(http.SameSiteNoneMode)
|
||||||
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", gc.Request.Host, secure, httpOnly)
|
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", host, secure, httpOnly)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCookie(gc *gin.Context) (string, error) {
|
func GetCookie(gc *gin.Context) (string, error) {
|
||||||
|
@ -32,7 +35,7 @@ func DeleteCookie(gc *gin.Context) {
|
||||||
secure = false
|
secure = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host := GetDomainName(gc.Request.Host)
|
||||||
gc.SetSameSite(http.SameSiteNoneMode)
|
gc.SetSameSite(http.SameSiteNoneMode)
|
||||||
|
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", host, secure, httpOnly)
|
||||||
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", gc.Request.Host, secure, httpOnly)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,36 +2,36 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/constants"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDomainName() string {
|
// function to get hostname
|
||||||
u, err := url.Parse(constants.FRONTEND_URL)
|
func GetDomainName(auth_url string) string {
|
||||||
|
u, err := url.Parse("//" + auth_url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return `localhost`
|
return `localhost`
|
||||||
}
|
}
|
||||||
|
|
||||||
host := u.Hostname()
|
host := u.Hostname()
|
||||||
hostParts := strings.Split(host, ".")
|
|
||||||
hostPartsLen := len(hostParts)
|
|
||||||
|
|
||||||
if hostPartsLen == 1 {
|
// code to get root domain in case of sub-domains
|
||||||
return host
|
// hostParts := strings.Split(host, ".")
|
||||||
}
|
// hostPartsLen := len(hostParts)
|
||||||
|
|
||||||
if hostPartsLen == 2 {
|
// if hostPartsLen == 1 {
|
||||||
if hostParts[0] == "www" {
|
// return host
|
||||||
return hostParts[1]
|
// }
|
||||||
} else {
|
|
||||||
return host
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if hostPartsLen > 2 {
|
// if hostPartsLen == 2 {
|
||||||
return strings.Join(hostParts[hostPartsLen-2:], ".")
|
// if hostParts[0] == "www" {
|
||||||
}
|
// return hostParts[1]
|
||||||
|
// } else {
|
||||||
|
// return host
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if hostPartsLen > 2 {
|
||||||
|
// return strings.Join(hostParts[hostPartsLen-2:], ".")
|
||||||
|
// }
|
||||||
|
|
||||||
return host
|
return host
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user