diff --git a/api/api.yaml b/api/api.yaml index b67e56ff6..30a872a05 100644 --- a/api/api.yaml +++ b/api/api.yaml @@ -18,6 +18,8 @@ info: version: "1" tags: + - name: Public + description: Collection of endpoints that have to be public - name: Identity description: Collection of endpoints related to Identity - name: Credentials @@ -29,6 +31,7 @@ tags: - name: Key Management description: Collection of endpoints related to Key Management + paths: /status: @@ -139,9 +142,35 @@ paths: post: summary: Authentication Callback operationId: authCallback + deprecated: true + description: This endpoint is called when the QR code is scanned and the user is authenticated. A connection is created. + tags: + - Auth + parameters: + - $ref: '#/components/parameters/sessionID' + requestBody: + required: true + content: + text/plain: + schema: + type: string + example: jwz-token + responses: + '200': + description: ok + '400': + $ref: '#/components/responses/400' + '500': + $ref: '#/components/responses/500' + + /public/v2/authentication/callback: + post: + summary: Authentication Callback + operationId: authCallbackPublic description: This endpoint is called when the QR code is scanned and the user is authenticated. A connection is created. tags: - Auth + - Public parameters: - $ref: '#/components/parameters/sessionID' requestBody: @@ -906,6 +935,29 @@ paths: '500': $ref: '#/components/responses/500' + /public/v2/identities/{identifier}/credentials/revocation/status/{nonce}: + get: + summary: Get Revocation Status + operationId: GetRevocationStatusV2Public + description: Endpoint to get the revocation status + tags: + - Credentials + - Public + parameters: + - $ref: '#/components/parameters/pathIdentifier' + - $ref: '#/components/parameters/pathNonce' + responses: + '200': + description: Proof + content: + application/json: + schema: + $ref: '#/components/schemas/RevocationStatusResponse' + '400': + $ref: '#/components/responses/400' + '500': + $ref: '#/components/responses/500' + /v2/identities/{identifier}/credentials/{id}/offer: get: summary: Get Credentials Offer @@ -953,6 +1005,7 @@ paths: summary: Agent operationId: Agent description: Identity Agent Endpoint + deprecated: true tags: - Agent requestBody: @@ -1001,12 +1054,39 @@ paths: '500': $ref: '#/components/responses/500' + /public/v2/agent: + post: + summary: Agent + operationId: AgentPublic + description: Identity Agent Endpoint + tags: + - Agent + - Public + requestBody: + required: true + content: + text/plain: + schema: + type: string + example: jwz-token + responses: + '200': + description: TBD + content: + application/json: + schema: + $ref: '#/components/schemas/AgentResponse' + '400': + $ref: '#/components/responses/400' + '500': + $ref: '#/components/responses/500' /v2/qr-store: get: summary: Get QrCode from store operationId: GetQrFromStore description: Returns a previously generated QR code via url shortener method + deprecated: true tags: - QR Store parameters: @@ -1040,6 +1120,45 @@ paths: '500': $ref: '#/components/responses/500' + /public/v2/qr-store: + get: + summary: Get QrCode from store + operationId: GetQrFromStorePublic + description: Returns a previously generated QR code via url shortener method + tags: + - QR Store + - Public + parameters: + - in: query + name: id + schema: + type: string + x-go-type: uuid.UUID + x-go-type-import: + name: uuid + path: github.com/google/uuid + example: 8edd8112-c415-11ed-b036-debe37e1cbd6 + - in: query + name: issuer + schema: + type: string + + responses: + '200': + description: A json to generate a QR code + content: + application/json: + schema: + type: object + '400': + $ref: '#/components/responses/400' + '410': + $ref: '#/components/responses/410' + '404': + $ref: '#/components/responses/404' + '500': + $ref: '#/components/responses/500' + #schemas: /v2/identities/{identifier}/schemas: post: @@ -1314,8 +1433,40 @@ paths: summary: Create Link QR Code Callback operationId: CreateLinkQrCodeCallback description: Process the callback from the QR code link + deprecated: true + tags: + - Links + parameters: + - $ref: '#/components/parameters/pathIdentifier' + - $ref: '#/components/parameters/linkID' + requestBody: + required: true + content: + text/plain: + schema: + type: string + example: jwz-token + responses: + '200': + description: | + Return the offer for fetching the credential if the link was created for a Signature Credential or just 200 http status if the link was created for MTP Credential. + content: + application/json: + schema: + $ref: '#/components/schemas/Offer' + '400': + $ref: '#/components/responses/400' + '500': + $ref: '#/components/responses/500' + + /public/v2/identities/{identifier}/credentials/links/callback: + post: + summary: Create Link QR Code Callback + operationId: CreateLinkQrCodeCallbackPublic + description: Process the callback from the QR code link tags: - Links + - Public parameters: - $ref: '#/components/parameters/pathIdentifier' - $ref: '#/components/parameters/linkID' diff --git a/internal/api/agent.go b/internal/api/agent.go index 2c8684449..9aecc9cca 100644 --- a/internal/api/agent.go +++ b/internal/api/agent.go @@ -77,3 +77,23 @@ func (s *Server) AgentV1(ctx context.Context, request AgentV1RequestObject) (Age Type: string(agent.Type), }, nil } + +// AgentPublic is the controller to fetch credentials from mobile +func (s *Server) AgentPublic(ctx context.Context, request AgentPublicRequestObject) (AgentPublicResponseObject, error) { + response, err := s.Agent(ctx, AgentRequestObject(request)) + if err != nil { + return nil, err + } + + switch resp := response.(type) { + case Agent200JSONResponse: + return AgentPublic200JSONResponse(resp), nil + case Agent400JSONResponse: + return AgentPublic400JSONResponse(resp), nil + case Agent500JSONResponse: + return AgentPublic500JSONResponse(resp), nil + default: + log.Error(ctx, "agent public response", "err", "unexpected response type") + return AgentPublic500JSONResponse{N500JSONResponse{"unexpected response type"}}, nil + } +} diff --git a/internal/api/api.gen.go b/internal/api/api.gen.go index 41785cb7e..64b7111ef 100644 --- a/internal/api/api.gen.go +++ b/internal/api/api.gen.go @@ -796,6 +796,33 @@ type N500CreateIdentity struct { RequestID *string `json:"requestID,omitempty"` } +// AgentPublicTextBody defines parameters for AgentPublic. +type AgentPublicTextBody = string + +// AuthCallbackPublicTextBody defines parameters for AuthCallbackPublic. +type AuthCallbackPublicTextBody = string + +// AuthCallbackPublicParams defines parameters for AuthCallbackPublic. +type AuthCallbackPublicParams struct { + // SessionID Session ID e.g: 89d298fa-15a6-4a1d-ab13-d1069467eedd + SessionID SessionID `form:"sessionID" json:"sessionID"` +} + +// CreateLinkQrCodeCallbackPublicTextBody defines parameters for CreateLinkQrCodeCallbackPublic. +type CreateLinkQrCodeCallbackPublicTextBody = string + +// CreateLinkQrCodeCallbackPublicParams defines parameters for CreateLinkQrCodeCallbackPublic. +type CreateLinkQrCodeCallbackPublicParams struct { + // LinkID Session ID e.g: 89d298fa-15a6-4a1d-ab13-d1069467eedd + LinkID LinkID `form:"linkID" json:"linkID"` +} + +// GetQrFromStorePublicParams defines parameters for GetQrFromStorePublic. +type GetQrFromStorePublicParams struct { + Id *uuid.UUID `form:"id,omitempty" json:"id,omitempty"` + Issuer *string `form:"issuer,omitempty" json:"issuer,omitempty"` +} + // AgentV1TextBody defines parameters for AgentV1. type AgentV1TextBody = string @@ -992,6 +1019,15 @@ type AuthenticationParams struct { // AuthenticationParamsType defines parameters for Authentication. type AuthenticationParamsType string +// AgentPublicTextRequestBody defines body for AgentPublic for text/plain ContentType. +type AgentPublicTextRequestBody = AgentPublicTextBody + +// AuthCallbackPublicTextRequestBody defines body for AuthCallbackPublic for text/plain ContentType. +type AuthCallbackPublicTextRequestBody = AuthCallbackPublicTextBody + +// CreateLinkQrCodeCallbackPublicTextRequestBody defines body for CreateLinkQrCodeCallbackPublic for text/plain ContentType. +type CreateLinkQrCodeCallbackPublicTextRequestBody = CreateLinkQrCodeCallbackPublicTextBody + // AgentV1TextRequestBody defines body for AgentV1 for text/plain ContentType. type AgentV1TextRequestBody = AgentV1TextBody @@ -1051,6 +1087,21 @@ type ImportSchemaJSONRequestBody = ImportSchemaRequest // ServerInterface represents all server handlers. type ServerInterface interface { + // Agent + // (POST /public/v2/agent) + AgentPublic(w http.ResponseWriter, r *http.Request) + // Authentication Callback + // (POST /public/v2/authentication/callback) + AuthCallbackPublic(w http.ResponseWriter, r *http.Request, params AuthCallbackPublicParams) + // Create Link QR Code Callback + // (POST /public/v2/identities/{identifier}/credentials/links/callback) + CreateLinkQrCodeCallbackPublic(w http.ResponseWriter, r *http.Request, identifier PathIdentifier, params CreateLinkQrCodeCallbackPublicParams) + // Get Revocation Status + // (GET /public/v2/identities/{identifier}/credentials/revocation/status/{nonce}) + GetRevocationStatusV2Public(w http.ResponseWriter, r *http.Request, identifier PathIdentifier, nonce PathNonce) + // Get QrCode from store + // (GET /public/v2/qr-store) + GetQrFromStorePublic(w http.ResponseWriter, r *http.Request, params GetQrFromStorePublicParams) // Healthcheck // (GET /status) Health(w http.ResponseWriter, r *http.Request) @@ -1231,6 +1282,36 @@ type ServerInterface interface { type Unimplemented struct{} +// Agent +// (POST /public/v2/agent) +func (_ Unimplemented) AgentPublic(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotImplemented) +} + +// Authentication Callback +// (POST /public/v2/authentication/callback) +func (_ Unimplemented) AuthCallbackPublic(w http.ResponseWriter, r *http.Request, params AuthCallbackPublicParams) { + w.WriteHeader(http.StatusNotImplemented) +} + +// Create Link QR Code Callback +// (POST /public/v2/identities/{identifier}/credentials/links/callback) +func (_ Unimplemented) CreateLinkQrCodeCallbackPublic(w http.ResponseWriter, r *http.Request, identifier PathIdentifier, params CreateLinkQrCodeCallbackPublicParams) { + w.WriteHeader(http.StatusNotImplemented) +} + +// Get Revocation Status +// (GET /public/v2/identities/{identifier}/credentials/revocation/status/{nonce}) +func (_ Unimplemented) GetRevocationStatusV2Public(w http.ResponseWriter, r *http.Request, identifier PathIdentifier, nonce PathNonce) { + w.WriteHeader(http.StatusNotImplemented) +} + +// Get QrCode from store +// (GET /public/v2/qr-store) +func (_ Unimplemented) GetQrFromStorePublic(w http.ResponseWriter, r *http.Request, params GetQrFromStorePublicParams) { + w.WriteHeader(http.StatusNotImplemented) +} + // Healthcheck // (GET /status) func (_ Unimplemented) Health(w http.ResponseWriter, r *http.Request) { @@ -1588,6 +1669,166 @@ type ServerInterfaceWrapper struct { type MiddlewareFunc func(http.Handler) http.Handler +// AgentPublic operation middleware +func (siw *ServerInterfaceWrapper) AgentPublic(w http.ResponseWriter, r *http.Request) { + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.AgentPublic(w, r) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r) +} + +// AuthCallbackPublic operation middleware +func (siw *ServerInterfaceWrapper) AuthCallbackPublic(w http.ResponseWriter, r *http.Request) { + + var err error + + // Parameter object where we will unmarshal all parameters from the context + var params AuthCallbackPublicParams + + // ------------- Required query parameter "sessionID" ------------- + + if paramValue := r.URL.Query().Get("sessionID"); paramValue != "" { + + } else { + siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "sessionID"}) + return + } + + err = runtime.BindQueryParameter("form", true, true, "sessionID", r.URL.Query(), ¶ms.SessionID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sessionID", Err: err}) + return + } + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.AuthCallbackPublic(w, r, params) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r) +} + +// CreateLinkQrCodeCallbackPublic operation middleware +func (siw *ServerInterfaceWrapper) CreateLinkQrCodeCallbackPublic(w http.ResponseWriter, r *http.Request) { + + var err error + + // ------------- Path parameter "identifier" ------------- + var identifier PathIdentifier + + err = runtime.BindStyledParameterWithOptions("simple", "identifier", chi.URLParam(r, "identifier"), &identifier, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "identifier", Err: err}) + return + } + + // Parameter object where we will unmarshal all parameters from the context + var params CreateLinkQrCodeCallbackPublicParams + + // ------------- Required query parameter "linkID" ------------- + + if paramValue := r.URL.Query().Get("linkID"); paramValue != "" { + + } else { + siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "linkID"}) + return + } + + err = runtime.BindQueryParameter("form", true, true, "linkID", r.URL.Query(), ¶ms.LinkID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "linkID", Err: err}) + return + } + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.CreateLinkQrCodeCallbackPublic(w, r, identifier, params) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r) +} + +// GetRevocationStatusV2Public operation middleware +func (siw *ServerInterfaceWrapper) GetRevocationStatusV2Public(w http.ResponseWriter, r *http.Request) { + + var err error + + // ------------- Path parameter "identifier" ------------- + var identifier PathIdentifier + + err = runtime.BindStyledParameterWithOptions("simple", "identifier", chi.URLParam(r, "identifier"), &identifier, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "identifier", Err: err}) + return + } + + // ------------- Path parameter "nonce" ------------- + var nonce PathNonce + + err = runtime.BindStyledParameterWithOptions("simple", "nonce", chi.URLParam(r, "nonce"), &nonce, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true}) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "nonce", Err: err}) + return + } + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.GetRevocationStatusV2Public(w, r, identifier, nonce) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r) +} + +// GetQrFromStorePublic operation middleware +func (siw *ServerInterfaceWrapper) GetQrFromStorePublic(w http.ResponseWriter, r *http.Request) { + + var err error + + // Parameter object where we will unmarshal all parameters from the context + var params GetQrFromStorePublicParams + + // ------------- Optional query parameter "id" ------------- + + err = runtime.BindQueryParameter("form", true, false, "id", r.URL.Query(), ¶ms.Id) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err}) + return + } + + // ------------- Optional query parameter "issuer" ------------- + + err = runtime.BindQueryParameter("form", true, false, "issuer", r.URL.Query(), ¶ms.Issuer) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "issuer", Err: err}) + return + } + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.GetQrFromStorePublic(w, r, params) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r) +} + // Health operation middleware func (siw *ServerInterfaceWrapper) Health(w http.ResponseWriter, r *http.Request) { @@ -3869,6 +4110,21 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl ErrorHandlerFunc: options.ErrorHandlerFunc, } + r.Group(func(r chi.Router) { + r.Post(options.BaseURL+"/public/v2/agent", wrapper.AgentPublic) + }) + r.Group(func(r chi.Router) { + r.Post(options.BaseURL+"/public/v2/authentication/callback", wrapper.AuthCallbackPublic) + }) + r.Group(func(r chi.Router) { + r.Post(options.BaseURL+"/public/v2/identities/{identifier}/credentials/links/callback", wrapper.CreateLinkQrCodeCallbackPublic) + }) + r.Group(func(r chi.Router) { + r.Get(options.BaseURL+"/public/v2/identities/{identifier}/credentials/revocation/status/{nonce}", wrapper.GetRevocationStatusV2Public) + }) + r.Group(func(r chi.Router) { + r.Get(options.BaseURL+"/public/v2/qr-store", wrapper.GetQrFromStorePublic) + }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/status", wrapper.Health) }) @@ -4069,6 +4325,202 @@ type N500CreateIdentityJSONResponse struct { RequestID *string `json:"requestID,omitempty"` } +type AgentPublicRequestObject struct { + Body *AgentPublicTextRequestBody +} + +type AgentPublicResponseObject interface { + VisitAgentPublicResponse(w http.ResponseWriter) error +} + +type AgentPublic200JSONResponse AgentResponse + +func (response AgentPublic200JSONResponse) VisitAgentPublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + + return json.NewEncoder(w).Encode(response) +} + +type AgentPublic400JSONResponse struct{ N400JSONResponse } + +func (response AgentPublic400JSONResponse) VisitAgentPublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(400) + + return json.NewEncoder(w).Encode(response) +} + +type AgentPublic500JSONResponse struct{ N500JSONResponse } + +func (response AgentPublic500JSONResponse) VisitAgentPublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(500) + + return json.NewEncoder(w).Encode(response) +} + +type AuthCallbackPublicRequestObject struct { + Params AuthCallbackPublicParams + Body *AuthCallbackPublicTextRequestBody +} + +type AuthCallbackPublicResponseObject interface { + VisitAuthCallbackPublicResponse(w http.ResponseWriter) error +} + +type AuthCallbackPublic200Response struct { +} + +func (response AuthCallbackPublic200Response) VisitAuthCallbackPublicResponse(w http.ResponseWriter) error { + w.WriteHeader(200) + return nil +} + +type AuthCallbackPublic400JSONResponse struct{ N400JSONResponse } + +func (response AuthCallbackPublic400JSONResponse) VisitAuthCallbackPublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(400) + + return json.NewEncoder(w).Encode(response) +} + +type AuthCallbackPublic500JSONResponse struct{ N500JSONResponse } + +func (response AuthCallbackPublic500JSONResponse) VisitAuthCallbackPublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(500) + + return json.NewEncoder(w).Encode(response) +} + +type CreateLinkQrCodeCallbackPublicRequestObject struct { + Identifier PathIdentifier `json:"identifier"` + Params CreateLinkQrCodeCallbackPublicParams + Body *CreateLinkQrCodeCallbackPublicTextRequestBody +} + +type CreateLinkQrCodeCallbackPublicResponseObject interface { + VisitCreateLinkQrCodeCallbackPublicResponse(w http.ResponseWriter) error +} + +type CreateLinkQrCodeCallbackPublic200JSONResponse Offer + +func (response CreateLinkQrCodeCallbackPublic200JSONResponse) VisitCreateLinkQrCodeCallbackPublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + + return json.NewEncoder(w).Encode(response) +} + +type CreateLinkQrCodeCallbackPublic400JSONResponse struct{ N400JSONResponse } + +func (response CreateLinkQrCodeCallbackPublic400JSONResponse) VisitCreateLinkQrCodeCallbackPublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(400) + + return json.NewEncoder(w).Encode(response) +} + +type CreateLinkQrCodeCallbackPublic500JSONResponse struct{ N500JSONResponse } + +func (response CreateLinkQrCodeCallbackPublic500JSONResponse) VisitCreateLinkQrCodeCallbackPublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(500) + + return json.NewEncoder(w).Encode(response) +} + +type GetRevocationStatusV2PublicRequestObject struct { + Identifier PathIdentifier `json:"identifier"` + Nonce PathNonce `json:"nonce"` +} + +type GetRevocationStatusV2PublicResponseObject interface { + VisitGetRevocationStatusV2PublicResponse(w http.ResponseWriter) error +} + +type GetRevocationStatusV2Public200JSONResponse RevocationStatusResponse + +func (response GetRevocationStatusV2Public200JSONResponse) VisitGetRevocationStatusV2PublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + + return json.NewEncoder(w).Encode(response) +} + +type GetRevocationStatusV2Public400JSONResponse struct{ N400JSONResponse } + +func (response GetRevocationStatusV2Public400JSONResponse) VisitGetRevocationStatusV2PublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(400) + + return json.NewEncoder(w).Encode(response) +} + +type GetRevocationStatusV2Public500JSONResponse struct{ N500JSONResponse } + +func (response GetRevocationStatusV2Public500JSONResponse) VisitGetRevocationStatusV2PublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(500) + + return json.NewEncoder(w).Encode(response) +} + +type GetQrFromStorePublicRequestObject struct { + Params GetQrFromStorePublicParams +} + +type GetQrFromStorePublicResponseObject interface { + VisitGetQrFromStorePublicResponse(w http.ResponseWriter) error +} + +type GetQrFromStorePublic200JSONResponse map[string]interface{} + +func (response GetQrFromStorePublic200JSONResponse) VisitGetQrFromStorePublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(200) + + return json.NewEncoder(w).Encode(response) +} + +type GetQrFromStorePublic400JSONResponse struct{ N400JSONResponse } + +func (response GetQrFromStorePublic400JSONResponse) VisitGetQrFromStorePublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(400) + + return json.NewEncoder(w).Encode(response) +} + +type GetQrFromStorePublic404JSONResponse struct{ N404JSONResponse } + +func (response GetQrFromStorePublic404JSONResponse) VisitGetQrFromStorePublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(404) + + return json.NewEncoder(w).Encode(response) +} + +type GetQrFromStorePublic410JSONResponse struct{ N410JSONResponse } + +func (response GetQrFromStorePublic410JSONResponse) VisitGetQrFromStorePublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(410) + + return json.NewEncoder(w).Encode(response) +} + +type GetQrFromStorePublic500JSONResponse struct{ N500JSONResponse } + +func (response GetQrFromStorePublic500JSONResponse) VisitGetQrFromStorePublicResponse(w http.ResponseWriter) error { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(500) + + return json.NewEncoder(w).Encode(response) +} + type HealthRequestObject struct { } @@ -6528,6 +6980,21 @@ func (response Authentication500JSONResponse) VisitAuthenticationResponse(w http // StrictServerInterface represents all server handlers. type StrictServerInterface interface { + // Agent + // (POST /public/v2/agent) + AgentPublic(ctx context.Context, request AgentPublicRequestObject) (AgentPublicResponseObject, error) + // Authentication Callback + // (POST /public/v2/authentication/callback) + AuthCallbackPublic(ctx context.Context, request AuthCallbackPublicRequestObject) (AuthCallbackPublicResponseObject, error) + // Create Link QR Code Callback + // (POST /public/v2/identities/{identifier}/credentials/links/callback) + CreateLinkQrCodeCallbackPublic(ctx context.Context, request CreateLinkQrCodeCallbackPublicRequestObject) (CreateLinkQrCodeCallbackPublicResponseObject, error) + // Get Revocation Status + // (GET /public/v2/identities/{identifier}/credentials/revocation/status/{nonce}) + GetRevocationStatusV2Public(ctx context.Context, request GetRevocationStatusV2PublicRequestObject) (GetRevocationStatusV2PublicResponseObject, error) + // Get QrCode from store + // (GET /public/v2/qr-store) + GetQrFromStorePublic(ctx context.Context, request GetQrFromStorePublicRequestObject) (GetQrFromStorePublicResponseObject, error) // Healthcheck // (GET /status) Health(ctx context.Context, request HealthRequestObject) (HealthResponseObject, error) @@ -6733,6 +7200,160 @@ type strictHandler struct { options StrictHTTPServerOptions } +// AgentPublic operation middleware +func (sh *strictHandler) AgentPublic(w http.ResponseWriter, r *http.Request) { + var request AgentPublicRequestObject + + data, err := io.ReadAll(r.Body) + if err != nil { + sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't read body: %w", err)) + return + } + body := AgentPublicTextRequestBody(data) + request.Body = &body + + handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) { + return sh.ssi.AgentPublic(ctx, request.(AgentPublicRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "AgentPublic") + } + + response, err := handler(r.Context(), w, r, request) + + if err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } else if validResponse, ok := response.(AgentPublicResponseObject); ok { + if err := validResponse.VisitAgentPublicResponse(w); err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } + } else if response != nil { + sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response)) + } +} + +// AuthCallbackPublic operation middleware +func (sh *strictHandler) AuthCallbackPublic(w http.ResponseWriter, r *http.Request, params AuthCallbackPublicParams) { + var request AuthCallbackPublicRequestObject + + request.Params = params + + data, err := io.ReadAll(r.Body) + if err != nil { + sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't read body: %w", err)) + return + } + body := AuthCallbackPublicTextRequestBody(data) + request.Body = &body + + handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) { + return sh.ssi.AuthCallbackPublic(ctx, request.(AuthCallbackPublicRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "AuthCallbackPublic") + } + + response, err := handler(r.Context(), w, r, request) + + if err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } else if validResponse, ok := response.(AuthCallbackPublicResponseObject); ok { + if err := validResponse.VisitAuthCallbackPublicResponse(w); err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } + } else if response != nil { + sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response)) + } +} + +// CreateLinkQrCodeCallbackPublic operation middleware +func (sh *strictHandler) CreateLinkQrCodeCallbackPublic(w http.ResponseWriter, r *http.Request, identifier PathIdentifier, params CreateLinkQrCodeCallbackPublicParams) { + var request CreateLinkQrCodeCallbackPublicRequestObject + + request.Identifier = identifier + request.Params = params + + data, err := io.ReadAll(r.Body) + if err != nil { + sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't read body: %w", err)) + return + } + body := CreateLinkQrCodeCallbackPublicTextRequestBody(data) + request.Body = &body + + handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) { + return sh.ssi.CreateLinkQrCodeCallbackPublic(ctx, request.(CreateLinkQrCodeCallbackPublicRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "CreateLinkQrCodeCallbackPublic") + } + + response, err := handler(r.Context(), w, r, request) + + if err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } else if validResponse, ok := response.(CreateLinkQrCodeCallbackPublicResponseObject); ok { + if err := validResponse.VisitCreateLinkQrCodeCallbackPublicResponse(w); err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } + } else if response != nil { + sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response)) + } +} + +// GetRevocationStatusV2Public operation middleware +func (sh *strictHandler) GetRevocationStatusV2Public(w http.ResponseWriter, r *http.Request, identifier PathIdentifier, nonce PathNonce) { + var request GetRevocationStatusV2PublicRequestObject + + request.Identifier = identifier + request.Nonce = nonce + + handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) { + return sh.ssi.GetRevocationStatusV2Public(ctx, request.(GetRevocationStatusV2PublicRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "GetRevocationStatusV2Public") + } + + response, err := handler(r.Context(), w, r, request) + + if err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } else if validResponse, ok := response.(GetRevocationStatusV2PublicResponseObject); ok { + if err := validResponse.VisitGetRevocationStatusV2PublicResponse(w); err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } + } else if response != nil { + sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response)) + } +} + +// GetQrFromStorePublic operation middleware +func (sh *strictHandler) GetQrFromStorePublic(w http.ResponseWriter, r *http.Request, params GetQrFromStorePublicParams) { + var request GetQrFromStorePublicRequestObject + + request.Params = params + + handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) { + return sh.ssi.GetQrFromStorePublic(ctx, request.(GetQrFromStorePublicRequestObject)) + } + for _, middleware := range sh.middlewares { + handler = middleware(handler, "GetQrFromStorePublic") + } + + response, err := handler(r.Context(), w, r, request) + + if err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } else if validResponse, ok := response.(GetQrFromStorePublicResponseObject); ok { + if err := validResponse.VisitGetQrFromStorePublicResponse(w); err != nil { + sh.options.ResponseErrorHandlerFunc(w, r, err) + } + } else if response != nil { + sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response)) + } +} + // Health operation middleware func (sh *strictHandler) Health(w http.ResponseWriter, r *http.Request) { var request HealthRequestObject diff --git a/internal/api/authentication.go b/internal/api/authentication.go index 5a10081d8..bedc9975f 100644 --- a/internal/api/authentication.go +++ b/internal/api/authentication.go @@ -26,6 +26,28 @@ func (s *Server) AuthCallback(ctx context.Context, request AuthCallbackRequestOb return AuthCallback200Response{}, nil } +// AuthCallbackPublic receives the authentication information of a holder +func (s *Server) AuthCallbackPublic(ctx context.Context, request AuthCallbackPublicRequestObject) (AuthCallbackPublicResponseObject, error) { + resp, err := s.AuthCallback(ctx, AuthCallbackRequestObject{ + Body: request.Body, + Params: AuthCallbackParams(request.Params), + }) + if err != nil { + return nil, err + } + + switch response := resp.(type) { + case AuthCallback200Response: + return AuthCallbackPublic200Response{}, nil + case AuthCallback400JSONResponse: + return AuthCallbackPublic400JSONResponse(response), nil + case AuthCallback500JSONResponse: + return AuthCallbackPublic500JSONResponse(response), nil + default: + return AuthCallbackPublic500JSONResponse{N500JSONResponse{"unexpected response"}}, nil + } +} + // Authentication returns the qr code for authenticating a user func (s *Server) Authentication(ctx context.Context, req AuthenticationRequestObject) (AuthenticationResponseObject, error) { did, err := w3c.ParseDID(req.Identifier) diff --git a/internal/api/authentication_test.go b/internal/api/authentication_test.go index adb23f1dd..a8680e94a 100644 --- a/internal/api/authentication_test.go +++ b/internal/api/authentication_test.go @@ -199,7 +199,7 @@ func TestServer_AuthQRCode(t *testing.T) { qrWithLink: true, response: protocol.AuthorizationRequestMessage{ Body: protocol.AuthorizationRequestMessageBody{ - CallbackURL: "https://testing.env/v2/authentication/callback?sessionID=", + CallbackURL: "https://testing.env/public/v2/authentication/callback?sessionID=", Reason: "authentication", Scope: make([]protocol.ZeroKnowledgeProofRequest, 0), }, @@ -217,7 +217,7 @@ func TestServer_AuthQRCode(t *testing.T) { qrWithLink: true, response: protocol.AuthorizationRequestMessage{ Body: protocol.AuthorizationRequestMessageBody{ - CallbackURL: "https://testing.env/v2/authentication/callback?sessionID=", + CallbackURL: "https://testing.env/public/v2/authentication/callback?sessionID=", Reason: "authentication", Scope: make([]protocol.ZeroKnowledgeProofRequest, 0), }, @@ -235,7 +235,7 @@ func TestServer_AuthQRCode(t *testing.T) { qrWithLink: false, response: protocol.AuthorizationRequestMessage{ Body: protocol.AuthorizationRequestMessageBody{ - CallbackURL: "https://testing.env/v2/authentication/callback?sessionID=", + CallbackURL: "https://testing.env/public/v2/authentication/callback?sessionID=", Reason: "authentication", Scope: make([]protocol.ZeroKnowledgeProofRequest, 0), }, diff --git a/internal/api/credentials.go b/internal/api/credentials.go index ae4137f74..aae085f65 100644 --- a/internal/api/credentials.go +++ b/internal/api/credentials.go @@ -218,8 +218,26 @@ func (s *Server) GetRevocationStatusV2(ctx context.Context, request GetRevocatio return GetRevocationStatusV2200JSONResponse(response), nil case GetRevocationStatus500JSONResponse: return GetRevocationStatusV2500JSONResponse(response), nil + default: + log.Error(ctx, "getting revocation status", "err", "unexpected response type") + return GetRevocationStatusV2500JSONResponse{N500JSONResponse{"unexpected response type"}}, nil + } +} + +// GetRevocationStatusV2Public is the controller to get revocation status +func (s *Server) GetRevocationStatusV2Public(ctx context.Context, request GetRevocationStatusV2PublicRequestObject) (GetRevocationStatusV2PublicResponseObject, error) { + resp, err := s.GetRevocationStatusV2(ctx, GetRevocationStatusV2RequestObject(request)) + if err != nil { + return nil, err + } + switch response := resp.(type) { + case GetRevocationStatusV2200JSONResponse: + return GetRevocationStatusV2Public200JSONResponse(response), nil + case GetRevocationStatusV2500JSONResponse: + return GetRevocationStatusV2Public500JSONResponse(response), nil + default: + return GetRevocationStatusV2Public500JSONResponse{N500JSONResponse{"unexpected response type"}}, nil } - return nil, nil } // GetCredentials returns a collection of credentials that matches the request. diff --git a/internal/api/credentials_test.go b/internal/api/credentials_test.go index d02b4156e..1edc2a139 100644 --- a/internal/api/credentials_test.go +++ b/internal/api/credentials_test.go @@ -712,7 +712,7 @@ func TestServer_GetCredentialQrCode(t *testing.T) { _, err = url.Parse(values.Get("request_uri")) assert.NoError(t, err) case "deepLink": - assert.True(t, strings.HasPrefix(response.UniversalLink, "iden3comm://?request_uri="+url.QueryEscape("https://testing.env/v2/qr-store?id="))) + assert.True(t, strings.HasPrefix(response.UniversalLink, "iden3comm://?request_uri="+url.QueryEscape("https://testing.env/public/v2/qr-store?id="))) parsedURL, err := url.Parse(strings.Replace(response.UniversalLink, "iden3comm://", "http://anurl", 1)) require.NoError(t, err) queryParams := parsedURL.Query() diff --git a/internal/api/links.go b/internal/api/links.go index 74d5b2ea2..73b55e930 100644 --- a/internal/api/links.go +++ b/internal/api/links.go @@ -127,6 +127,33 @@ func (s *Server) CreateLinkQrCodeCallback(ctx context.Context, request CreateLin return offerResponse, nil } +// CreateLinkQrCodeCallbackPublic - Callback endpoint for the link qr code creation. +func (s *Server) CreateLinkQrCodeCallbackPublic(ctx context.Context, request CreateLinkQrCodeCallbackPublicRequestObject) (CreateLinkQrCodeCallbackPublicResponseObject, error) { + resp, err := s.CreateLinkQrCodeCallback(ctx, CreateLinkQrCodeCallbackRequestObject{ + Identifier: request.Identifier, + Params: CreateLinkQrCodeCallbackParams(request.Params), + Body: request.Body, + }) + if err != nil { + return nil, err + } + + switch response := resp.(type) { + case CreateLinkQrCodeCallback200JSONResponse: + return CreateLinkQrCodeCallbackPublic200JSONResponse(response), nil + case CreateLinkQrCodeCallback400JSONResponse: + return CreateLinkQrCodeCallbackPublic400JSONResponse(response), nil + case CreateLinkQrCodeCallback500JSONResponse: + return CreateLinkQrCodeCallbackPublic500JSONResponse(response), nil + default: + return CreateLinkQrCodeCallbackPublic500JSONResponse{ + N500JSONResponse: N500JSONResponse{ + Message: "unexpected response", + }, + }, nil + } +} + // DeleteLink - delete a link func (s *Server) DeleteLink(ctx context.Context, request DeleteLinkRequestObject) (DeleteLinkResponseObject, error) { issuerDID, err := w3c.ParseDID(request.Identifier) diff --git a/internal/api/links_test.go b/internal/api/links_test.go index 415b6e9d2..87d5b1b1c 100644 --- a/internal/api/links_test.go +++ b/internal/api/links_test.go @@ -996,7 +996,7 @@ func TestServer_CreateLinkOffer(t *testing.T) { switch tc.expected.httpCode { case http.StatusOK: - callBack := cfg.ServerUrl + fmt.Sprintf("/v2/identities/%s/credentials/links/callback?", iden.Identifier) + callBack := cfg.ServerUrl + fmt.Sprintf("/public/v2/identities/%s/credentials/links/callback?", iden.Identifier) var response CreateLinkOffer200JSONResponse require.NoError(t, json.Unmarshal(rr.Body.Bytes(), &response)) diff --git a/internal/api/qrcode.go b/internal/api/qrcode.go index 593fb69c8..0757bd36f 100644 --- a/internal/api/qrcode.go +++ b/internal/api/qrcode.go @@ -47,3 +47,38 @@ func (s *Server) GetQrFromStore(ctx context.Context, request GetQrFromStoreReque } return NewQrContentResponse(body), nil } + +// GetQrFromStorePublic is the controller to get qr bodies +func (s *Server) GetQrFromStorePublic(ctx context.Context, request GetQrFromStorePublicRequestObject) (GetQrFromStorePublicResponseObject, error) { + req := GetQrFromStoreRequestObject{ + Params: GetQrFromStoreParams{ + Id: request.Params.Id, + Issuer: request.Params.Issuer, + }, + } + resp, err := s.GetQrFromStore(ctx, req) + if err != nil { + return nil, err + } + + switch response := resp.(type) { + case GetQrFromStore400JSONResponse: + return GetQrFromStorePublic400JSONResponse(response), nil + case GetQrFromStore404JSONResponse: + return GetQrFromStorePublic404JSONResponse(response), nil + case GetQrFromStore410JSONResponse: + return GetQrFromStorePublic410JSONResponse(response), nil + case GetQrFromStore500JSONResponse: + return GetQrFromStorePublic500JSONResponse(response), nil + case GetQrFromStoreResponseObject: + r, ok := resp.(GetQrFromStorePublicResponseObject) + if !ok { + log.Error(ctx, "unexpected response type", "response", response) + return GetQrFromStorePublic500JSONResponse{N500JSONResponse{"unexpected response type"}}, nil + } + return r, nil + default: + log.Error(ctx, "unexpected response type", "response", response) + return GetQrFromStorePublic500JSONResponse{N500JSONResponse{"unexpected response type"}}, nil + } +} diff --git a/internal/api/qrcode_test.go b/internal/api/qrcode_test.go index 1dd2eb7c9..5d4906812 100644 --- a/internal/api/qrcode_test.go +++ b/internal/api/qrcode_test.go @@ -132,7 +132,7 @@ func TestServer_GetQrFromStore(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { rr := httptest.NewRecorder() - url := fmt.Sprintf("/v2/qr-store?id=%s&issuer=%s", tc.request.Params.Id, *tc.request.Params.Issuer) + url := fmt.Sprintf("/public/v2/qr-store?id=%s&issuer=%s", tc.request.Params.Id, *tc.request.Params.Issuer) req, err := http.NewRequest(http.MethodGet, url, nil) assert.NoError(t, err) handler.ServeHTTP(rr, req) diff --git a/internal/api/responses.go b/internal/api/responses.go index c5dcb63de..d6813e347 100644 --- a/internal/api/responses.go +++ b/internal/api/responses.go @@ -32,6 +32,11 @@ func (response CustomQrContentResponse) VisitGetQrFromStoreResponse(w http.Respo return response.visit(w) } +// VisitGetQrFromStorePublicResponse satisfies the AuthQRCodeResponseObject +func (response CustomQrContentResponse) VisitGetQrFromStorePublicResponse(w http.ResponseWriter) error { + return response.visit(w) +} + func (response CustomQrContentResponse) visit(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) diff --git a/internal/core/ports/identity_service.go b/internal/core/ports/identity_service.go index c0d179858..9155b77e6 100644 --- a/internal/core/ports/identity_service.go +++ b/internal/core/ports/identity_service.go @@ -16,7 +16,7 @@ import ( const ( // AuthorizationRequestQRCallbackURL is the URL to call back after the user has authenticated - AuthorizationRequestQRCallbackURL = "%s/v2/authentication/callback?sessionID=%s" + AuthorizationRequestQRCallbackURL = "%s/public/v2/authentication/callback?sessionID=%s" ) // DIDCreationOptions represents options for DID creation diff --git a/internal/core/ports/link_service.go b/internal/core/ports/link_service.go index 332668a30..d41359c4a 100644 --- a/internal/core/ports/link_service.go +++ b/internal/core/ports/link_service.go @@ -28,12 +28,12 @@ type CreateQRCodeResponse struct { type LinkStatus string const ( - LinkAll LinkStatus = "all" // LinkAll : All links - LinkActive LinkStatus = "active" // LinkActive : Active links - LinkInactive LinkStatus = "inactive" // LinkInactive : Inactive links - LinkExceeded LinkStatus = "exceeded" // LinkExceeded : Expired links or with more credentials issued than expected - AgentUrl = "%s/v2/agent" // AgentUrl : Agent URL - LinksCallbackURL = "%s/v2/identities/%s/credentials/links/callback?linkID=%s" // LinksCallbackURL : Links callback URL + LinkAll LinkStatus = "all" // LinkAll : All links + LinkActive LinkStatus = "active" // LinkActive : Active links + LinkInactive LinkStatus = "inactive" // LinkInactive : Inactive links + LinkExceeded LinkStatus = "exceeded" // LinkExceeded : Expired links or with more credentials issued than expected + AgentUrl = "%s/public/v2/agent" // AgentUrl : Agent URL + LinksCallbackURL = "%s/public/v2/identities/%s/credentials/links/callback?linkID=%s" // LinksCallbackURL : Links callback URL ) // LinkTypeReqFromString constructs a LinkStatus from a string diff --git a/internal/core/services/identity_test.go b/internal/core/services/identity_test.go index 30d529edb..d40a339aa 100644 --- a/internal/core/services/identity_test.go +++ b/internal/core/services/identity_test.go @@ -93,7 +93,7 @@ func Test_identity_CreateIdentity(t *testing.T) { assert.NotNil(t, identity.AuthCoreClaimRevocationStatus) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, fmt.Sprintf("%s/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, fmt.Sprintf("%s/public/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) assert.NotNil(t, identity.State.State) assert.Equal(t, "confirmed", string(identity.State.Status)) if tc.options.KeyType == ETH { @@ -165,7 +165,7 @@ func Test_identity_CreateIdentityWithRHSNone(t *testing.T) { assert.NotNil(t, identity.AuthCoreClaimRevocationStatus) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, fmt.Sprintf("%s/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, fmt.Sprintf("%s/public/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) assert.NotNil(t, identity.State.State) assert.Equal(t, "confirmed", string(identity.State.Status)) assert.NotNil(t, identity.State.ClaimsTreeRoot) @@ -201,7 +201,7 @@ func Test_identity_CreateIdentityWithRHSNone(t *testing.T) { assert.NotNil(t, identity.AuthCoreClaimRevocationStatus) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, fmt.Sprintf("%s/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, fmt.Sprintf("%s/public/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) assert.NotNil(t, identity.State.State) assert.Equal(t, "confirmed", string(identity.State.Status)) rhsFactoryMock.AssertNumberOfCalls(t, "BuildPublishers", 0) @@ -229,7 +229,7 @@ func Test_identity_CreateIdentityWithRHSNone(t *testing.T) { assert.NotNil(t, identity.AuthCoreClaimRevocationStatus) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, fmt.Sprintf("%s/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, fmt.Sprintf("%s/public/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) assert.NotNil(t, identity.State.State) assert.Equal(t, "confirmed", string(identity.State.Status)) assert.NotNil(t, identity.State.ClaimsTreeRoot) @@ -257,7 +257,7 @@ func Test_identity_CreateIdentityWithRHSNone(t *testing.T) { assert.NotNil(t, identity.AuthCoreClaimRevocationStatus) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, "http://localhost:3001/v2/agent", identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, "http://localhost:3001/public/v2/agent", identity.AuthCoreClaimRevocationStatus.ID) assert.NotNil(t, identity.State.State) assert.Equal(t, "confirmed", string(identity.State.Status)) assert.NotNil(t, identity.State.ClaimsTreeRoot) @@ -300,7 +300,7 @@ func Test_identity_CreateIdentityWithRHSOffChain(t *testing.T) { assert.NotNil(t, identity.AuthCoreClaimRevocationStatus) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, fmt.Sprintf("%s/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, fmt.Sprintf("%s/public/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) assert.NotNil(t, identity.State.State) assert.Equal(t, "confirmed", string(identity.State.Status)) assert.NotNil(t, identity.State.ClaimsTreeRoot) @@ -336,7 +336,7 @@ func Test_identity_CreateIdentityWithRHSOffChain(t *testing.T) { assert.NotNil(t, identity.AuthCoreClaimRevocationStatus) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, fmt.Sprintf("%s/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, fmt.Sprintf("%s/public/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) assert.NotNil(t, identity.State.State) assert.Equal(t, "confirmed", string(identity.State.Status)) rhsFactoryMock.AssertNumberOfCalls(t, "BuildPublishers", 0) @@ -364,7 +364,7 @@ func Test_identity_CreateIdentityWithRHSOffChain(t *testing.T) { assert.NotNil(t, identity.AuthCoreClaimRevocationStatus) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, fmt.Sprintf("%s/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, fmt.Sprintf("%s/public/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) assert.NotNil(t, identity.State.State) assert.Equal(t, "confirmed", string(identity.State.Status)) assert.NotNil(t, identity.State.ClaimsTreeRoot) @@ -772,7 +772,7 @@ func Test_identity_RotateKey(t *testing.T) { assert.NotNil(t, identity.AuthCoreClaimRevocationStatus) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, fmt.Sprintf("%s/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, fmt.Sprintf("%s/public/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) assert.NotNil(t, identity.State.State) assert.Equal(t, "confirmed", string(identity.State.Status)) if tc.options.KeyType == ETH { @@ -784,7 +784,7 @@ func Test_identity_RotateKey(t *testing.T) { t.Errorf("invalid key type") } assert.Equal(t, string(verifiable.Iden3commRevocationStatusV1), identity.AuthCoreClaimRevocationStatus.Type) - assert.Equal(t, fmt.Sprintf("%s/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) + assert.Equal(t, fmt.Sprintf("%s/public/v2/agent", cfg.ServerUrl), identity.AuthCoreClaimRevocationStatus.ID) assert.Equal(t, uint(0), identity.AuthCoreClaimRevocationStatus.RevocationNonce) authCoreClaimNew, err := claimsRepo.FindOneClaimBySchemaHash(ctx, storage.Pgx, did, string(authHash)) diff --git a/internal/core/services/link_test.go b/internal/core/services/link_test.go index 1550e61fd..4d860b133 100644 --- a/internal/core/services/link_test.go +++ b/internal/core/services/link_test.go @@ -127,7 +127,7 @@ func Test_link_issueClaim(t *testing.T) { Typ: packers.MediaTypePlainMessage, Type: protocol.CredentialOfferMessageType, Body: protocol.CredentialsOfferMessageBody{ - URL: "host_url/v2/agent", + URL: "host_url/public/v2/agent", Credentials: []protocol.CredentialOffer{ { ID: "1", diff --git a/internal/qrlink/link.go b/internal/qrlink/link.go index fa69c3e54..723555fa8 100644 --- a/internal/qrlink/link.go +++ b/internal/qrlink/link.go @@ -9,8 +9,8 @@ import ( ) const ( - requestURI = "%s/v2/qr-store?id=%s" - requestURIWithIssuer = "%s/v2/qr-store?id=%s&issuer=%s" + requestURI = "%s/public/v2/qr-store?id=%s" + requestURIWithIssuer = "%s/public/v2/qr-store?id=%s&issuer=%s" ) // NewDeepLink creates a deep link diff --git a/internal/qrlink/link_test.go b/internal/qrlink/link_test.go index 2121ee796..da8ca7157 100644 --- a/internal/qrlink/link_test.go +++ b/internal/qrlink/link_test.go @@ -16,7 +16,7 @@ func TestNewUniversal(t *testing.T) { require.NoError(t, err) issuerDID, err := w3c.ParseDID("did:iden3:polygon:amoy:x7xjFDkoCW7MSQUZQwrXhyU5HqQ8npzEdAvHmBjqx") require.NoError(t, err) - expected := "https://wallet-dev.privado.id/#request_uri=https%3A%2F%2Fissuer-node-core-api-testing.privado.id%2Fv2%2Fqr-store%3Fid%3D1f209581-ab1d-426d-88d9-2b545bdb851d%26issuer%3Ddid%3Aiden3%3Apolygon%3Aamoy%3Ax7xjFDkoCW7MSQUZQwrXhyU5HqQ8npzEdAvHmBjqx" + expected := "https://wallet-dev.privado.id/#request_uri=https%3A%2F%2Fissuer-node-core-api-testing.privado.id%2Fpublic%2Fv2%2Fqr-store%3Fid%3D1f209581-ab1d-426d-88d9-2b545bdb851d%26issuer%3Ddid%3Aiden3%3Apolygon%3Aamoy%3Ax7xjFDkoCW7MSQUZQwrXhyU5HqQ8npzEdAvHmBjqx" got := NewUniversal(baseURL, hostURL, id, issuerDID) assert.Equal(t, expected, got) } @@ -27,7 +27,7 @@ func TestDeepLink(t *testing.T) { require.NoError(t, err) issuerDID, err := w3c.ParseDID("did:iden3:polygon:amoy:x7xjFDkoCW7MSQUZQwrXhyU5HqQ8npzEdAvHmBjqx") require.NoError(t, err) - expected := "iden3comm://?request_uri=https%3A%2F%2Fissuer-node-core-api-testing.privado.id%2Fv2%2Fqr-store%3Fid%3D1f209581-ab1d-426d-88d9-2b545bdb851d%26issuer%3Ddid%3Aiden3%3Apolygon%3Aamoy%3Ax7xjFDkoCW7MSQUZQwrXhyU5HqQ8npzEdAvHmBjqx" + expected := "iden3comm://?request_uri=https%3A%2F%2Fissuer-node-core-api-testing.privado.id%2Fpublic%2Fv2%2Fqr-store%3Fid%3D1f209581-ab1d-426d-88d9-2b545bdb851d%26issuer%3Ddid%3Aiden3%3Apolygon%3Aamoy%3Ax7xjFDkoCW7MSQUZQwrXhyU5HqQ8npzEdAvHmBjqx" got := NewDeepLink(hostURL, id, issuerDID) assert.Equal(t, expected, got) } diff --git a/internal/revocationstatus/iden3_reverse_sparse_merkletree_proof_resolver.go b/internal/revocationstatus/iden3_reverse_sparse_merkletree_proof_resolver.go index 951b31a39..0e4bad3f4 100644 --- a/internal/revocationstatus/iden3_reverse_sparse_merkletree_proof_resolver.go +++ b/internal/revocationstatus/iden3_reverse_sparse_merkletree_proof_resolver.go @@ -17,7 +17,7 @@ func (r *iden3ReverseSparseMerkleTreeProofResolver) resolve(credentialStatusSett Type: verifiable.Iden3ReverseSparseMerkleTreeProof, RevocationNonce: nonce, StatusIssuer: &verifiable.CredentialStatus{ - ID: fmt.Sprintf("%s/v2/agent", credentialStatusSettings.Iden3CommAgentStatus), + ID: fmt.Sprintf(agentURL, credentialStatusSettings.Iden3CommAgentStatus), Type: verifiable.Iden3commRevocationStatusV1, RevocationNonce: nonce, }, diff --git a/internal/revocationstatus/iden3_revocation_status_v1.go b/internal/revocationstatus/iden3_revocation_status_v1.go index 2fc089ed2..e5404ee15 100644 --- a/internal/revocationstatus/iden3_revocation_status_v1.go +++ b/internal/revocationstatus/iden3_revocation_status_v1.go @@ -13,7 +13,7 @@ type iden3CommRevocationStatusV1Resolver struct{} func (r *iden3CommRevocationStatusV1Resolver) resolve(credentialStatusSettings network.RhsSettings, _ w3c.DID, nonce uint64, _ string) *verifiable.CredentialStatus { return &verifiable.CredentialStatus{ - ID: fmt.Sprintf("%s/v2/agent", credentialStatusSettings.Iden3CommAgentStatus), + ID: fmt.Sprintf(agentURL, credentialStatusSettings.Iden3CommAgentStatus), Type: verifiable.Iden3commRevocationStatusV1, RevocationNonce: nonce, } diff --git a/internal/revocationstatus/resolver.go b/internal/revocationstatus/resolver.go index e031e9327..16c4d386c 100644 --- a/internal/revocationstatus/resolver.go +++ b/internal/revocationstatus/resolver.go @@ -11,7 +11,10 @@ import ( "github.com/polygonid/sh-id-platform/internal/network" ) -const resolversLength = 3 +const ( + resolversLength = 3 + agentURL = "%s/public/v2/agent" +) type revocationCredentialStatusResolver interface { resolve(credentialStatusSettings network.RhsSettings, issuerDID w3c.DID, nonce uint64, issuerState string) *verifiable.CredentialStatus diff --git a/internal/revocationstatus/resolver_test.go b/internal/revocationstatus/resolver_test.go index a359cd1b5..859ccb1ec 100644 --- a/internal/revocationstatus/resolver_test.go +++ b/internal/revocationstatus/resolver_test.go @@ -51,7 +51,7 @@ func TestRevocationStatusResolver_GetCredentialRevocationStatus(t *testing.T) { RevocationNonce: 12345, StatusIssuer: &verifiable.CredentialStatus{ Type: verifiable.Iden3commRevocationStatusV1, - ID: "https://issuer-node.privado.id/v2/agent", + ID: "https://issuer-node.privado.id/public/v2/agent", RevocationNonce: 12345, }, }, @@ -75,7 +75,7 @@ func TestRevocationStatusResolver_GetCredentialRevocationStatus(t *testing.T) { RevocationNonce: 12345, StatusIssuer: &verifiable.CredentialStatus{ Type: verifiable.Iden3commRevocationStatusV1, - ID: "https://issuer-node.privado.id/v2/agent", + ID: "https://issuer-node.privado.id/public/v2/agent", RevocationNonce: 12345, }, },