Skip to content
Merged
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
37 changes: 36 additions & 1 deletion authsignal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def send(self, request, **kwargs) -> requests.Response:
status_code = e.response.status_code
try:
error_data = e.response.json()
error_code = error_data.get("errorCode")
error_code = error_data.get("errorCode") or error_data.get("error")
error_description = error_data.get("errorDescription")
except (ValueError, AttributeError):
pass
Expand Down Expand Up @@ -115,6 +115,41 @@ def __init__(self, api_secret_key, api_url=API_BASE_URL, timeout=2.0):
self.version = VERSION
self.webhook = Webhook(api_secret_key=api_secret_key)

def start_flow(
self,
action_code: str,
user: Dict[str, Any] = None,
attributes: Dict[str, Any] = None,
redirect_url: str = None,
client_id: str = None,
) -> Dict[str, Any]:
"""Start a flow. Nested user/attributes dictionaries use API camelCase keys."""
_assert_non_empty_string(action_code, "action_code")
body = {
"actionCode": action_code,
"user": user,
"attributes": attributes,
"redirectUrl": redirect_url,
"clientId": client_id,
}
response = self.session.post(
self.api_url.rstrip("/") + "/flows",
json={k: v for k, v in body.items() if v is not None},
timeout=self.session.timeout,
)
return humps.decamelize(response.json())

def verify_flow(self, action_code: str, challenge_token: str) -> Dict[str, Any]:
"""Verify a flow and retrieve its action, user and optional session."""
_assert_non_empty_string(action_code, "action_code")
_assert_non_empty_string(challenge_token, "challenge_token")
response = self.session.post(
self.api_url.rstrip("/") + "/flows/verify",
json={"actionCode": action_code, "challengeToken": challenge_token},
timeout=self.session.timeout,
)
return humps.decamelize(response.json())

def track(
self, user_id: str, action: str, attributes: Dict[str, Any] = None
) -> Dict[str, Any]:
Expand Down
2 changes: 1 addition & 1 deletion authsignal/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "4.2.0"
VERSION = "4.4.0"
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.3.0"
version = "4.4.0"
description = "Authsignal Python SDK for Passwordless Step Up Authentication"
authors = ["justinsoong <justinsoong@gmail.com>"]
license = "MIT"
Expand Down
Loading