Skip to content

SDK-2869: Python - Support fetching session PDF in IDV - python - #471

Merged
mehmet-yoti merged 4 commits into
developmentfrom
websdk-auto/SDK-2869-python-support-fetching-session-pdf-in-idv
Nov 18, 2026
Merged

mehmet-yoti merged 4 commits into
developmentfrom
websdk-auto/SDK-2869-python-support-fetching-session-pdf-in-idv

Conversation

@mehmet-yoti

Copy link
Copy Markdown
Contributor

Summary

Adds support for fetching a session overview PDF from the IDV (Identity Verification) service. A new create_session_overview_pdf(session_id, pdf_request=None) method is added to DocScanClient that POSTs to /idverify/v1/sessions/{sessionId}/pdf, expects HTTP 201, and returns the raw PDF bytes. Optional boolean flags controlling PDF content (images, extracted text, device tracking) are cleanly omitted from the request JSON when not set.

Changes

  • yoti_python_sdk/doc_scan/client.py — Added create_session_overview_pdf(session_id, pdf_request=None) method to DocScanClient; raises DocScanException on non-201 response.
  • yoti_python_sdk/doc_scan/endpoint.py — Added create_session_overview_pdf_path(session_id) static helper to build the /idverify/v1/sessions/{sessionId}/pdf endpoint path.
  • yoti_python_sdk/doc_scan/session/create/session_overview_pdf_request.py — New file introducing SessionOverviewPdfRequest (serialisable dataclass) and SessionOverviewPdfRequestBuilder with three optional boolean flags: include_images, include_extracted_text, include_device_tracking. Unset flags are omitted from JSON entirely via remove_null_values.
  • yoti_python_sdk/doc_scan/__init__.py — Exports SessionOverviewPdfRequest and SessionOverviewPdfRequestBuilder from the yoti_python_sdk.doc_scan public API.
  • examples/doc_scan/app.py — Added /session-pdf Flask route that reads optional query-string flags, builds a SessionOverviewPdfRequest, calls create_session_overview_pdf, and streams the PDF back as application/pdf.
  • examples/doc_scan/templates/success.html — Added two download links on the success page: one for a plain PDF and one with all optional flags enabled.
  • yoti_python_sdk/tests/doc_scan/test_doc_scan_client.py — 3 new client tests covering: successful PDF generation with no request body, successful PDF generation with a populated request, and error handling on non-201 responses.
  • yoti_python_sdk/tests/doc_scan/session/create/test_session_overview_pdf_request.py — 12 new tests for SessionOverviewPdfRequest and SessionOverviewPdfRequestBuilder covering default/None serialisation, individual flag combinations, and chained builder usage.

QA Test Steps

Setup

  1. Clone the repo and check out websdk-auto/SDK-2869-python-support-fetching-session-pdf-in-idv.
  2. Install dependencies: pip install -e ".[dev]".
  3. Run the test suite: pytest yoti_python_sdk/tests/doc_scan/ -v — all 27 tests should pass (15 client tests, 12 request-model tests).

Happy path — SDK method
4. Instantiate DocScanClient with valid sandbox credentials.
5. Create a session and call doc_scan_client.create_session_overview_pdf(session_id) with no extra arguments.
6. Verify the return value is bytes and starts with %PDF.
7. Call again with a SessionOverviewPdfRequestBuilder().with_include_images().with_include_extracted_text().build() and verify the same.

Happy path — Flask example app
8. Configure the example app with valid YOTI_CLIENT_SDK_ID and key, then run flask run from examples/doc_scan/.
9. Complete a Doc Scan session. On the success page, click "Download Session PDF" — a PDF should download.
10. Click "Download Session PDF (with images & text)" — the PDF should download and include images/extracted text.
11. Navigate directly to /session-pdf?include_images=true&include_extracted_text=true&include_device_tracking=true with a valid session cookie.

Edge cases
12. Call create_session_overview_pdf with an invalid/expired session_id — verify a DocScanException is raised with an informative message.
13. Construct SessionOverviewPdfRequest() with no arguments and verify to_json() returns {} (all flags omitted).
14. Set only include_images=False explicitly and verify only that key appears in the serialised JSON (not the other two).

Regression
15. Run the full test suite (pytest) — no pre-existing tests should be broken.

Notes

  • Optional boolean flags are intentionally omitted from the JSON payload when None (not set), rather than being sent as false. This matches the backend contract and avoids unintended overrides.
  • The method returns raw bytes; callers are responsible for writing to file or streaming.
  • The example app /session-pdf route reads session_id from the Flask session cookie set during the normal flow; it will return a 400 error if no session has been created yet.
  • No changes to authentication, session creation, or other existing IDV flows.

Related Jira: SDK-2869
Auto-generated by Claude dynamic workflow

