Skip to content

Commit

Permalink
added claimUserByThirdParty endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-ares committed Oct 22, 2024
1 parent 80959ee commit d9c6305
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 50 deletions.
67 changes: 67 additions & 0 deletions cmd/eskimo-hut/api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,73 @@ const docTemplate = `{
}
}
},
"/v1w/auth/thirdParty/:thirdParty/claimUser/:username": {
"post": {
"description": "Claims the user",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ThirdParty"
],
"parameters": [
{
"type": "string",
"default": "\u003cAdd api key here\u003e",
"description": "Insert your api key",
"name": "X-API-Key",
"in": "header",
"required": true
},
{
"type": "string",
"description": "some name or identifier of the caller",
"name": "thirdParty",
"in": "path",
"required": true
},
{
"type": "string",
"description": "the username",
"name": "username",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"403": {
"description": "api key invalid",
"schema": {
"$ref": "#/definitions/server.ErrorResponse"
}
},
"404": {
"description": "if the username provided does not exist or the account does not validate the requirements",
"schema": {
"$ref": "#/definitions/server.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/server.ErrorResponse"
}
},
"504": {
"description": "if request times out",
"schema": {
"$ref": "#/definitions/server.ErrorResponse"
}
}
}
}
},
"/v1w/kyc/checkKYCStep4Status/users/{userId}": {
"post": {
"description": "Checks the status of the quiz kyc step (4).",
Expand Down
67 changes: 67 additions & 0 deletions cmd/eskimo-hut/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,73 @@
}
}
},
"/v1w/auth/thirdParty/:thirdParty/claimUser/:username": {
"post": {
"description": "Claims the user",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ThirdParty"
],
"parameters": [
{
"type": "string",
"default": "\u003cAdd api key here\u003e",
"description": "Insert your api key",
"name": "X-API-Key",
"in": "header",
"required": true
},
{
"type": "string",
"description": "some name or identifier of the caller",
"name": "thirdParty",
"in": "path",
"required": true
},
{
"type": "string",
"description": "the username",
"name": "username",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK"
},
"403": {
"description": "api key invalid",
"schema": {
"$ref": "#/definitions/server.ErrorResponse"
}
},
"404": {
"description": "if the username provided does not exist or the account does not validate the requirements",
"schema": {
"$ref": "#/definitions/server.ErrorResponse"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/server.ErrorResponse"
}
},
"504": {
"description": "if request times out",
"schema": {
"$ref": "#/definitions/server.ErrorResponse"
}
}
}
}
},
"/v1w/kyc/checkKYCStep4Status/users/{userId}": {
"post": {
"description": "Checks the status of the quiz kyc step (4).",
Expand Down
46 changes: 46 additions & 0 deletions cmd/eskimo-hut/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,52 @@ paths:
$ref: '#/definitions/server.ErrorResponse'
tags:
- Auth
/v1w/auth/thirdParty/:thirdParty/claimUser/:username:
post:
consumes:
- application/json
description: Claims the user
parameters:
- default: <Add api key here>
description: Insert your api key
in: header
name: X-API-Key
required: true
type: string
- description: some name or identifier of the caller
in: path
name: thirdParty
required: true
type: string
- description: the username
in: path
name: username
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
"403":
description: api key invalid
schema:
$ref: '#/definitions/server.ErrorResponse'
"404":
description: if the username provided does not exist or the account does
not validate the requirements
schema:
$ref: '#/definitions/server.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/server.ErrorResponse'
"504":
description: if request times out
schema:
$ref: '#/definitions/server.ErrorResponse'
tags:
- ThirdParty
/v1w/kyc/checkKYCStep4Status/users/{userId}:
post:
consumes:
Expand Down
39 changes: 38 additions & 1 deletion cmd/eskimo-hut/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func (s *service) setupAuthRoutes(router *server.Router) {
POST("auth/getMetadata", server.RootHandler(s.Metadata)).
POST("auth/processFaceRecognitionResult", server.RootHandler(s.ProcessFaceRecognitionResult)).
POST("auth/getValidUserForPhoneNumberMigration", server.RootHandler(s.GetValidUserForPhoneNumberMigration)).
POST("auth/signInWithTelegram", server.RootHandler(s.SignInWithTelegram))
POST("auth/signInWithTelegram", server.RootHandler(s.SignInWithTelegram)).
POST("auth/thirdParty/{thirdParty}/claimUser/{username}", server.RootHandler(s.ClaimUserByThirdParty))
}

// SendSignInLinkToEmail godoc
Expand Down Expand Up @@ -534,3 +535,39 @@ func (s *service) SignInWithTelegram( //nolint:gocritic // .

return server.OK(&RefreshedToken{Tokens: tokens}), nil
}

// ClaimUserByThirdParty godoc
//
// @Schemes
// @Description Claims the user
// @Tags ThirdParty
// @Accept json
// @Produce json
// @Param X-API-Key header string true "Insert your api key" default(<Add api key here>)
// @Param thirdParty path string true "some name or identifier of the caller"
// @Param username path string true "the username"
// @Success 200 "OK"
// @Failure 404 {object} server.ErrorResponse "if the username provided does not exist or the account does not validate the requirements"
// @Failure 403 {object} server.ErrorResponse "api key invalid"
// @Failure 500 {object} server.ErrorResponse
// @Failure 504 {object} server.ErrorResponse "if request times out"
// @Router /v1w/auth/thirdParty/:thirdParty/claimUser/:username [POST].
func (s *service) ClaimUserByThirdParty( //nolint:gocritic // .
ctx context.Context,
req *server.Request[ClaimUserByThirdPartyRequestArg, any],
) (*server.Response[any], *server.Response[server.ErrorResponse]) {
if cfg.ThirdPartyAPIKey != req.Data.APIKey {
return nil, server.Forbidden(errors.New("not allowed"))
}
if err := s.usersProcessor.ClaimUserBy3rdParty(ctx, req.Data.Username, req.Data.ThirdParty); err != nil {
err = errors.Wrapf(err, "failed to ClaimUserBy3rdParty(%v,%v)", req.Data.Username, req.Data.ThirdParty)
switch {
case errors.Is(err, users.ErrNotFound):
return nil, server.NotFound(err, userNotFoundErrorCode)
default:
return nil, server.Unexpected(err)
}
}

return server.OK[any](), nil
}
14 changes: 10 additions & 4 deletions cmd/eskimo-hut/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ type (
DeviceUniqueID string `json:"deviceUniqueId" required:"true" example:"70063ABB-E69F-4FD2-8B83-90DD372802DA"`
Language string `json:"language" required:"true" example:"en"`
}
ClaimUserByThirdPartyRequestArg struct {
APIKey string `header:"X-API-Key" swaggerignore:"true" allowUnauthorized:"true" required:"true" example:"some secret"` //nolint:tagliatelle // Nope.
Username string `uri:"username" swaggerignore:"true" allowUnauthorized:"true" required:"true" example:"jdoe"`
ThirdParty string `uri:"thirdParty" swaggerignore:"true" allowUnauthorized:"true" required:"true" example:"Facebook"`
}
StatusArg struct {
LoginSession string `json:"loginSession" allowUnauthorized:"true" required:"true" example:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2ODQzMjQ0NTYsImV4cCI6MTcxNTg2MDQ1NiwiYXVkIjoiIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIm90cCI6IjUxMzRhMzdkLWIyMWEtNGVhNi1hNzk2LTAxOGIwMjMwMmFhMCJ9.q3xa8Gwg2FVCRHLZqkSedH3aK8XBqykaIy85rRU40nM"` //nolint:lll // .
}
Expand Down Expand Up @@ -248,9 +253,10 @@ type (
faceKycClient facekyc.Client
}
config struct {
APIKey string `yaml:"api-key" mapstructure:"api-key"` //nolint:tagliatelle // Nope.
Host string `yaml:"host"`
Version string `yaml:"version"`
Tenant string `yaml:"tenant"`
APIKey string `yaml:"api-key" mapstructure:"api-key"` //nolint:tagliatelle // Nope.
ThirdPartyAPIKey string `yaml:"third-party-api-key" mapstructure:"third-party-api-key"` //nolint:tagliatelle // Nope.
Host string `yaml:"host"`
Version string `yaml:"version"`
Tenant string `yaml:"tenant"`
}
)
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/jackc/pgx/v5 v5.7.1
github.com/pkg/errors v0.9.1
github.com/prometheus/common v0.60.0
github.com/prometheus/prometheus v0.54.1
github.com/prometheus/prometheus v0.55.0
github.com/redis/go-redis/v9 v9.7.0
github.com/stretchr/testify v1.9.0
github.com/swaggo/swag v1.16.4
Expand Down Expand Up @@ -46,12 +46,12 @@ require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/MicahParks/keyfunc v1.9.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.12.7 // indirect
github.com/Microsoft/hcsshim v0.12.8 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.12.3 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/bytedance/sonic/loader v0.2.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
Expand All @@ -62,7 +62,6 @@ require (
github.com/containerd/cgroups/v3 v3.0.3 // indirect
github.com/containerd/containerd v1.7.23 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/containerd/errdefs v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dennwc/varint v1.0.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
Expand Down Expand Up @@ -98,7 +97,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e // indirect
github.com/google/pprof v0.0.0-20241017200806-017d972448fc // indirect
github.com/google/pprof v0.0.0-20241021161924-4cf4322d492d // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
Expand All @@ -121,6 +120,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/sys/mount v0.3.4 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/sys/user v0.3.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -129,7 +129,7 @@ require (
github.com/onsi/ginkgo/v2 v2.20.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runc v1.1.15 // indirect
github.com/opencontainers/runc v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240917153116-6f2963f01587 // indirect
Expand All @@ -138,7 +138,7 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.48.0 // indirect
github.com/quic-go/quic-go v0.48.1 // indirect
github.com/refraction-networking/utls v1.6.7 // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
Expand Down Expand Up @@ -185,11 +185,11 @@ require (
golang.org/x/tools v0.26.0 // indirect
google.golang.org/api v0.201.0 // indirect
google.golang.org/appengine/v2 v2.0.6 // indirect
google.golang.org/genproto v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/grpc/stats/opentelemetry v0.0.0-20241018153737-98959d9a4904 // indirect
google.golang.org/grpc/stats/opentelemetry v0.0.0-20241021183144-14e2a206ca0a // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit d9c6305

Please sign in to comment.