Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from oxygenpay/develop
Browse files Browse the repository at this point in the history
merge: develop
  • Loading branch information
swift1337 authored Jul 27, 2023
2 parents 4173ea8 + 79b56a5 commit 7f7d695
Show file tree
Hide file tree
Showing 13 changed files with 1,460 additions and 641 deletions.
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ require (
github.com/jackc/pgx/v4 v4.16.1
github.com/jellydator/ttlcache/v3 v3.0.1
github.com/labstack/echo-contrib v0.12.0
github.com/labstack/echo/v4 v4.7.2
github.com/labstack/gommon v0.3.1
github.com/labstack/echo/v4 v4.11.1
github.com/labstack/gommon v0.4.0
github.com/olekukonko/tablewriter v0.0.5
github.com/oxygenpay/tatum-sdk v0.0.0-20230529210116-d986b7743613
github.com/pkg/errors v0.9.1
Expand All @@ -36,7 +36,7 @@ require (
github.com/ziflex/lecho/v3 v3.1.0
go.etcd.io/bbolt v1.3.6
go.uber.org/atomic v1.10.0
golang.org/x/crypto v0.7.0
golang.org/x/crypto v0.11.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/oauth2 v0.1.0
golang.org/x/sync v0.1.0
Expand Down Expand Up @@ -80,7 +80,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
Expand All @@ -95,12 +95,12 @@ require (
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.mongodb.org/mongo-driver v1.8.3 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
Expand Down
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6dtGktsI=
github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK09Y2A4Xv7EE0=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 h1:HbphB4TFFXpv7MNrT52FGrrgVXF1owhMVTHFZIlnvd4=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2UO1+lbSKsdiOoYi9Zzey7Fc=
github.com/denisenkom/go-mssqldb v0.9.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
Expand Down Expand Up @@ -425,9 +426,13 @@ github.com/labstack/echo-contrib v0.12.0/go.mod h1:kR62TbwsBgmpV2HVab5iQRsQtLuhP
github.com/labstack/echo/v4 v4.6.1/go.mod h1:RnjgMWNDB9g/HucVWhQYNQP9PvbYf6adqftqryo7s9k=
github.com/labstack/echo/v4 v4.7.2 h1:Kv2/p8OaQ+M6Ex4eGimg9b9e6icoxA42JSlOR3msKtI=
github.com/labstack/echo/v4 v4.7.2/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks=
github.com/labstack/echo/v4 v4.11.1 h1:dEpLU2FLg4UVmvCGPuk/APjlH6GDpbEPti61srUUUs4=
github.com/labstack/echo/v4 v4.11.1/go.mod h1:YuYRTSM3CHs2ybfrL8Px48bO6BAnYIN4l8wSTMP6BDQ=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o=
github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
Expand Down Expand Up @@ -464,6 +469,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-oci8 v0.1.1/go.mod h1:wjDx6Xm9q7dFtHJvIlrI99JytznLw5wQ4R+9mNXJwGI=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
Expand Down Expand Up @@ -611,6 +618,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/wemeetagain/go-hdwallet v0.1.0 h1:ELpLLaz47CgYyXfyLDGnZgGJSkG9eWvK/RF4f0WmLyM=
github.com/wemeetagain/go-hdwallet v0.1.0/go.mod h1:V2AxcXVscy8NML27VJNpnqpkU68pJfuPFSCIIzWnrKU=
github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
Expand Down Expand Up @@ -686,6 +695,8 @@ golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -768,6 +779,8 @@ golang.org/x/net v0.0.0-20210913180222-943fd674d43e/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -861,10 +874,13 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -876,12 +892,16 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down Expand Up @@ -950,6 +970,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
Expand Down
9 changes: 6 additions & 3 deletions internal/auth/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"io"

"github.com/oxygenpay/oxygen/internal/util"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -46,9 +47,11 @@ func NewGoogleOAuth(cfg GoogleConfig, logger *zerolog.Logger) *GoogleOAuthManage
}
}

// RedirectURL return URL to Google auth screen.
func (a *GoogleOAuthManager) RedirectURL() string {
return a.config.AuthCodeURL("")
// RedirectURLWithState return URL to Google auth screen.
func (a *GoogleOAuthManager) RedirectURLWithState() (string, string) {
state := util.Strings.Random(16)

return a.config.AuthCodeURL(state), state
}

func (a *GoogleOAuthManager) ResolveUser(ctx context.Context, code string) (*GoogleUser, error) {
Expand Down
10 changes: 6 additions & 4 deletions internal/server/http/internalapi/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/pkg/errors"
)

const defaultPaginationLimit = 30
const defaultPaginationLimit = int32(30)
const maxPaginationLimit = 100

const paramWalletID = "walletID"
Expand Down Expand Up @@ -221,14 +221,16 @@ func (h *Handler) ListWallets(c echo.Context) error {

paginationLimit := defaultPaginationLimit
if limit != "" {
paginationLimit, err = strconv.Atoi(limit)
if err != nil {
l, errParse := strconv.ParseInt(limit, 10, 32)
if errParse != nil {
return c.JSON(http.StatusBadRequest, &admin.ErrorResponse{
Errors: nil,
Message: "Invalid query param: limit",
Status: "validation_error",
})
}

paginationLimit = int32(l)
}

invalid := startID < 1 || paginationLimit > maxPaginationLimit ||
Expand All @@ -245,7 +247,7 @@ func (h *Handler) ListWallets(c echo.Context) error {
ctx := c.Request().Context()
wallets, nextPageID, err := h.wallet.List(ctx, wallet.Pagination{
Start: int64(startID),
Limit: int64(paginationLimit),
Limit: paginationLimit,
FilterByBlockchain: blockchain,
})

Expand Down
3 changes: 2 additions & 1 deletion internal/server/http/merchantapi/auth/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ func (h *Handler) PostLogin(c echo.Context) error {
return errors.Wrap(err, "unable to resolve user")
}

if err := h.persistSessionUserID(c, person.ID, "email"); err != nil {
setSession := map[string]any{middleware.UserIDContextKey: person.ID}
if err := h.persistSession(c, "email", setSession); err != nil {
return common.ErrorResponse(c, "internal error")
}

Expand Down
27 changes: 22 additions & 5 deletions internal/server/http/merchantapi/auth/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,34 @@ func (h *Handler) GetRedirect(c echo.Context) error {
return c.Redirect(http.StatusTemporaryRedirect, h.googleAuth.GetAuthenticatedRedirectURL())
}

return c.Redirect(http.StatusTemporaryRedirect, h.googleAuth.RedirectURL())
redirect, state := h.googleAuth.RedirectURLWithState()

setSession := map[string]any{middleware.SessionStateKey: state}
if err := h.persistSession(c, "google", setSession); err != nil {
return common.ErrorResponse(c, "internal error")
}

return c.Redirect(http.StatusTemporaryRedirect, redirect)
}

func (h *Handler) GetCallback(c echo.Context) error {
ctx := c.Request().Context()

if person := middleware.ResolveUser(c); person != nil {
return c.Redirect(http.StatusTemporaryRedirect, h.googleAuth.GetAuthenticatedRedirectURL())
}

ctx := c.Request().Context()
query := c.Request().URL.Query()

expectedState, stateExists := middleware.ResolveSessionOAuthState(c)
switch {
case !stateExists:
return common.ValidationErrorResponse(c, "Missing OAuth state")
case expectedState != query.Get("state"):
return common.ValidationErrorResponse(c, "OAuth state mismatch")
}

code := c.Request().URL.Query().Get("code")
googleUser, err := h.googleAuth.ResolveUser(ctx, code)
googleUser, err := h.googleAuth.ResolveUser(ctx, query.Get("code"))
if err != nil {
msg := "unable to resolve googleUser"
h.logger.Error().Err(err).Msg(msg)
Expand All @@ -43,7 +59,8 @@ func (h *Handler) GetCallback(c echo.Context) error {
return errors.Wrap(err, "unable to resolve google user")
}

if err := h.persistSessionUserID(c, person.ID, "google"); err != nil {
setSession := map[string]any{middleware.UserIDContextKey: person.ID}
if err := h.persistSession(c, "google", setSession); err != nil {
return common.ErrorResponse(c, "internal error")
}

Expand Down
9 changes: 6 additions & 3 deletions internal/server/http/merchantapi/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ func (h *Handler) PostLogout(c echo.Context) error {
return c.NoContent(http.StatusNoContent)
}

func (h *Handler) persistSessionUserID(c echo.Context, id int64, provider string) error {
func (h *Handler) persistSession(c echo.Context, source string, values map[string]any) error {
s := middleware.ResolveSession(c)
s.Values[middleware.UserIDContextKey] = id

for k, v := range values {
s.Values[k] = v
}

if err := s.Save(c.Request(), c.Response()); err != nil {
h.logger.Error().Err(err).Str("provider", provider).Msg("unable to persist user session")
h.logger.Error().Err(err).Str("source", source).Msg("unable to persist user session")
return err
}

Expand Down
18 changes: 18 additions & 0 deletions internal/server/http/middleware/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
IsTokenAuthContextKey = "token_auth"
MerchantContextKey = "merchant"

SessionStateKey = "session_state"

ParamMerchantID = "merchantId"
)

Expand Down Expand Up @@ -216,6 +218,22 @@ func ResolveSession(c echo.Context) *sessions.Session {
return userSession
}

func ResolveSessionOAuthState(c echo.Context) (string, bool) {
s := ResolveSession(c)

raw, ok := s.Values[SessionStateKey]
if !ok {
return "", false
}

state, ok := raw.(string)
if !ok {
return "", false
}

return state, true
}

func ResolveUser(c echo.Context) *user.User {
personRaw := c.Get(UserContextKey)
person, ok := personRaw.(*user.User)
Expand Down
4 changes: 2 additions & 2 deletions internal/service/wallet/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Type string

type Pagination struct {
Start int64
Limit int64
Limit int32
FilterByBlockchain kmswallet.Blockchain
FilterByType Type
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func (s *Service) GetByUUID(ctx context.Context, id uuid.UUID) (*Wallet, error)
func (s *Service) List(ctx context.Context, pagination Pagination) ([]*Wallet, *int64, error) {
results, err := s.store.PaginateWalletsByID(ctx, repository.PaginateWalletsByIDParams{
ID: pagination.Start,
Limit: int32(pagination.Limit),
Limit: pagination.Limit,
FilterByBlockchain: pagination.FilterByBlockchain != "",
Blockchain: string(pagination.FilterByBlockchain),
FilterByType: pagination.FilterByType != "",
Expand Down
Loading

0 comments on commit 7f7d695

Please sign in to comment.