Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update_user method #20

Merged
merged 3 commits into from
Oct 9, 2024
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
18 changes: 18 additions & 0 deletions authsignal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Dict, Any, Optional
import json
import requests
import urllib.parse

_UNICODE_STRING = str

Expand Down Expand Up @@ -148,6 +149,23 @@ def get_user(self, user_id, redirect_url=None, path=None):
return humps.decamelize(response.json())
except requests.exceptions.RequestException as e:
raise ApiException(str(e), path) from e

def update_user(self, user_id, data):
user_id = urllib.parse.quote(user_id)

path = self._get_user_url(user_id)

headers = self._default_headers()

response = requests.post(path,
json=data,
headers=headers,
auth=requests.auth.HTTPBasicAuth(self.api_key, '')
)

response.raise_for_status()

return humps.decamelize(response.json())

def enroll_verified_authenticator(self, user_id, authenticator_payload, path=None):
"""Enrols an authenticator like a phone number for SMS on behalf of the user
Expand Down
13 changes: 13 additions & 0 deletions authsignal/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ def test_get_action(self):
self.assertEqual(response["state"], "ALLOW")
self.assertEqual(response["state_updated_at"], "2022-07-25T03:19:00.316Z")

@responses.activate
def test_update_user(self):
user_id = "1234"
data = {"email": "[email protected]"}
expected_response = {"email": "[email protected]"}

responses.add(responses.POST, f"{base_url}/users/{user_id}",
json=expected_response, status=200)

response = self.authsignal_client.update_user(user_id=user_id, data=data)

self.assertEqual(response["email"], "[email protected]")

class ValidateChallenge(unittest.TestCase):
def setUp(self):
self.api_key='SECRET'
Expand Down
2 changes: 1 addition & 1 deletion authsignal/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.0.3'
VERSION = '2.0.4'
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 = "2.0.3"
version = "2.0.4"
description = "Authsignal Python SDK for Passwordless Step Up Authentication"
authors = ["justinsoong <[email protected]>"]
license = "MIT"
Expand Down
Loading