Skip to content

Commit

Permalink
Merge pull request #5870 from mysteriumnetwork/improvements/grant-ver…
Browse files Browse the repository at this point in the history
…ification

Extend grant verification response
  • Loading branch information
mdomasevicius authored Sep 1, 2023
2 parents 6128592 + 5a06e2b commit e233f37
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions tequilapi/contract/mmn.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type MMNLinkRedirectResponse struct {
// MMNGrantVerificationResponse message received via redirect from mystnodes.com
// swagger:model MMNGrantVerificationResponse
type MMNGrantVerificationResponse struct {
ApiKey string `json:"api_key"`
WalletAddress string `json:"wallet_address"`
ApiKey string `json:"api_key"`
WalletAddress string `json:"wallet_address"`
IsEligibleForFreeRegistration bool `json:"is_eligible_for_free_registration"`
}
4 changes: 4 additions & 0 deletions tequilapi/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4480,6 +4480,10 @@
"type": "string",
"x-go-name": "ApiKey"
},
"is_eligible_for_free_registration": {
"type": "boolean",
"x-go-name": "IsEligibleForFreeRegistration"
},
"wallet_address": {
"type": "string",
"x-go-name": "WalletAddress"
Expand Down
5 changes: 3 additions & 2 deletions tequilapi/endpoints/mmn.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,9 @@ func (api *mmnAPI) VerifyGrant(c *gin.Context) {
}

r := contract.MMNGrantVerificationResponse{
ApiKey: vi.APIkey,
WalletAddress: vi.WalletAddress,
ApiKey: vi.APIkey,
WalletAddress: vi.WalletAddress,
IsEligibleForFreeRegistration: vi.IsEligibleForFreeRegistration,
}

c.JSON(http.StatusOK, r)
Expand Down
5 changes: 3 additions & 2 deletions tequilapi/sso/mystnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ func (m *Mystnodes) consumeCodeVerifier() {

// VerifyInfo information gathered during grant verification
type VerifyInfo struct {
APIkey string
WalletAddress string
APIkey string `json:"apiKey"`
WalletAddress string `json:"walletAddress"`
IsEligibleForFreeRegistration bool `json:"isEligibleForFreeRegistration"`
}

// DefaultVerificationOptions default options
Expand Down
7 changes: 5 additions & 2 deletions tequilapi/sso/mystnodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,17 @@ func TestMystnodesSSOGrantVerification(t *testing.T) {
assert.NoError(t, err)

// when
sso := NewMystnodes(signerFactory, newHttpClientMock(&http.Response{StatusCode: 200, Status: "200 OK", Body: &readCloser{Reader: strings.NewReader("{}")}}))
sso := NewMystnodes(signerFactory, newHttpClientMock(&http.Response{StatusCode: 200, Status: "200 OK", Body: &readCloser{Reader: strings.NewReader(`{"walletAddress": "0x111", "apiKey": "xxx", "isEligibleForFreeRegistration": true}`)}}))
sso.lastUnlockedIdentity = identity.Identity{Address: "0x1"}
_, err = sso.SSOLink(redirect)
assert.NoError(t, err)

// then
_, err = sso.VerifyAuthorizationGrant("auth_grant", DefaultVerificationOptions)
vi, err := sso.VerifyAuthorizationGrant("auth_grant", DefaultVerificationOptions)
assert.NoError(t, err)
assert.Equal(t, true, vi.IsEligibleForFreeRegistration)
assert.Equal(t, "0x111", vi.WalletAddress)
assert.Equal(t, "xxx", vi.APIkey)

// when
sso = NewMystnodes(signerFactory, newHttpClientMock(nil))
Expand Down

0 comments on commit e233f37

Please sign in to comment.