@mehmet-yoti

Copy link
Copy Markdown
Contributor Author

🤖 Claude Code Review

Code Review Findings

Critical

None

Major

1. create_session_overview_pdf sends JSON null as request body when pdf_request=None
yoti_python_sdk/doc_scan/client.py:220

json.dumps(None, cls=YotiEncoder).encode("utf-8") produces b'null', which is sent verbatim as the POST body with Content-Type: application/json. This means:

  • The Yoti backend receives a JSON null body (not an empty object {}), which most REST APIs reject with a 400/415.
  • The auth digest (X-YOTI-AUTH-DIGEST) includes the base64 of b'null', so if the backend signs the request against an empty body instead, it will return a 401.
  • The existing test (test_should_return_pdf_bytes_when_no_request_body_provided) does not catch this because it stubs SignedRequest.execute before the request is built.

Suggested fix:

payload = (
    json.dumps(pdf_request, cls=YotiEncoder).encode("utf-8")
    if pdf_request is not None
    else b"{}"
)

2. Builder with_include_* methods accept any type — non-bool values are silently serialised as JSON strings
yoti_python_sdk/doc_scan/session/create/session_overview_pdf_request.py:75–111

The three builder methods declare bool parameters in their docstrings but perform no runtime type check. Passing e.g. with_include_images("yes") stores a str, which to_json() then serialises as "include_images": "yes" (a JSON string, not a boolean). The backend will likely reject this or silently ignore the flag.

The example app (examples/doc_scan/app.py:197) correctly converts strings before calling the builder, but SDK consumers calling the builder directly have no guard.

Suggested fix: add a type guard in each setter:

def with_include_images(self, include_images=True):
    if not isinstance(include_images, bool):
        raise TypeError("include_images must be a bool")
    self.__include_images = include_images
    return self

Minor

3. to_json operates on the private mangled dict via remove_null_values — accesses name-mangled attributes correctly, but the dict literal uses public names that don't match the stored attribute names
yoti_python_sdk/doc_scan/session/create/session_overview_pdf_request.py:58–65

This is fine as written (the dict keys are the JSON field names, not the attribute names), but inside to_json the private fields are accessed through self.__include_images etc. Python's name-mangling means these are actually _SessionOverviewPdfRequest__include_images. The code works but would silently produce an AttributeError if this method were ever subclassed and the fields were not redeclared. This is a latent fragility, not a current bug.

No change required right now, but worth noting for any future subclassing.


4. No test asserts the actual serialised payload sent when pdf_request=None
yoti_python_sdk/tests/doc_scan/test_doc_scan_client.py:239–252

test_should_return_pdf_bytes_when_no_request_body_provided stubs the execute layer entirely. It never observes the SignedRequest that was built, so it cannot catch the b'null' body regression described in finding #1. The test passes today and would continue to pass even after the bug is introduced.

Suggested addition: capture the SignedRequest argument passed to execute and assert request.data == b"{}".

Nit

5. Filename in Content-Disposition header exposes the raw session_id to the browser
examples/doc_scan/app.py:216–220

"Content-Disposition": "attachment; filename=session-overview-{}.pdf".format(session_id)

session_id is taken from the server-side Flask session and is Yoti-generated (so unlikely to be malicious here), but inserting arbitrary values into a Content-Disposition filename without RFC 5987 encoding is a header-injection pattern. A session_id containing " or ; would break the header. Safe alternative:

import re
safe_id = re.sub(r'[^A-Za-z0-9_-]', '_', session_id)
"Content-Disposition": "attachment; filename=session-overview-{}.pdf".format(safe_id)

6. Example session_pdf view always re-instantiates DocScanClient per request
examples/doc_scan/app.py:182

DocScanClient is created fresh inside the view function, consistent with how the other example views work (e.g. media() at line 161). This is harmless in the example, but it differs from the documented best practice of creating the client once. Not a bug; flagging for consistency.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The request’s default Accept header excludes PDF responses and can cause HTTP 406; it must allow both PDF and JSON, with a client-test assertion verifying the built header.

1 open issue
8 files not reviewed
  • yoti_python_sdk/protobuf/attrpubapi_v1/AttributeChange_pb2.py: Generated file
  • yoti_python_sdk/protobuf/attrpubapi_v1/AttributeDisplayRequest_pb2.py: Generated file
  • yoti_python_sdk/protobuf/attrpubapi_v1/AttributeDisplayResponse_pb2.py: Generated file
  • yoti_python_sdk/protobuf/attrpubapi_v1/Attribute_pb2.py: Generated file
  • yoti_python_sdk/protobuf/attrpubapi_v1/DeleteSuperseded_pb2.py: Generated file
  • yoti_python_sdk/protobuf/attrpubapi_v1/Delete_pb2.py: Generated file
  • yoti_python_sdk/protobuf/attrpubapi_v1/List_pb2.py: Generated file
  • yoti_python_sdk/protobuf/attrpubapi_v1/Refresh_pb2.py: Generated file
