Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AWS_SECRET_ACCESS_KEY=
AWS_KMS_KEY_ID=
CHECKOUT_PUBLIC_KEY=
CHECKOUT_SECRET_KEY=
CHECKOUT_ENV=sandbox
EVM_PRIVATE_KEY=
DB_NAME=string_db
DB_USERNAME=string_db
Expand Down
16 changes: 12 additions & 4 deletions api/handler/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func SetJWTCookie(c echo.Context, jwt service.JWT) error {
cookie.Value = jwt.Token
// cookie.HttpOnly = true // due the short expiration time it is not needed to be http only
cookie.Expires = jwt.ExpAt // we want the cookie to expire at the same time as the token
cookie.SameSite = http.SameSiteNoneMode
cookie.SameSite = getCookieSameSiteMode()
cookie.Path = "/" // Send cookie in every sub path request
cookie.Secure = !IsLocalEnv() // in production allow https only
c.SetCookie(cookie)
Expand All @@ -70,7 +70,7 @@ func SetRefreshTokenCookie(c echo.Context, refresh service.RefreshTokenResponse)
cookie.Value = refresh.Token
cookie.HttpOnly = true
cookie.Expires = refresh.ExpAt // we want the cookie to expire at the same time as the token
cookie.SameSite = http.SameSiteNoneMode
cookie.SameSite = getCookieSameSiteMode()
cookie.Path = "/login/" // Send cookie only in /login path request
cookie.Secure = !IsLocalEnv() // in production allow https only
c.SetCookie(cookie)
Expand Down Expand Up @@ -98,7 +98,7 @@ func DeleteAuthCookies(c echo.Context) error {
cookie.Name = "StringJWT"
cookie.Value = ""
cookie.Expires = time.Now()
cookie.SameSite = http.SameSiteLaxMode
cookie.SameSite = getCookieSameSiteMode()
cookie.Path = "/" // Send cookie in every sub path request
cookie.Secure = !IsLocalEnv()
c.SetCookie(cookie)
Expand All @@ -107,7 +107,7 @@ func DeleteAuthCookies(c echo.Context) error {
cookie.Name = "refresh_token"
cookie.Value = ""
cookie.Expires = time.Now()
cookie.SameSite = http.SameSiteNoneMode
cookie.SameSite = getCookieSameSiteMode()
cookie.Path = "/login/" // Send cookie only in refresh path request
cookie.Secure = !IsLocalEnv()
c.SetCookie(cookie)
Expand All @@ -124,6 +124,14 @@ func validAddress(addr string) bool {
return re.MatchString(addr)
}

func getCookieSameSiteMode() http.SameSite {
sameSiteMode := http.SameSiteNoneMode // allow cors
if IsLocalEnv() {
sameSiteMode = http.SameSiteLaxMode // because SameSiteNoneMode is not allowed in localhost we use lax mode
}
return sameSiteMode
}

func SanitizeChecksums(addrs ...*string) {
for _, addr := range addrs {
if !validAddress(*addr) {
Expand Down
4 changes: 4 additions & 0 deletions infra/dev/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ locals {
name = "UNIT21_ORG_NAME"
value = "string"
},
{
name = "CHECKOUT_ENV"
value = local.env
},
{
name = "DD_LOGS_ENABLED"
value = "true"
Expand Down
4 changes: 4 additions & 0 deletions infra/prod/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ locals {
{
name = "UNIT21_ENV"
value = "api.prod2"
},
{
name = "CHECKOUT_ENV"
value = local.env
},
{
name = "UNIT21_ORG_NAME"
Expand Down
8 changes: 7 additions & 1 deletion pkg/service/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ import (
func getConfig() (*checkout.Config, error) {
var sk = os.Getenv("CHECKOUT_SECRET_KEY")
var pk = os.Getenv("CHECKOUT_PUBLIC_KEY")
var env = os.Getenv("CHECKOUT_ENV")
checkoutEnv := checkout.Sandbox

var config, err = checkout.SdkConfig(&sk, &pk, checkout.Sandbox)
if env == "prod" {
checkoutEnv = checkout.Production
}

var config, err = checkout.SdkConfig(&sk, &pk, checkoutEnv)
if err != nil {
return nil, common.StringError(err)
}
Expand Down
16 changes: 8 additions & 8 deletions scripts/data_seeding.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func DataSeeding() {
fmt.Printf("%+v", err)
return
}
networkMumbai, err := repos.Network.Create(model.Network{Name: "Mumbai Testnet", NetworkID: 80001, ChainID: 80001, GasOracle: "poly", RPCUrl: "https://matic-mumbai.chainstacklabs.com", ExplorerUrl: "https://mumbai.polygonscan.com/"})
networkMumbai, err := repos.Network.Create(model.Network{Name: "Mumbai Testnet", NetworkID: 80001, ChainID: 80001, GasOracle: "poly", RPCUrl: "https://matic-mumbai.chainstacklabs.com", ExplorerUrl: "https://mumbai.polygonscan.com"})
if err != nil {
panic(err)
}
networkGoerli, err := repos.Network.Create(model.Network{Name: "Goerli Testnet", NetworkID: 5, ChainID: 5, GasOracle: "eth", RPCUrl: "https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161", ExplorerUrl: "https://goerli.etherscan.io"})
if err != nil {
panic(err)
}
networkEthereum, err := repos.Network.Create(model.Network{Name: "Ethereum Mainnet", NetworkID: 1, ChainID: 1, GasOracle: "eth", RPCUrl: "https://rpc.ankr.com/eth", ExplorerUrl: "https://etherscan.io/"})
networkEthereum, err := repos.Network.Create(model.Network{Name: "Ethereum Mainnet", NetworkID: 1, ChainID: 1, GasOracle: "eth", RPCUrl: "https://rpc.ankr.com/eth", ExplorerUrl: "https://etherscan.io"})
if err != nil {
panic(err)
}
Expand All @@ -63,11 +63,11 @@ func DataSeeding() {
if err != nil {
panic(err)
}
networkNitroGoerli, err := repos.Network.Create(model.Network{Name: "Nitro Goerli Rollup Testnet", NetworkID: 421613, ChainID: 421613, GasOracle: "arb", RPCUrl: "https://goerli-rollup.arbitrum.io/rpc", ExplorerUrl: "https://goerli.arbiscan.io/"})
networkNitroGoerli, err := repos.Network.Create(model.Network{Name: "Nitro Goerli Rollup Testnet", NetworkID: 421613, ChainID: 421613, GasOracle: "arb", RPCUrl: "https://goerli-rollup.arbitrum.io/rpc", ExplorerUrl: "https://goerli.arbiscan.io"})
if err != nil {
panic(err)
}
networkArbitrumNova, err := repos.Network.Create(model.Network{Name: "Arbitrum Nova Mainnet", NetworkID: 42170, ChainID: 42170, GasOracle: "arb", RPCUrl: "https://nova.arbitrum.io/rpc", ExplorerUrl: "https://nova-explorer.arbitrum.io/"})
networkArbitrumNova, err := repos.Network.Create(model.Network{Name: "Arbitrum Nova Mainnet", NetworkID: 42170, ChainID: 42170, GasOracle: "arb", RPCUrl: "https://nova.arbitrum.io/rpc", ExplorerUrl: "https://nova-explorer.arbitrum.io"})
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -230,15 +230,15 @@ func MockSeeding() {
fmt.Printf("%+v", err)
return
}
networkMumbai, err := repos.Network.Create(model.Network{Name: "Mumbai Testnet", NetworkID: 80001, ChainID: 80001, GasOracle: "poly", RPCUrl: "https://matic-mumbai.chainstacklabs.com", ExplorerUrl: "https://mumbai.polygonscan.com/"})
networkMumbai, err := repos.Network.Create(model.Network{Name: "Mumbai Testnet", NetworkID: 80001, ChainID: 80001, GasOracle: "poly", RPCUrl: "https://matic-mumbai.chainstacklabs.com", ExplorerUrl: "https://mumbai.polygonscan.com"})
if err != nil {
panic(err)
}
networkGoerli, err := repos.Network.Create(model.Network{Name: "Goerli Testnet", NetworkID: 5, ChainID: 5, GasOracle: "eth", RPCUrl: "https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161", ExplorerUrl: "https://goerli.etherscan.io"})
if err != nil {
panic(err)
}
networkEthereum, err := repos.Network.Create(model.Network{Name: "Ethereum Mainnet", NetworkID: 1, ChainID: 1, GasOracle: "eth", RPCUrl: "https://rpc.ankr.com/eth", ExplorerUrl: "https://etherscan.io/"})
networkEthereum, err := repos.Network.Create(model.Network{Name: "Ethereum Mainnet", NetworkID: 1, ChainID: 1, GasOracle: "eth", RPCUrl: "https://rpc.ankr.com/eth", ExplorerUrl: "https://etherscan.io"})
if err != nil {
panic(err)
}
Expand All @@ -250,11 +250,11 @@ func MockSeeding() {
if err != nil {
panic(err)
}
networkNitroGoerli, err := repos.Network.Create(model.Network{Name: "Nitro Goerli Rollup Testnet", NetworkID: 421613, ChainID: 421613, GasOracle: "arb", RPCUrl: "https://goerli-rollup.arbitrum.io/rpc", ExplorerUrl: "https://goerli.arbiscan.io/"})
networkNitroGoerli, err := repos.Network.Create(model.Network{Name: "Nitro Goerli Rollup Testnet", NetworkID: 421613, ChainID: 421613, GasOracle: "arb", RPCUrl: "https://goerli-rollup.arbitrum.io/rpc", ExplorerUrl: "https://goerli.arbiscan.io"})
if err != nil {
panic(err)
}
networkArbitrumNova, err := repos.Network.Create(model.Network{Name: "Arbitrum Nova Mainnet", NetworkID: 42170, ChainID: 42170, GasOracle: "arb", RPCUrl: "https://nova.arbitrum.io/rpc", ExplorerUrl: "https://nova-explorer.arbitrum.io/"})
networkArbitrumNova, err := repos.Network.Create(model.Network{Name: "Arbitrum Nova Mainnet", NetworkID: 42170, ChainID: 42170, GasOracle: "arb", RPCUrl: "https://nova.arbitrum.io/rpc", ExplorerUrl: "https://nova-explorer.arbitrum.io"})
if err != nil {
panic(err)
}
Expand Down