diff --git a/_examples/idv/handlers.session.go b/_examples/idv/handlers.session.go index 804c673d..938833d9 100644 --- a/_examples/idv/handlers.session.go +++ b/_examples/idv/handlers.session.go @@ -230,3 +230,30 @@ func showErrorPage(c *gin.Context) { "error.html") return } + +func getSessionConfigurationHandler(c *gin.Context) { + sessionID := c.Query("SessionID") // Get the SessionID from the query parameters + err := ensureDocScanClientInitialised() + if err != nil { + c.HTML( + http.StatusUnprocessableEntity, + "error.html", + gin.H{ + "ErrorTitle": "error setting the Doc Scan (IDV) Client", + "ErrorMessage": err.Error()}) + return + } + + if sessionID == "" { + c.JSON(http.StatusBadRequest, gin.H{"error": "Missing SessionID query parameter"}) + return + } + + sessionConfig, err := client.GetSessionConfiguration(sessionID) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to retrieve session configuration", "details": err.Error()}) + return + } + + c.JSON(http.StatusOK, sessionConfig) +} diff --git a/_examples/idv/routes.go b/_examples/idv/routes.go index 9112caa0..1ef64156 100644 --- a/_examples/idv/routes.go +++ b/_examples/idv/routes.go @@ -14,4 +14,5 @@ func initializeRoutes() { router.GET("/media", getMedia) router.GET("/privacy-policy", showPrivacyPolicyPage) router.GET("/error", showErrorPage) + router.GET("/config", getSessionConfigurationHandler) } diff --git a/docscan/client.go b/docscan/client.go index c4aa82dc..41cbab68 100644 --- a/docscan/client.go +++ b/docscan/client.go @@ -12,6 +12,7 @@ import ( "strings" "github.com/getyoti/yoti-go-sdk/v3/cryptoutil" + "github.com/getyoti/yoti-go-sdk/v3/docscan/config" "github.com/getyoti/yoti-go-sdk/v3/docscan/session/create" "github.com/getyoti/yoti-go-sdk/v3/docscan/session/retrieve" "github.com/getyoti/yoti-go-sdk/v3/docscan/supported" @@ -291,3 +292,40 @@ func marshalJSON(jsonMarshaler jsonMarshaler, v interface{}) ([]byte, error) { } return json.Marshal(v) } + +const getSessionConfigurationPath = "/sessions/%s/configuration" + +// GetSessionConfiguration retrieves the configuration of a previously created Yoti Doc Scan (IDV) session +func (c *Client) GetSessionConfiguration(sessionID string) (*config.SessionConfigurationResponse, error) { + if sessionID == "" { + return nil, fmt.Errorf(mustNotBeEmptyString, "sessionID") + } + + request, err := (&requests.SignedRequest{ + Key: c.Key, + HTTPMethod: http.MethodGet, + BaseURL: c.apiURL, + Endpoint: fmt.Sprintf(getSessionConfigurationPath, sessionID), + Params: map[string]string{"sdkID": c.SdkID}, + }).Request() + if err != nil { + return nil, err + } + + var response *http.Response + response, err = requests.Execute(c.HTTPClient, request, yotierror.DefaultHTTPErrorMessages) + if err != nil { + return nil, err + } + + var responseBytes []byte + responseBytes, err = io.ReadAll(response.Body) + if err != nil { + return nil, err + } + + var result config.SessionConfigurationResponse + err = json.Unmarshal(responseBytes, &result) + + return &result, err +} diff --git a/docscan/config/config_retrieve.go b/docscan/config/config_retrieve.go new file mode 100644 index 00000000..3d30ef16 --- /dev/null +++ b/docscan/config/config_retrieve.go @@ -0,0 +1,78 @@ +package config + +// SessionConfigurationResponse represents the configuration of a Doc Scan session. +type SessionConfigurationResponse struct { + ClientSessionTokenTTL int `json:"client_session_token_ttl"` + SessionID string `json:"session_id"` + RequestedChecks []string `json:"requested_checks"` + Capture *CaptureResponse `json:"capture"` +} + +// GetClientSessionTokenTTL returns the amount of time remaining in seconds until the session expires. +func (s *SessionConfigurationResponse) GetClientSessionTokenTTL() int { + return s.ClientSessionTokenTTL +} + +// GetSessionID returns the session ID that the configuration belongs to. +func (s *SessionConfigurationResponse) GetSessionID() string { + return s.SessionID +} + +// GetRequestedChecks returns a list of strings, signifying the checks that have been requested in the session. +func (s *SessionConfigurationResponse) GetRequestedChecks() []string { + return s.RequestedChecks +} + +// GetCapture returns information about what needs to be captured to fulfil the session's requirements. +func (s *SessionConfigurationResponse) GetCapture() *CaptureResponse { + return s.Capture +} + +// CaptureResponse represents the capture requirements for the session. +type CaptureResponse struct { + BiometricConsent string `json:"biometric_consent"` + RequiredResources []*RequiredResource `json:"required_resources"` +} + +// RequiredResource represents a resource that needs to be captured. +type RequiredResource struct { + Type string `json:"type"` + ID string `json:"id,omitempty"` + State string `json:"state,omitempty"` + AllowedSources []*AllowedSource `json:"allowed_sources,omitempty"` + SupportedCountries []*SupportedCountry `json:"supported_countries,omitempty"` + AllowedCaptureMethods string `json:"allowed_capture_methods,omitempty"` + RequestedTasks []*RequestedTask `json:"requested_tasks,omitempty"` + AttemptsRemaining map[string]int `json:"attempts_remaining,omitempty"` + DocumentTypes []string `json:"document_types,omitempty"` + CountryCodes []string `json:"country_codes,omitempty"` + Objective *Objective `json:"objective,omitempty"` + LivenessType string `json:"liveness_type,omitempty"` +} + +// AllowedSource represents a source that is allowed for a resource. +type AllowedSource struct { + Type string `json:"type"` +} + +// SupportedCountry represents a country and its supported documents. +type SupportedCountry struct { + Code string `json:"code"` + SupportedDocuments []*SupportedDocument `json:"supported_documents"` +} + +// SupportedDocument represents a document type supported for a country. +type SupportedDocument struct { + Type string `json:"type"` +} + +// RequestedTask represents a task that has been requested for a resource. +type RequestedTask struct { + Type string `json:"type"` + State string `json:"state,omitempty"` +} + +// Objective represents the objective for a supplementary document. +type Objective struct { + Type string `json:"type"` +}