Skip to content

Commit

Permalink
Merge pull request #35 from authsignal/AUT-2461.8
Browse files Browse the repository at this point in the history
AUT-2429: allowing track with no attributes
  • Loading branch information
LittleJono authored Dec 9, 2024
2 parents 41ccbd2 + 1c0757f commit 94d4a20
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
7 changes: 4 additions & 3 deletions authsignal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,22 @@ def __init__(self, api_secret_key, api_url=API_BASE_URL, timeout=2.0):
self.version = VERSION

def track(
self, user_id: str, action: str, attributes: Dict[str, Any]
self, user_id: str, action: str, attributes: Dict[str, Any] = None
) -> Dict[str, Any]:
"""Tracks an action to authsignal, scoped to the user_id and action
Returns the status of the action so that you can determine to whether to continue
Args:
user_id: A user's id. This id should be the same as the user_id used in
event calls.
action: The action that you are tracking an event for, i.e. signIn.
attributes: A dictionary containing the request body.
attributes: A dictionary containing the request body. Optional.
"""
_assert_non_empty_string(user_id, "user_id")
_assert_non_empty_string(action, "action")
_assert_non_empty_dict(attributes, "attributes")

path = f"{self.api_url}/users/{urllib.parse.quote(user_id)}/actions/{urllib.parse.quote(action)}"

attributes = attributes or {}
response = self.session.post(
url=path, data=json.dumps(attributes, cls=DecimalEncoder)
)
Expand Down
16 changes: 16 additions & 0 deletions authsignal/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,22 @@ def test_get_action_with_bad_secret(self):
"AuthsignalException: 401 - The request is unauthorized. Check that your API key and region base URL are correctly configured.",
)

def test_track_without_attributes(self):
client = AuthsignalClient(
api_secret_key=self.test_config["api_secret_key"],
api_url=self.test_config["api_url"],
)

track_response = client.track(
user_id="user123",
action="python-sdk-test",
)

# Verify basic response structure
self.assertEqual(track_response["state"], "CHALLENGE_REQUIRED")
self.assertTrue(track_response.get("idempotency_key"))
self.assertIsNotNone(track_response.get("token"))


if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion authsignal/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "4.0.2"
VERSION = "4.0.3"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "authsignal"
version = "4.0.2"
version = "4.0.3"
description = "Authsignal Python SDK for Passwordless Step Up Authentication"
authors = ["justinsoong <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 94d4a20

Please sign in to comment.