Skip to content

Commit

Permalink
return 401 Unauthorized if user is not registered in Kleros
Browse files Browse the repository at this point in the history
  • Loading branch information
freigeistig committed Dec 21, 2023
1 parent cb1f006 commit 9647cf5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion internal/service/api/handlers/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
providers "github.com/rarimo/kyc-service/internal/service/core/identity_providers"
"github.com/rarimo/kyc-service/internal/service/core/identity_providers/civic"
gcpsp "github.com/rarimo/kyc-service/internal/service/core/identity_providers/gitcoin_passport"
"github.com/rarimo/kyc-service/internal/service/core/identity_providers/kleros"
"github.com/rarimo/kyc-service/internal/service/core/identity_providers/worldcoin"

"github.com/rarimo/kyc-service/internal/data"
Expand Down Expand Up @@ -69,5 +70,6 @@ func isUnauthorizedError(err error) bool {
errors.Is(err, providers.ErrNonceNotFound) ||
errors.Is(err, worldcoin.ErrNotLikelyHuman) ||
errors.Is(err, gcpsp.ErrScoreIsTooLow) ||
errors.Is(err, civic.ErrInvalidGatewayToken)
errors.Is(err, civic.ErrInvalidGatewayToken) ||
errors.Is(err, kleros.ErrIsNotRegistered)
}
12 changes: 6 additions & 6 deletions internal/service/core/identity_providers/kleros/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package kleros

import (
"encoding/json"
cryptoPkg "github.com/ethereum/go-ethereum/crypto"
"github.com/rarimo/kyc-service/internal/config"
"github.com/rarimo/kyc-service/internal/crypto"
"github.com/rarimo/kyc-service/internal/service/core/identity_providers/kleros/contracts"
"time"

"github.com/ethereum/go-ethereum/common"
cryptoPkg "github.com/ethereum/go-ethereum/crypto"
"gitlab.com/distributed_lab/logan/v3"
"gitlab.com/distributed_lab/logan/v3/errors"

"github.com/rarimo/kyc-service/internal/config"
"github.com/rarimo/kyc-service/internal/crypto"
"github.com/rarimo/kyc-service/internal/data"
providers "github.com/rarimo/kyc-service/internal/service/core/identity_providers"
"github.com/rarimo/kyc-service/internal/service/core/identity_providers/kleros/contracts"
"github.com/rarimo/kyc-service/internal/service/core/issuer"
)

type Kleros struct { // TODO?
type Kleros struct {
logger *logan.Entry
masterQ data.MasterQ
proofOfHumanityContract *contracts.ProofOfHumanity
Expand Down Expand Up @@ -113,7 +113,7 @@ func (k *Kleros) checkIfIsRegistered(userAddress common.Address) error {
return errors.Wrap(err, "failed to call isRegistered contract method")
}
if !isRegistered {
return errors.New("user is not registered")
return ErrIsNotRegistered
}
return nil
}
4 changes: 4 additions & 0 deletions internal/service/core/identity_providers/kleros/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package kleros
import (
"github.com/ethereum/go-ethereum/common"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/pkg/errors"

"github.com/rarimo/kyc-service/internal/service/api/requests"
"github.com/rarimo/kyc-service/resources"
)

var ErrIsNotRegistered = errors.New("user is not registered")

type (
// VerificationData is a data that is required by Kleros to verify a user
VerificationData resources.KlerosData
Expand Down

0 comments on commit 9647cf5

Please sign in to comment.