Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions _examples/idv/handlers.session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions _examples/idv/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ func initializeRoutes() {
router.GET("/media", getMedia)
router.GET("/privacy-policy", showPrivacyPolicyPage)
router.GET("/error", showErrorPage)
router.GET("/config", getSessionConfigurationHandler)
}
38 changes: 38 additions & 0 deletions docscan/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -291,3 +292,40 @@ func marshalJSON(jsonMarshaler jsonMarshaler, v interface{}) ([]byte, error) {
}
return json.Marshal(v)
}

const getSessionConfigurationPath = "/sessions/%s/configuration"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this to docscan/endpoint.go for consistency.


// 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
}
78 changes: 78 additions & 0 deletions docscan/config/config_retrieve.go
Copy link

@saurabh-yoti saurabh-yoti May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add filters for returning Document, Liveness and Face capture resource requirements similar to the Node SDK.

Original file line number Diff line number Diff line change
@@ -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"`
}
Loading