Skip to content

Commit 3aed8ce

Browse files
committed
code review comments
1 parent 1a55eae commit 3aed8ce

12 files changed

Lines changed: 28 additions & 26 deletions

File tree

examples/getting-started/conversation/send_handle_incoming_sms/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The server listens on the port set in your `.env` file (default: 3001).
7070

7171
### Exposing the server with ngrok
7272

73-
To receive webhooks on your machine, expose the server with a tunnel (e.g. ngrok).
73+
To receive Conversation API Sinch Events on your machine, expose the server with a tunnel (e.g. ngrok).
7474

7575

7676
```bash

examples/sinch_events/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "sinch-sdk-python-quickstart-server"
33
version = "0.1.0"
4-
description = "Sinch SDK Python Quickstart Webhooks Server"
4+
description = "Sinch SDK Python Quickstart Sinch Events Server"
55
readme = "README.md"
66
package-mode = false
77

File renamed without changes.

sinch/domains/authentication/webhooks/v1/__init__.py renamed to sinch/domains/authentication/sinch_events/v1/__init__.py

File renamed without changes.

sinch/domains/authentication/webhooks/v1/authentication_validation.py renamed to sinch/domains/authentication/sinch_events/v1/authentication_validation.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,26 @@ def validate_sinch_event_signature_with_nonce(
7373
"""
7474
Validate signature headers for Sinch Event callbacks that use nonce and timestamp.
7575
76-
:param callback_secret: Secret associated with the webhook.
76+
:param callback_secret: Secret associated with the Sinch Event destination.
7777
:type callback_secret: str
7878
:param headers: Incoming request's headers.
7979
:type headers: Dict[str, str]
8080
:param body: Incoming request's body.
8181
:type body: str
82-
:returns: True if the X-Sinch-Webhook-Signature header is valid.
82+
:returns: True if the ``X-Sinch-Webhook-Signature`` header and related nonce/timestamp headers are valid.
8383
:rtype: bool
8484
"""
8585
if callback_secret is None:
8686
return False
87-
87+
8888
normalized_headers = normalize_headers(headers)
8989
signature = get_header(normalized_headers.get('x-sinch-webhook-signature'))
9090
if signature is None:
9191
return False
9292

9393
nonce = get_header(normalized_headers.get('x-sinch-webhook-signature-nonce'))
9494
timestamp = get_header(normalized_headers.get('x-sinch-webhook-signature-timestamp'))
95-
95+
9696
if nonce is None or timestamp is None:
9797
return False
9898

@@ -101,24 +101,24 @@ def validate_sinch_event_signature_with_nonce(
101101
body_as_string = json.dumps(body)
102102

103103
signed_data = compute_signed_data(body_as_string, nonce, timestamp)
104-
105-
expected_signature = calculate_webhook_signature(signed_data, callback_secret)
104+
105+
expected_signature = calculate_sinch_event_signature(signed_data, callback_secret)
106106
return hmac.compare_digest(signature, expected_signature)
107107

108108

109109
def compute_signed_data(body: str, nonce: str, timestamp: str) -> str:
110110
"""
111-
Compute signed data for webhook signature validation.
112-
111+
Compute signed data for Sinch Event signature validation.
112+
113113
Format: body.nonce.timestamp (with dots as separators)
114114
"""
115115
return f'{body}.{nonce}.{timestamp}'
116116

117117

118-
def calculate_webhook_signature(signed_data: str, secret: str) -> str:
118+
def calculate_sinch_event_signature(signed_data: str, secret: str) -> str:
119119
"""
120-
Calculate webhook signature using HMAC-SHA256 with Base64 encoding.
121-
120+
Calculate Sinch Event signature using HMAC-SHA256 with Base64 encoding.
121+
122122
:param signed_data: The data to sign (body.nonce.timestamp)
123123
:type signed_data: str
124124
:param secret: The secret key for HMAC

sinch/domains/authentication/webhooks/v1/webhook_utils.py renamed to sinch/domains/authentication/sinch_events/v1/sinch_event_utils.py

File renamed without changes.

sinch/domains/conversation/sinch_events/v1/conversation_sinch_event.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import logging
22
from typing import Any, Dict, Union, Optional
3-
from sinch.domains.authentication.webhooks.v1.authentication_validation import (
4-
validate_webhook_signature_with_nonce,
3+
from sinch.domains.authentication.sinch_events.v1.authentication_validation import (
4+
validate_sinch_event_signature_with_nonce,
55
)
6-
from sinch.domains.authentication.webhooks.v1.webhook_utils import (
6+
from sinch.domains.authentication.sinch_events.v1.sinch_event_utils import (
77
decode_payload,
88
parse_json,
99
normalize_iso_timestamp,
@@ -57,7 +57,7 @@ def _validate_signature(
5757
if not secret:
5858
return False
5959
payload_str = decode_payload(payload, headers)
60-
return validate_webhook_signature_with_nonce(
60+
return validate_sinch_event_signature_with_nonce(
6161
secret, headers, payload_str
6262
)
6363

sinch/domains/numbers/sinch_events/v1/sinch_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any, Dict, Optional, Union
2-
from sinch.domains.authentication.webhooks.v1.authentication_validation import (
2+
from sinch.domains.authentication.sinch_events.v1.authentication_validation import (
33
validate_signature_header,
44
)
5-
from sinch.domains.authentication.webhooks.v1.webhook_utils import (
5+
from sinch.domains.authentication.sinch_events.v1.sinch_event_utils import (
66
decode_payload,
77
parse_json,
88
normalize_iso_timestamp,

sinch/domains/sms/models/v1/response/recipient_delivery_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from sinch.domains.sms.models.v1.internal.base import (
1717
BaseModelConfigurationResponse,
1818
)
19-
from sinch.domains.authentication.webhooks.v1.webhook_utils import (
19+
from sinch.domains.authentication.sinch_events.v1.sinch_event_utils import (
2020
normalize_iso_timestamp,
2121
)
2222

sinch/domains/sms/sinch_events/v1/sms_sinch_event.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import json
22
from typing import Any, Dict, Union, Optional
33
from pydantic import TypeAdapter
4-
from sinch.domains.authentication.webhooks.v1.authentication_validation import (
5-
validate_webhook_signature_with_nonce,
4+
from sinch.domains.authentication.sinch_events.v1.authentication_validation import (
5+
validate_sinch_event_signature_with_nonce,
66
)
7-
from sinch.domains.authentication.webhooks.v1.webhook_utils import (
7+
from sinch.domains.authentication.sinch_events.v1.sinch_event_utils import (
88
decode_payload,
99
parse_json,
1010
normalize_iso_timestamp,
@@ -56,7 +56,7 @@ def validate_authentication_header(
5656
if isinstance(json_payload, bytes)
5757
else json_payload
5858
)
59-
return validate_webhook_signature_with_nonce(
59+
return validate_sinch_event_signature_with_nonce(
6060
self.app_secret, headers, payload_str
6161
)
6262

0 commit comments

Comments
 (0)