What changed in this PR

Adds session overview PDF downloads to the Python SDK’s Identity Verification client, with optional content controls and a Flask example.

Changes:

  • Adds the PDF endpoint, client method, and public request model/builder, preserving unset flags.
  • Adds download links and tests for PDF responses, errors, and request serialization.
  • Applies unrelated formatting-only changes across existing SDK code, tests, examples, and generated protobuf files.
File Description
yoti_python_sdk/​tests/​test_activity_details.py Formatting only.
yoti_python_sdk/​tests/​doc_scan/​test_doc_scan_client.py Tests PDF responses, errors, and nested request options.
yoti_python_sdk/​tests/​doc_scan/​session/​create/​test_session_overview_pdf_request.py Tests PDF flags, builder behavior, and serialization.
yoti_python_sdk/​tests/​doc_scan/​session/​create/​subcheck/​test_issuing_authority_sub_check.py Formatting only.
yoti_python_sdk/​tests/​doc_scan/​session/​create/​check/​test_wathclist_check.py Formatting only.
yoti_python_sdk/​tests/​doc_scan/​session/​create/​check/​test_liveness_check.py Whitespace cleanup only.
yoti_python_sdk/​tests/​doc_scan/​mocks.py Adds successful and failed PDF response fixtures.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​ThirdPartyAttribute_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​SharingNotificationPush_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​Sharing_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​SessionData_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​ScanYotiCompleteShare_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​ReceiptPush_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​Policy_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​Location_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​IssuingAttributes_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​IdentityProfileShare_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​ExtraData_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​DataEntry_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​CancelSharing_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​sharepubapi_v1/​AgeVerificationSecret_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​protobuf.py Formatting only.
yoti_python_sdk/​protobuf/​devicepubapi_v1/​StaticCredentialAuth_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​YotiYUV_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​SignedTimestamp_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​Signature_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​RsaAuthDigest_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​OptionalTypes_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​MRZ_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​Metadata_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​IdentityProfileReport_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​IdentityProfilePreview_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​IdentityProfile_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​Hmac_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​EncryptedData_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​DocumentTypes_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​DocumentFields_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​DataPrivacy_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​ChipInfo_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​AttributeMigration_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​AttributeLink_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​AdminReasonCode_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​compubapi_v1/​Address_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​Unlock_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​Signing_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​Refresh_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​List_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​DeleteSuperseded_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​Delete_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​AttributeDisplayResponse_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​AttributeDisplayRequest_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​AttributeChange_pb2.py Generated-code formatting only.
yoti_python_sdk/​protobuf/​attrpubapi_v1/​Attribute_pb2.py Generated-code formatting only.
yoti_python_sdk/​doc_scan/​session/​retrieve/​static_liveness_resource_response.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​retrieve/​share_code_resource_response.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​retrieve/​resource_response.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​retrieve/​resource_container.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​retrieve/​image_response.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​create/​subcheck/​issuing_authority_sub_check.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​create/​session_overview_pdf_request.py Adds optional PDF content flags and a fluent builder.
yoti_python_sdk/​doc_scan/​session/​create/​sdk_config.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​create/​notification_config.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​create/​filter/​orthogonal_restrictions_filter.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​create/​check/​watchlist_screen.py Formatting only.
yoti_python_sdk/​doc_scan/​session/​create/​check/​__init__.py Whitespace cleanup only.
yoti_python_sdk/​doc_scan/​endpoint.py Adds the session PDF endpoint path.
yoti_python_sdk/​doc_scan/​client.py Adds signed PDF creation requests returning raw bytes.
yoti_python_sdk/​doc_scan/​__init__.py Exports the PDF request model and builder.
yoti_python_sdk/​date_parser.py Whitespace cleanup only.
yoti_python_sdk/​activity_details.py Formatting only.
setup.py Whitespace cleanup; dependencies unchanged.
README.md Formats the existing authentication example.
examples/​yoti_example_django/​yoti_example/​urls.py Whitespace cleanup only.
examples/​doc_scan/​templates/​success.html Adds default and all-options PDF download links.
examples/​doc_scan/​app.py Adds the PDF download route with optional query flags.

Review effort: Balanced

Comment thread yoti_python_sdk/doc_scan/client.py Outdated
Comment on lines +233 to +234
.build()
)
@mehmet-yoti
mehmet-yoti marked this pull request as ready for review November 6, 2026 13:49
@nikhilPank
nikhilPank self-requested a review November 12, 2026 12:34

