diff --git a/docs/spec/components/schemas/Authorize.yaml b/docs/spec/components/schemas/Authorize.yaml index 7f073af..8956d27 100644 --- a/docs/spec/components/schemas/Authorize.yaml +++ b/docs/spec/components/schemas/Authorize.yaml @@ -1,5 +1,5 @@ allOf: - - $ref: '#/components/schemas/UserKey' + - $ref: '#/components/schemas/AuthorizeKey' - type: object x-go-is-request: true required: @@ -13,4 +13,4 @@ allOf: proof: type: object format: json.RawMessage - description: JSON encoded ZK proof AuthV2 proof. + description: JSON-encoded Query ZK-proof. diff --git a/docs/spec/components/schemas/UserKey.yaml b/docs/spec/components/schemas/AuthorizeKey.yaml similarity index 64% rename from docs/spec/components/schemas/UserKey.yaml rename to docs/spec/components/schemas/AuthorizeKey.yaml index aea5cf4..572bd12 100644 --- a/docs/spec/components/schemas/UserKey.yaml +++ b/docs/spec/components/schemas/AuthorizeKey.yaml @@ -10,9 +10,4 @@ properties: description: User nullifier 32 bytes type: type: string - enum: - - request-authorize - - request-challenge - - token - - validation - - challenge + enum: [ authorize ] diff --git a/docs/spec/components/schemas/Challenge.yaml b/docs/spec/components/schemas/Challenge.yaml index 5a44be5..635933d 100644 --- a/docs/spec/components/schemas/Challenge.yaml +++ b/docs/spec/components/schemas/Challenge.yaml @@ -1,5 +1,5 @@ allOf: - - $ref: '#/components/schemas/UserKey' + - $ref: '#/components/schemas/ChallengeKey' - type: object required: - attributes @@ -10,5 +10,7 @@ allOf: properties: challenge: type: string - description: Base64 encoded challenge. Use it to generate AuthV2 ZK proof. Decode base64 string and convert into big-endian decimal number. + description: | + Base64 encoded challenge. Use it to generate Query ZK-proof. + Decode base64 string and convert into big-endian decimal number. example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 diff --git a/docs/spec/components/schemas/ChallengeKey.yaml b/docs/spec/components/schemas/ChallengeKey.yaml new file mode 100644 index 0000000..a9718c4 --- /dev/null +++ b/docs/spec/components/schemas/ChallengeKey.yaml @@ -0,0 +1,13 @@ +type: object +required: + - id + - type +properties: + id: + type: string + example: "0x123...abc" + pattern: '^0x[0-9a-fA-F]{64}$' + description: User nullifier 32 bytes + type: + type: string + enum: [ challenge ] diff --git a/docs/spec/components/schemas/Claim.yaml b/docs/spec/components/schemas/Claim.yaml index a936595..50840f5 100644 --- a/docs/spec/components/schemas/Claim.yaml +++ b/docs/spec/components/schemas/Claim.yaml @@ -3,10 +3,6 @@ type: object required: - nullifier properties: - address: - type: string - example: "0xF65F3f18D9087c4E35BAC5b9746492082e186872" - description: User EVM address hex-encoded nullifier: type: string example: "0x123...abc" diff --git a/docs/spec/components/schemas/JWT.yaml b/docs/spec/components/schemas/JWT.yaml index ff8f45f..4b41b47 100644 --- a/docs/spec/components/schemas/JWT.yaml +++ b/docs/spec/components/schemas/JWT.yaml @@ -2,12 +2,12 @@ description: 'JWT token' type: object required: - token - - tokenType + - token_type properties: token: type: string description: Base64 encoded JWT example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c - tokenType: + token_type: type: string enum: [ access, refresh ] \ No newline at end of file diff --git a/docs/spec/components/schemas/Token.yaml b/docs/spec/components/schemas/Token.yaml index 2ecb543..51f5688 100644 --- a/docs/spec/components/schemas/Token.yaml +++ b/docs/spec/components/schemas/Token.yaml @@ -1,16 +1,16 @@ allOf: - - $ref: '#/components/schemas/UserKey' + - $ref: '#/components/schemas/TokenKey' - type: object required: - attributes properties: attributes: required: - - accessToken - - refreshToken + - access_token + - refresh_token type: object properties: - accessToken: + access_token: $ref: '#/components/schemas/JWT' - refreshToken: + refresh_token: $ref: '#/components/schemas/JWT' diff --git a/docs/spec/components/schemas/TokenKey.yaml b/docs/spec/components/schemas/TokenKey.yaml new file mode 100644 index 0000000..d6d0239 --- /dev/null +++ b/docs/spec/components/schemas/TokenKey.yaml @@ -0,0 +1,13 @@ +type: object +required: + - id + - type +properties: + id: + type: string + example: "0x123...abc" + pattern: '^0x[0-9a-fA-F]{64}$' + description: User nullifier 32 bytes + type: + type: string + enum: [ token ] diff --git a/docs/spec/components/schemas/ValidationResult.yaml b/docs/spec/components/schemas/ValidationResult.yaml index 5ba1d38..88deef3 100644 --- a/docs/spec/components/schemas/ValidationResult.yaml +++ b/docs/spec/components/schemas/ValidationResult.yaml @@ -1,5 +1,5 @@ allOf: - - $ref: '#/components/schemas/UserKey' + - $ref: '#/components/schemas/ValidationResultKey' - type: object required: - attributes diff --git a/docs/spec/components/schemas/ValidationResultKey.yaml b/docs/spec/components/schemas/ValidationResultKey.yaml new file mode 100644 index 0000000..be68af4 --- /dev/null +++ b/docs/spec/components/schemas/ValidationResultKey.yaml @@ -0,0 +1,13 @@ +type: object +required: + - id + - type +properties: + id: + type: string + example: "0x123...abc" + pattern: '^0x[0-9a-fA-F]{64}$' + description: User nullifier 32 bytes + type: + type: string + enum: [ validation ] diff --git a/docs/spec/paths/v1@authorize@{nullifier}@challenge.yaml b/docs/spec/paths/v1@authorize@{nullifier}@challenge.yaml index a1aa5ce..f60f48a 100644 --- a/docs/spec/paths/v1@authorize@{nullifier}@challenge.yaml +++ b/docs/spec/paths/v1@authorize@{nullifier}@challenge.yaml @@ -3,7 +3,7 @@ get: - Authorize summary: Request challenge description: | - Request challenge to generate AuthV2 proof with + Request challenge to generate Query proof with operationId: challenge parameters: - $ref: '#/components/parameters/pathNullifier' diff --git a/generate.sh b/generate.sh index 11fb283..b023b12 100755 --- a/generate.sh +++ b/generate.sh @@ -2,9 +2,10 @@ GENERATOR_IMAGE=tokend/openapi-generator:v0.1.0 +[[ ! -x "$(command -v go 2>/dev/null)" ]] && echo "go is not installed" && exit 1 -GENERATED="${GOPATH}/src/github.com/rarimo/decentralized-auth-svc/resources" -OPENAPI_DIR="${GOPATH}/src/github.com/rarimo/decentralized-auth-svc/docs/web_deploy" +GENERATED="$PWD/resources" +OPENAPI_DIR="$PWD/docs/web_deploy" PACKAGE_NAME=resources function printHelp { @@ -50,7 +51,8 @@ function parseArgs { function generate { (cd docs && npm run build) - docker run -v "${OPENAPI_DIR}":/openapi -v "${GENERATED}":/generated "${GENERATOR_IMAGE}" generate -pkg "${PACKAGE_NAME}" --raw-formats-as-types + docker run --rm -v "${OPENAPI_DIR}":/openapi -v "${GENERATED}":/generated "${GENERATOR_IMAGE}" \ + generate -pkg "${PACKAGE_NAME}" --raw-formats-as-types --meta-for-lists goimports -w ${GENERATED} } diff --git a/internal/service/requests/authorize.go b/internal/service/requests/authorize.go index 47c0340..13f7587 100644 --- a/internal/service/requests/authorize.go +++ b/internal/service/requests/authorize.go @@ -19,6 +19,7 @@ func NewAuthorizeRequest(r *http.Request) (*resources.AuthorizeRequest, error) { req.Data.ID = strings.ToLower(req.Data.ID) return req, validation.Errors{ - "data/id": validation.Validate(req.Data.ID, validation.Required, validation.Match(zkp.NullifierRegexp)), + "data/id": validation.Validate(req.Data.ID, validation.Required, validation.Match(zkp.NullifierRegexp)), + "data/type": validation.Validate(req.Data.Type, validation.Required, validation.In(resources.AUTHORIZE)), }.Filter() } diff --git a/resources/model_authorize.go b/resources/model_authorize.go index d687ac9..b91d8de 100644 --- a/resources/model_authorize.go +++ b/resources/model_authorize.go @@ -4,6 +4,8 @@ package resources +import "encoding/json" + type Authorize struct { Key Attributes AuthorizeAttributes `json:"attributes"` @@ -14,9 +16,19 @@ type AuthorizeRequest struct { } type AuthorizeListRequest struct { - Data []Authorize `json:"data"` - Included Included `json:"included"` - Links *Links `json:"links"` + Data []Authorize `json:"data"` + Included Included `json:"included"` + Links *Links `json:"links"` + Meta json.RawMessage `json:"meta,omitempty"` +} + +func (r *AuthorizeListRequest) PutMeta(v interface{}) (err error) { + r.Meta, err = json.Marshal(v) + return err +} + +func (r *AuthorizeListRequest) GetMeta(out interface{}) error { + return json.Unmarshal(r.Meta, out) } // MustAuthorize - returns Authorize from include collection. diff --git a/resources/model_authorize_attributes.go b/resources/model_authorize_attributes.go index 10608b3..fad6965 100644 --- a/resources/model_authorize_attributes.go +++ b/resources/model_authorize_attributes.go @@ -7,6 +7,6 @@ package resources import "encoding/json" type AuthorizeAttributes struct { - // JSON encoded ZK proof AuthV2 proof. + // JSON-encoded Query ZK-proof. Proof json.RawMessage `json:"proof"` } diff --git a/resources/model_challenge.go b/resources/model_challenge.go index 57f8b77..9323de2 100644 --- a/resources/model_challenge.go +++ b/resources/model_challenge.go @@ -4,6 +4,8 @@ package resources +import "encoding/json" + type Challenge struct { Key Attributes ChallengeAttributes `json:"attributes"` @@ -14,9 +16,19 @@ type ChallengeResponse struct { } type ChallengeListResponse struct { - Data []Challenge `json:"data"` - Included Included `json:"included"` - Links *Links `json:"links"` + Data []Challenge `json:"data"` + Included Included `json:"included"` + Links *Links `json:"links"` + Meta json.RawMessage `json:"meta,omitempty"` +} + +func (r *ChallengeListResponse) PutMeta(v interface{}) (err error) { + r.Meta, err = json.Marshal(v) + return err +} + +func (r *ChallengeListResponse) GetMeta(out interface{}) error { + return json.Unmarshal(r.Meta, out) } // MustChallenge - returns Challenge from include collection. diff --git a/resources/model_challenge_attributes.go b/resources/model_challenge_attributes.go index fae7614..2d185a2 100644 --- a/resources/model_challenge_attributes.go +++ b/resources/model_challenge_attributes.go @@ -5,6 +5,6 @@ package resources type ChallengeAttributes struct { - // Base64 encoded challenge. Use it to generate AuthV2 ZK proof. Decode base64 string and convert into big-endian decimal number. + // Base64 encoded challenge. Use it to generate Query ZK-proof. Decode base64 string and convert into big-endian decimal number. Challenge string `json:"challenge"` } diff --git a/resources/model_claim.go b/resources/model_claim.go index 9bf3257..a5770ac 100644 --- a/resources/model_claim.go +++ b/resources/model_claim.go @@ -6,8 +6,6 @@ package resources // Authorized user personal data type Claim struct { - // User EVM address hex-encoded - Address *string `json:"address,omitempty"` // Nullifier authorized with Nullifier string `json:"nullifier"` } diff --git a/resources/model_jwt.go b/resources/model_jwt.go index 5bd994f..d42f8ac 100644 --- a/resources/model_jwt.go +++ b/resources/model_jwt.go @@ -8,5 +8,5 @@ package resources type Jwt struct { // Base64 encoded JWT Token string `json:"token"` - TokenType string `json:"tokenType"` + TokenType string `json:"token_type"` } diff --git a/resources/model_resource_type.go b/resources/model_resource_type.go index 7dad730..ee09132 100644 --- a/resources/model_resource_type.go +++ b/resources/model_resource_type.go @@ -8,9 +8,8 @@ type ResourceType string // List of ResourceType const ( - REQUEST_AUTHORIZE ResourceType = "request-authorize" - REQUEST_CHALLENGE ResourceType = "request-challenge" - TOKEN ResourceType = "token" - VALIDATION ResourceType = "validation" - CHALLENGE ResourceType = "challenge" + AUTHORIZE ResourceType = "authorize" + CHALLENGE ResourceType = "challenge" + TOKEN ResourceType = "token" + VALIDATION ResourceType = "validation" ) diff --git a/resources/model_token.go b/resources/model_token.go index d34001d..c03c4af 100644 --- a/resources/model_token.go +++ b/resources/model_token.go @@ -4,6 +4,8 @@ package resources +import "encoding/json" + type Token struct { Key Attributes TokenAttributes `json:"attributes"` @@ -14,9 +16,19 @@ type TokenResponse struct { } type TokenListResponse struct { - Data []Token `json:"data"` - Included Included `json:"included"` - Links *Links `json:"links"` + Data []Token `json:"data"` + Included Included `json:"included"` + Links *Links `json:"links"` + Meta json.RawMessage `json:"meta,omitempty"` +} + +func (r *TokenListResponse) PutMeta(v interface{}) (err error) { + r.Meta, err = json.Marshal(v) + return err +} + +func (r *TokenListResponse) GetMeta(out interface{}) error { + return json.Unmarshal(r.Meta, out) } // MustToken - returns Token from include collection. diff --git a/resources/model_token_attributes.go b/resources/model_token_attributes.go index 4c1ea65..bceec1f 100644 --- a/resources/model_token_attributes.go +++ b/resources/model_token_attributes.go @@ -5,6 +5,6 @@ package resources type TokenAttributes struct { - AccessToken Jwt `json:"accessToken"` - RefreshToken Jwt `json:"refreshToken"` + AccessToken Jwt `json:"access_token"` + RefreshToken Jwt `json:"refresh_token"` } diff --git a/resources/model_validation_result.go b/resources/model_validation_result.go index eb3d532..a12939c 100644 --- a/resources/model_validation_result.go +++ b/resources/model_validation_result.go @@ -4,6 +4,8 @@ package resources +import "encoding/json" + type ValidationResult struct { Key Attributes ValidationResultAttributes `json:"attributes"` @@ -17,6 +19,16 @@ type ValidationResultListResponse struct { Data []ValidationResult `json:"data"` Included Included `json:"included"` Links *Links `json:"links"` + Meta json.RawMessage `json:"meta,omitempty"` +} + +func (r *ValidationResultListResponse) PutMeta(v interface{}) (err error) { + r.Meta, err = json.Marshal(v) + return err +} + +func (r *ValidationResultListResponse) GetMeta(out interface{}) error { + return json.Unmarshal(r.Meta, out) } // MustValidationResult - returns ValidationResult from include collection.