diff --git a/.env b/.env new file mode 100644 index 0000000..1d87537 --- /dev/null +++ b/.env @@ -0,0 +1,20 @@ +DATABASE_URL=postgres://localhost:5432/lakhansamani +DATABASE_TYPE=postgres +COOKIE_NAME=authorizer +ENV=development +FORGOT_PASSWORD_URI=reset-password +FRONTEND_URL=http://localhost:1234 +GITHUB_CLIENT_ID=Iv1.be6b1b73c67b5493 +GITHUB_CLIENT_SECRET=458c5bdd6614eb1ec917a6a049dfbe625129431c +GOOGLE_CLIENT_ID=678083311263-1n0k7fmbaq4k24pd1jslboj24bjmjub7.apps.googleusercontent.com +GOOGLE_CLIENT_SECRET=oxmxasg70lHWp71xqzEte5wv +JWT_SECRET=randome123 +JWT_TYPE=HS256 +SENDER_EMAIL=abhay.m.samani@gmail.com +SENDER_PASSWORD="bhySmn@q1w2e3#" +AUTHORIZER_URL=http://localhost:8080 +SMTP_HOST=smtp.gmail.com +SMTP_PORT=587 +ADMIN_SECRET=admin +ENV=production +DISABLE_EMAIL_VERICATION=true \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b23c462 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +DEFAULT_VERSION=0.1.0-local +VERSION := $(or $(VERSION),$(DEFAULT_VERSION)) + +cmd: + cd server && go build -ldflags "-w -X main.Version=$(VERSION)" -o '../build/server' +clean: + rm -rf build \ No newline at end of file diff --git a/build/server b/build/server new file mode 100755 index 0000000..b51f108 Binary files /dev/null and b/build/server differ diff --git a/server/Makefile b/server/Makefile deleted file mode 100644 index f7359dd..0000000 --- a/server/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -DEFAULT_VERSION=0.1.0-local -VERSION := $(or $(VERSION),$(DEFAULT_VERSION)) - -cmd: - go build -ldflags "-w -X main.Version=$(VERSION)" -clean: - rm -rf server \ No newline at end of file diff --git a/server/constants/constants.go b/server/constants/constants.go index 14e53be..41fafc2 100644 --- a/server/constants/constants.go +++ b/server/constants/constants.go @@ -14,7 +14,7 @@ var ( JWT_SECRET = "" ALLOWED_ORIGINS = []string{} ALLOWED_CALLBACK_URLS = []string{} - AUTHORIZER_DOMAIN = "" + AUTHORIZER_URL = "" PORT = "8080" REDIS_URL = "" IS_PROD = false diff --git a/server/env.go b/server/env.go index 7ce858c..99271af 100644 --- a/server/env.go +++ b/server/env.go @@ -17,7 +17,7 @@ var Version string func ParseArgs() { dbURL := flag.String("database_url", "", "Database connection string") dbType := flag.String("databse_type", "", "Database type, possible values are postgres,mysql,sqlit") - authroizerDomain := flag.String("authorizer_domain", "", "Domain name for authorizer instance, eg: https://xyz.herokuapp.com") + authorizerURL := flag.String("AUTHORIZER_URL", "", "URL for authorizer instance, eg: https://xyz.herokuapp.com") flag.Parse() if *dbURL != "" { constants.DATABASE_URL = *dbURL @@ -27,8 +27,8 @@ func ParseArgs() { constants.DATABASE_TYPE = *dbType } - if *authroizerDomain != "" { - constants.AUTHORIZER_DOMAIN = *authroizerDomain + if *authorizerURL != "" { + constants.AUTHORIZER_URL = *authorizerURL } } @@ -51,7 +51,7 @@ func InitEnv() { constants.SENDER_PASSWORD = os.Getenv("SENDER_PASSWORD") constants.JWT_SECRET = os.Getenv("JWT_SECRET") constants.JWT_TYPE = os.Getenv("JWT_TYPE") - constants.AUTHORIZER_DOMAIN = strings.TrimSuffix(os.Getenv("AUTHORIZER_DOMAIN"), "/") + constants.AUTHORIZER_URL = strings.TrimSuffix(os.Getenv("AUTHORIZER_URL"), "/") constants.PORT = os.Getenv("PORT") constants.REDIS_URL = os.Getenv("REDIS_URL") constants.COOKIE_NAME = os.Getenv("COOKIE_NAME") @@ -83,23 +83,31 @@ func InitEnv() { constants.IS_PROD = false } - allowedOrigins := strings.Split(os.Getenv("ALLOWED_ORIGINS"), ",") - for i, val := range allowedOrigins { - allowedOrigins[i] = strings.TrimSpace(val) + allowedOriginsSplit := strings.Split(os.Getenv("ALLOWED_ORIGINS"), ",") + allowedOrigins := []string{} + for _, val := range allowedOriginsSplit { + trimVal := strings.TrimSpace(val) + if trimVal != "" { + allowedOrigins = append(allowedOrigins, trimVal) + } } if len(allowedOrigins) == 0 { allowedOrigins = []string{"*"} } constants.ALLOWED_ORIGINS = allowedOrigins - allowedCallback := strings.Split(os.Getenv("ALLOWED_CALLBACK_URLS"), ",") - for i, val := range allowedOrigins { - allowedCallback[i] = strings.TrimSpace(val) + allowedCallbackSplit := strings.Split(os.Getenv("ALLOWED_CALLBACK_URLS"), ",") + allowedCallbacks := []string{} + for _, val := range allowedCallbackSplit { + trimVal := strings.TrimSpace(val) + if trimVal != "" { + allowedCallbacks = append(allowedCallbacks, trimVal) + } } - if len(allowedCallback) == 0 { - allowedCallback = []string{"*"} + if len(allowedCallbackSplit) == 0 { + allowedCallbackSplit = []string{"*"} } - constants.ALLOWED_CALLBACK_URLS = allowedCallback + constants.ALLOWED_CALLBACK_URLS = allowedCallbackSplit ParseArgs() if constants.DATABASE_URL == "" { diff --git a/server/handlers/app.go b/server/handlers/app.go index 36973b9..2f59f9d 100644 --- a/server/handlers/app.go +++ b/server/handlers/app.go @@ -22,8 +22,8 @@ func AppHandler() gin.HandlerFunc { } c.HTML(http.StatusOK, "app.tmpl", gin.H{ "data": map[string]string{ - "domain": c.Request.Host, - "redirect_url": "http://localhost:8080/app", + "authorizerURL": c.Request.Host, + "redirect_url": "http://localhost:8080/app", }, }) } diff --git a/server/handlers/graphql.go b/server/handlers/graphql.go index a6b2348..e98b257 100644 --- a/server/handlers/graphql.go +++ b/server/handlers/graphql.go @@ -15,8 +15,8 @@ func GraphqlHandler() gin.HandlerFunc { h := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}})) return func(c *gin.Context) { - if constants.AUTHORIZER_DOMAIN == "" { - constants.AUTHORIZER_DOMAIN = "https://" + c.Request.Host + if constants.AUTHORIZER_URL == "" { + constants.AUTHORIZER_URL = "https://" + c.Request.Host } h.ServeHTTP(c.Writer, c.Request) } diff --git a/server/main.go b/server/main.go index 56da6b8..9c5ebe8 100644 --- a/server/main.go +++ b/server/main.go @@ -50,11 +50,11 @@ func main() { r.GET("/", handlers.PlaygroundHandler()) r.POST("/graphql", handlers.GraphqlHandler()) r.GET("/verify_email", handlers.VerifyEmailHandler()) - r.GET("/login/:oauth_provider", handlers.OAuthLoginHandler()) - r.GET("/callback/:oauth_provider", handlers.OAuthCallbackHandler()) + r.GET("/oauth_login/:oauth_provider", handlers.OAuthLoginHandler()) + r.GET("/oauth_callback/:oauth_provider", handlers.OAuthCallbackHandler()) // login wall app related routes - r.Static("/app/build", "../app/build") + r.Static("/app/build", "app/build") r.LoadHTMLGlob("templates/*") r.GET("/app", handlers.AppHandler()) diff --git a/server/oauth/oauth.go b/server/oauth/oauth.go index a9e1f2a..7c67933 100644 --- a/server/oauth/oauth.go +++ b/server/oauth/oauth.go @@ -20,7 +20,7 @@ func InitOAuth() { OAuthProvider.GoogleConfig = &oauth2.Config{ ClientID: constants.GOOGLE_CLIENT_ID, ClientSecret: constants.GOOGLE_CLIENT_SECRET, - RedirectURL: constants.AUTHORIZER_DOMAIN + "/callback/google", + RedirectURL: constants.AUTHORIZER_URL + "/oauth_callback/google", Endpoint: googleOAuth2.Endpoint, Scopes: []string{"https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile"}, } @@ -29,7 +29,7 @@ func InitOAuth() { OAuthProvider.GithubConfig = &oauth2.Config{ ClientID: constants.GITHUB_CLIENT_ID, ClientSecret: constants.GITHUB_CLIENT_SECRET, - RedirectURL: constants.AUTHORIZER_DOMAIN + "/callback/github", + RedirectURL: constants.AUTHORIZER_URL + "/oauth_callback/github", Endpoint: githubOAuth2.Endpoint, } } @@ -37,7 +37,7 @@ func InitOAuth() { // OAuthProvider.FacebookConfig = &oauth2.Config{ // ClientID: constants.FACEBOOK_CLIENT_ID, // ClientSecret: constants.FACEBOOK_CLIENT_SECRET, - // RedirectURL: "/callback/facebook/", + // RedirectURL: "/oauth_callback/facebook/", // Endpoint: facebookOAuth2.Endpoint, // } // } diff --git a/server/utils/email.go b/server/utils/email.go index e429a00..c5d116b 100644 --- a/server/utils/email.go +++ b/server/utils/email.go @@ -26,7 +26,7 @@ func SendVerificationMail(toEmail, token string) error { Click here to verify - `, constants.AUTHORIZER_DOMAIN+"/verify_email"+"?token="+token) + `, constants.AUTHORIZER_URL+"/verify_email"+"?token="+token) bodyMessage := sender.WriteHTMLEmail(Receiver, Subject, message) return sender.SendMail(Receiver, Subject, bodyMessage) diff --git a/server/templates/app.tmpl b/templates/app.tmpl similarity index 100% rename from server/templates/app.tmpl rename to templates/app.tmpl