@nikhilPank nikhilPank left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See comment here: https://github.com/getyoti/yoti-python-sdk/pull/471/changes#r4550692863

Also, there are lots of unnecessary formatting changes in this PR, maybe they can be removed

Comment thread yoti_python_sdk/doc_scan/client.py Outdated
request = (
SignedRequest.builder()
.with_post()
.with_pem_file(self.__key)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This won't work with the new central auth added in #467

https://github.com/getyoti/yoti-python-sdk/pull/467/changes#diff-78be61d8a3b700ae5915889d4aa5db03502fbba341e1dc5061ebbdcaa9612766R78

you should replace .with_pem_file(self.__key) with .with_auth_strategy(self.__auth_strategy) to match that PR.
Also you need to replace .with_param("sdkId", self.__sdk_id) with self.__with_sdk_id_param(builder)

make sure #467 is merged first as well

- Add jti (UUID v4) claim to the client assertion JWT, with an optional
  with_jwt_id_supplier() builder override (parity with PHP/Java)
- Add a configurable timeout to the auth token request (default 30s)
- Don't append a trailing '?' to URLs when there are no query params
- Abstract AuthStrategy methods raise NotImplementedError
- Fix 'compatibility' typo and update DocScanClient docstring
Session overview PDF endpoint (POST /sessions/{id}/pdf) with optional
include_* flags nested under an "options" envelope.  Rebased onto the
central auth changes (SDK-2773) and stripped of unrelated formatting-only
changes.
… PDF

- Use with_auth_strategy() and __with_sdk_id_param() so the PDF request
  works with both signed requests and central auth tokens (SDK-2773)
- Send Accept: application/pdf, application/json on the PDF request
- Add tests asserting the exact wire body, headers and auth per mode
@mehmet-yoti
mehmet-yoti force-pushed the websdk-auto/SDK-2869-python-support-fetching-session-pdf-in-idv branch from fcde199 to a0a84b6 Compare November 13, 2026 15:18
@sonarqubecloud

Copy link
Copy Markdown

@nikhilPank nikhilPank left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - issues resolved

@mehmet-yoti
mehmet-yoti merged commit f46a3a2 into development Nov 18, 2026
13 checks passed
mehmet-yoti added a commit that referenced this pull request Nov 18, 2026
- resolve conflicts with #466/#468/#471 (keep company_profile, get_resources_for_check, session PDF)
- revert formatting-only changes (protobuf, README, setup.py, other SDK files) to development
- remove unused variable in test_session_spec (flake8 F841)
@mehmet-yoti mehmet-yoti mentioned this pull request Nov 18, 2026
mehmet-yoti added a commit that referenced this pull request Nov 18, 2026
…ort-fetching-session-pdf-in-idv

SDK-2869: Python - Support fetching session PDF in IDV - python
mehmet-yoti added a commit that referenced this pull request Nov 25, 2026
* SDK-2488: Python - Support dark mode in IDV SDK - python (#466)

* Add dark_mode and primary_colour_dark_mode to SdkConfig (SDK-2488)

Extends SdkConfig and SdkConfigBuilder with two new optional fields:
- dark_mode (with_dark_mode, with_dark_mode_on/off/auto convenience methods)
- primary_colour_dark_mode (with_primary_colour_dark_mode)

Both fields are omitted from the JSON payload when not set (None).
* feat(SDK-2488): Python - Support dark mode in IDV SDK [python]
* SDK-2751: Add  to Python SDK IDV Create Session (#470)
* SDK-2530-python-create-helper-methods-for-the-idv-sdk (#468)
* SDK-2773-python-support-central-auth-tokens (#467)
* SDK-2773-python-support-central-auth-tokens
* fix(SDK-2773): add jti claim to auth JWT and address review comments
- Add jti (UUID v4) claim to the client assertion JWT, with an optional
  with_jwt_id_supplier() builder override (parity with PHP/Java)
- Add a configurable timeout to the auth token request (default 30s)
- Don't append a trailing '?' to URLs when there are no query params
- Abstract AuthStrategy methods raise NotImplementedError
- Fix 'compatibility' typo and update DocScanClient docstring

* Merge pull request #471 from getyoti/websdk-auto/SDK-2869-python-support-fetching-session-pdf-in-idv
SDK-2869: Python - Support fetching session PDF in IDV - python
* Sdk 2802 python remove the api for aml check in connect (#469)
* SDK-2802-python-remove-the-api-for-aml-check-in-connect
* ci: pin runners to ubuntu-24.04 so Python 3.9 is still available
ubuntu-latest moved to Ubuntu 26.04, which has no Python 3.9 build in
actions/python-versions. The SDK still supports 3.9 (python_requires>=3.9).
* feat(SDK-2827): Python - Support company_profile for IDV [python] (#472)
* Bump version to 2.15.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants