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
9 changes: 2 additions & 7 deletions descope/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,13 @@ def __init__(self, project_id: str, public_key: str = None, base_uri: str = None
def do_get(
self,
uri: str,
cookies=None,
params=None,
allow_redirects=None,
pswd: str = None,
) -> requests.Response:
response = requests.get(
f"{self.base_url}{uri}",
headers=self._get_default_headers(pswd),
cookies=cookies,
params=params,
allow_redirects=allow_redirects,
)
Expand All @@ -77,14 +75,11 @@ def do_get(
)
return response

def do_post(
self, uri: str, body: dict, cookies=None, pswd: str = None
) -> requests.Response:
def do_post(self, uri: str, body: dict, pswd: str = None) -> requests.Response:
response = requests.post(
f"{self.base_url}{uri}",
headers=self._get_default_headers(pswd),
data=json.dumps(body),
cookies=cookies,
)
if not response.ok:
raise AuthException(
Expand Down Expand Up @@ -305,7 +300,7 @@ def _get_default_headers(self, pswd: str = None):

def _refresh_token(self, refresh_token: str) -> dict:
uri = Auth._compose_refresh_token_url()
response = self.do_get(uri, None, None, None, refresh_token)
response = self.do_get(uri, None, None, refresh_token)

resp = response.json()
auth_info = self._generate_auth_info(
Expand Down
2 changes: 1 addition & 1 deletion descope/authmethod/exchanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def exchange_token(self, code: str) -> dict:

uri = EndpointsV1.exchangeTokenPath
params = Exchanger._compose_exchange_params(code)
response = self._auth.do_get(uri, None, params, False)
response = self._auth.do_get(uri, params, False)
resp = response.json()
jwt_response = self._auth._generate_jwt_response(
resp, response.cookies.get(REFRESH_SESSION_COOKIE_NAME, None)
Expand Down
4 changes: 2 additions & 2 deletions descope/authmethod/magiclink.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def _update_user_email(
identifier, email, cross_device
)
uri = EndpointsV1.updateUserEmailOTPPath
return self._auth.do_post(uri, body, None, refresh_token)
return self._auth.do_post(uri, body, refresh_token)

def _update_user_phone(
self,
Expand All @@ -172,7 +172,7 @@ def _update_user_phone(
identifier, phone, cross_device
)
uri = EndpointsV1.updateUserPhoneOTPPath
return self._auth.do_post(uri, body, None, refresh_token)
return self._auth.do_post(uri, body, refresh_token)

@staticmethod
def _compose_signin_url(method: DeliveryMethod) -> str:
Expand Down
2 changes: 1 addition & 1 deletion descope/authmethod/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def start(self, provider: str, return_url: str = "") -> dict:

uri = EndpointsV1.oauthStart
params = OAuth._compose_start_params(provider, return_url)
response = self._auth.do_get(uri, None, params, False)
response = self._auth.do_get(uri, params, False)

return response.json()

Expand Down
4 changes: 2 additions & 2 deletions descope/authmethod/otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def update_user_email(

uri = EndpointsV1.updateUserEmailOTPPath
body = OTP._compose_update_user_email_body(identifier, email)
self._auth.do_post(uri, body, None, refresh_token)
self._auth.do_post(uri, body, refresh_token)

def update_user_phone(
self, method: DeliveryMethod, identifier: str, phone: str, refresh_token: str
Expand Down Expand Up @@ -185,7 +185,7 @@ def update_user_phone(

uri = OTP._compose_update_phone_url(method)
body = OTP._compose_update_user_phone_body(identifier, phone)
self._auth.do_post(uri, body, None, refresh_token)
self._auth.do_post(uri, body, refresh_token)

@staticmethod
def _compose_signup_url(method: DeliveryMethod) -> str:
Expand Down
2 changes: 1 addition & 1 deletion descope/authmethod/saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def start(self, tenant: str, return_url: str = None) -> dict:

uri = EndpointsV1.authSAMLStart
params = SAML._compose_start_params(tenant, return_url)
response = self._auth.do_get(uri, None, params)
response = self._auth.do_get(uri, params)

return response.json()

Expand Down
2 changes: 1 addition & 1 deletion descope/authmethod/totp.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def update_user(self, identifier: str, refresh_token: str) -> None:

uri = EndpointsV1.updateTOTPPath
body = TOTP._compose_update_user_body(identifier)
response = self._auth.do_post(uri, body, None, refresh_token)
response = self._auth.do_post(uri, body, refresh_token)

return response.json()
# Response should have these schema:
Expand Down
2 changes: 1 addition & 1 deletion descope/authmethod/webauthn.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def add_device_start(self, identifier: str, refresh_token: str, origin: str):

uri = EndpointsV1.deviceAddAuthWebauthnStart
body = WebauthN._compose_add_device_start_body(identifier, origin)
response = self._auth.do_post(uri, body, None, refresh_token)
response = self._auth.do_post(uri, body, refresh_token)

return response.json()

Expand Down
2 changes: 1 addition & 1 deletion descope/descope_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ def logout(self, refresh_token: str) -> requests.Response:
)

uri = EndpointsV1.logoutPath
return self._auth.do_get(uri, None, None, None, refresh_token)
return self._auth.do_get(uri, None, None, refresh_token)
1 change: 1 addition & 0 deletions samples/webauthn_web_sample_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def webauthn_add_device_start():
def webauthn_add_device_finish():
data = request.get_json()
descope_client.webauthn.add_device_finish(data["transactionId"], data["response"])
return jsonify("{}")


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion tests/test_exchanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def test_exchange_token(self):
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
},
cookies=None,
params={"code": "c1"},
allow_redirects=False,
)
Expand Down
3 changes: 0 additions & 3 deletions tests/test_magiclink.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def test_sign_in_cross_device(self):
)
mock_post.assert_called_with(
f"{DEFAULT_BASE_URL}{EndpointsV1.signInAuthMagicLinkPath}/email",
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down Expand Up @@ -278,7 +277,6 @@ def test_sign_up_cross_device(self):
)
mock_post.assert_called_with(
f"{DEFAULT_BASE_URL}{EndpointsV1.signUpAuthMagicLinkPath}/email",
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down Expand Up @@ -308,7 +306,6 @@ def test_sign_up_or_in_cross_device(self):
)
mock_post.assert_called_with(
f"{DEFAULT_BASE_URL}{EndpointsV1.signUpOrInAuthMagicLinkPath}/email",
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down
1 change: 0 additions & 1 deletion tests/test_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def test_oauth_start(self):
expected_uri = f"{DEFAULT_BASE_URL}{EndpointsV1.oauthStart}"
mock_get.assert_called_with(
expected_uri,
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down
1 change: 0 additions & 1 deletion tests/test_saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def test_saml_start(self):
expected_uri = f"{DEFAULT_BASE_URL}{EndpointsV1.authSAMLStart}"
mock_get.assert_called_with(
expected_uri,
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down
1 change: 0 additions & 1 deletion tests/test_totp.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def test_update_user(self):
expected_uri = f"{DEFAULT_BASE_URL}{EndpointsV1.updateTOTPPath}"
mock_post.assert_called_with(
expected_uri,
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6ZXlKaGJHY2lPaUpGVXpNNE5DSXNJbXRwWkNJNklqSkNkRFZYVEdOalRGVmxlVEZFY0RkMWRIQjBXbUl6Um5nNVN5SXNJblI1Y0NJNklrcFhWQ0o5LmV5SmhkWFJvYjNKcGVtVmtWR1Z1WVc1MGN5STZleUlpT201MWJHeDlMQ0pqYjI5cmFXVkViMjFoYVc0aU9pSWlMQ0pqYjI5cmFXVkZlSEJwY21GMGFXOXVJam94TmpZd05qYzVNakE0TENKamIyOXJhV1ZOWVhoQloyVWlPakkxT1RFNU9Ua3NJbU52YjJ0cFpVNWhiV1VpT2lKRVUxSWlMQ0pqYjI5cmFXVlFZWFJvSWpvaUx5SXNJbVY0Y0NJNk1qQTVNREE0TnpJd09Dd2lhV0YwSWpveE5qVTRNRGczTWpBNExDSnBjM01pT2lJeVFuUTFWMHhqWTB4VlpYa3hSSEEzZFhSd2RGcGlNMFo0T1VzaUxDSnpkV0lpT2lJeVF6VTFkbmw0ZHpCelVrdzJSbVJOTmpoeFVuTkRSR1JTVDFZaWZRLmNXUDV1cDRSNXhlSWwycW9HMk50ZkxIM1E1blJKVktkei1GRG9BWGN0T1FXOWczY2VaUWk2clpRLVRQQmFYTUt3NjhiaWpOM2JMSlRxeFdXNVdIenFSVWVvcGZ1elRjTVltQzB3UDJYR0prcmRGNkE4RDVRVzZhY1NHcWdsRmd1",
Expand Down
6 changes: 0 additions & 6 deletions tests/test_webauthn.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def test_sign_up_start(self):
expected_uri = f"{DEFAULT_BASE_URL}{EndpointsV1.signUpAuthWebauthnStart}"
mock_post.assert_called_with(
expected_uri,
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down Expand Up @@ -132,7 +131,6 @@ def test_sign_up_finish(self):
webauthn.sign_up_finish("t01", "response01")
mock_post.assert_called_with(
expected_uri,
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down Expand Up @@ -178,7 +176,6 @@ def test_sign_in_start(self):
expected_uri = f"{DEFAULT_BASE_URL}{EndpointsV1.signInAuthWebauthnStart}"
mock_post.assert_called_with(
expected_uri,
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down Expand Up @@ -217,7 +214,6 @@ def test_sign_in_finish(self):
webauthn.sign_in_finish("t01", "response01")
mock_post.assert_called_with(
expected_uri,
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down Expand Up @@ -283,7 +279,6 @@ def test_add_device_start(self):
expected_uri = f"{DEFAULT_BASE_URL}{EndpointsV1.deviceAddAuthWebauthnStart}"
mock_post.assert_called_with(
expected_uri,
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6YXNkYXNk",
Expand Down Expand Up @@ -325,7 +320,6 @@ def test_add_device_finish(self):
webauthn.add_device_finish("t01", "response01")
mock_post.assert_called_with(
expected_uri,
cookies=None,
headers={
"Content-Type": "application/json",
"Authorization": "Basic ZHVtbXk6",
Expand Down