diff --git a/.env.dist b/.env.dist index 88c6736..71173c3 100644 --- a/.env.dist +++ b/.env.dist @@ -1,11 +1,16 @@ ## Server -web_adress=":3001" +jwt_web_adress=":3001" ## Postgres -db_user="jwtserver" -db_pass="jwtserver" -db_name="jwtserver" -db_host="localhost" +jwt_db_user="jwtserver" +jwt_db_pass="jwtserver" +jwt_db_name="jwtserver" +jwt_db_host="localhost" ## JWT -token_password="NotSoSecretJwtSecretPassword" \ No newline at end of file +jwt_subject="factory" +jwt_audience="risotto" +jwt_access_token_password="NotSoSecretJwtAccessSecretPassword" +jwt_refresh_token_password="NotSoSecretJwtRefreshSecretPassword" +jwt_access_expiration=30 ## in seconds +jwt_refresh_expiration=2 ## in minutes \ No newline at end of file diff --git a/cmd/jwtserver/main.go b/cmd/jwtserver/main.go index 913568f..0c57894 100644 --- a/cmd/jwtserver/main.go +++ b/cmd/jwtserver/main.go @@ -23,7 +23,7 @@ func init() { if e != nil { fmt.Print(e) } - confWebadress = os.Getenv("web_adress") + confWebadress = os.Getenv("jwt_web_adress") } func main() { diff --git a/middleware/accounts.go b/middleware/accounts.go index 7e6746a..6d56422 100644 --- a/middleware/accounts.go +++ b/middleware/accounts.go @@ -34,16 +34,16 @@ func init() { fmt.Print(e) } var err error - accessExpires, err = strconv.Atoi(os.Getenv("access_expiration")) + accessExpires, err = strconv.Atoi(os.Getenv("jwt_access_expiration")) if err != nil { panic(err) } - refreshExpiration, err = strconv.Atoi(os.Getenv("access_expiration")) + refreshExpiration, err = strconv.Atoi(os.Getenv("jwt_access_expiration")) if err != nil { panic(err) } - audience = os.Getenv("audience") - subject = os.Getenv("subject") + audience = os.Getenv("jwt_audience") + subject = os.Getenv("jwt_subject") } // TokenDetails struct @@ -151,7 +151,7 @@ func (account *Account) GenerateTokenPair() (*TokenDetails, error) { }, } token := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), tk) - tokenString, err := token.SignedString([]byte(os.Getenv("access_token_password"))) + tokenString, err := token.SignedString([]byte(os.Getenv("jwt_access_token_password"))) if err != nil { return nil, err } @@ -164,7 +164,7 @@ func (account *Account) GenerateTokenPair() (*TokenDetails, error) { }, } refreshtoken := jwt.NewWithClaims(jwt.GetSigningMethod("HS256"), reftk) - refreshtokenString, err := refreshtoken.SignedString([]byte(os.Getenv("refresh_token_password"))) + refreshtokenString, err := refreshtoken.SignedString([]byte(os.Getenv("jwt_refresh_token_password"))) if err != nil { return nil, err } diff --git a/middleware/postgres.go b/middleware/postgres.go index d7c76ea..35edb52 100644 --- a/middleware/postgres.go +++ b/middleware/postgres.go @@ -19,15 +19,15 @@ func init() { fmt.Print(e) } - username := os.Getenv("db_user") - password := os.Getenv("db_pass") - dbName := os.Getenv("db_name") - dbHost := os.Getenv("db_host") + username := os.Getenv("jwt_db_user") + password := os.Getenv("jwt_db_pass") + dbName := os.Getenv("jwt_db_name") + dbHost := os.Getenv("jwt_db_host") - dbUri := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable password=%s", dbHost, username, dbName, password) //Build connection string - fmt.Println(dbUri) + dbURI := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable password=%s", dbHost, username, dbName, password) //Build connection string + fmt.Println(dbURI) - conn, err := gorm.Open("postgres", dbUri) + conn, err := gorm.Open("postgres", dbURI) if err != nil { fmt.Print(err) } @@ -36,7 +36,7 @@ func init() { db.Debug().AutoMigrate(&Account{}) //Database migration } -//returns a handle to the DB object +//GetDB returns a handle to the DB object func GetDB() *gorm.DB { return db }