Skip to content

Commit 9be190c

Browse files
authored
Fix oauth start (#72)
1 parent 0cf302c commit 9be190c

File tree

13 files changed

+48
-33
lines changed

13 files changed

+48
-33
lines changed

descope/auth.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ def do_get(
8787
)
8888
return response
8989

90-
def do_post(self, uri: str, body: dict, pswd: str = None) -> requests.Response:
90+
def do_post(
91+
self, uri: str, body: dict, params=None, pswd: str = None
92+
) -> requests.Response:
9193
response = requests.post(
9294
f"{self.base_url}{uri}",
9395
headers=self._get_default_headers(pswd),
9496
data=json.dumps(body),
9597
allow_redirects=False,
9698
verify=self.secure,
99+
params=params,
97100
)
98101
if not response.ok:
99102
raise AuthException(
@@ -116,7 +119,7 @@ def exchange_token(
116119
)
117120

118121
body = Auth._compose_exchange_body(code, loginOptions)
119-
response = self.do_post(uri, body, refreshToken)
122+
response = self.do_post(uri, body, None, refreshToken)
120123
resp = response.json()
121124
jwt_response = self.generate_jwt_response(
122125
resp, response.cookies.get(REFRESH_SESSION_COOKIE_NAME, None)
@@ -225,14 +228,14 @@ def validate_phone(method: DeliveryMethod, phone: str):
225228

226229
def refresh_token(self, refresh_token: str) -> dict:
227230
uri = Auth._compose_refresh_token_url()
228-
response = self.do_post(uri, {}, refresh_token)
231+
response = self.do_post(uri, {}, None, refresh_token)
229232

230233
resp = response.json()
231234
return self.generate_jwt_response(resp, refresh_token)
232235

233236
def exchange_access_key(self, access_key: str) -> dict:
234237
uri = Auth._compose_exchange_access_key_url()
235-
server_response = self.do_post(uri, {}, access_key)
238+
server_response = self.do_post(uri, {}, None, access_key)
236239
json = server_response.json()
237240
result = {
238241
SESSION_TOKEN_NAME: self._validate_token(json.get("sessionJwt", "")),

descope/authmethod/magiclink.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_session(
5555
) -> dict:
5656
uri = EndpointsV1.getSessionMagicLinkAuthPath
5757
body = MagicLink._compose_get_session_body(pending_ref, loginOptions)
58-
response = self._auth.do_post(uri, body, refreshToken)
58+
response = self._auth.do_post(uri, body, None, refreshToken)
5959

6060
resp = response.json()
6161
jwt_response = self._auth.generate_jwt_response(
@@ -68,7 +68,7 @@ def verify(
6868
) -> dict:
6969
uri = EndpointsV1.verifyMagicLinkAuthPath
7070
body = MagicLink._compose_verify_body(token, loginOptions)
71-
response = self._auth.do_post(uri, body, refreshToken)
71+
response = self._auth.do_post(uri, body, None, refreshToken)
7272
resp = response.json()
7373
jwt_response = self._auth.generate_jwt_response(
7474
resp, response.cookies.get(REFRESH_SESSION_COOKIE_NAME, None)
@@ -112,7 +112,7 @@ def _sign_in(
112112
body = MagicLink._compose_signin_body(identifier, uri, cross_device)
113113
uri = MagicLink._compose_signin_url(method)
114114

115-
return self._auth.do_post(uri, body)
115+
return self._auth.do_post(uri, body, None)
116116

117117
def _sign_up(
118118
self,
@@ -133,15 +133,15 @@ def _sign_up(
133133
method, identifier, uri, cross_device, user
134134
)
135135
uri = MagicLink._compose_signup_url(method)
136-
return self._auth.do_post(uri, body)
136+
return self._auth.do_post(uri, body, None)
137137

138138
def _sign_up_or_in(
139139
self, method: DeliveryMethod, identifier: str, uri: str, cross_device: bool
140140
) -> requests.Response:
141141

142142
body = MagicLink._compose_signin_body(identifier, uri, cross_device)
143143
uri = MagicLink._compose_sign_up_or_in_url(method)
144-
return self._auth.do_post(uri, body)
144+
return self._auth.do_post(uri, body, None)
145145

146146
def _update_user_email(
147147
self, identifier: str, email: str, refresh_token: str, cross_device: bool
@@ -157,7 +157,7 @@ def _update_user_email(
157157
identifier, email, cross_device
158158
)
159159
uri = EndpointsV1.updateUserEmailOTPPath
160-
return self._auth.do_post(uri, body, refresh_token)
160+
return self._auth.do_post(uri, body, None, refresh_token)
161161

162162
def _update_user_phone(
163163
self,
@@ -178,7 +178,7 @@ def _update_user_phone(
178178
identifier, phone, cross_device
179179
)
180180
uri = EndpointsV1.updateUserPhoneOTPPath
181-
return self._auth.do_post(uri, body, refresh_token)
181+
return self._auth.do_post(uri, body, None, refresh_token)
182182

183183
@staticmethod
184184
def _compose_signin_url(method: DeliveryMethod) -> str:

descope/authmethod/oauth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def start(self, provider: str, return_url: str = "") -> dict:
1919
)
2020

2121
uri = EndpointsV1.oauthStart
22-
body = OAuth._compose_start_body(provider, return_url)
23-
response = self._auth.do_post(uri, body)
22+
params = OAuth._compose_start_params(provider, return_url)
23+
response = self._auth.do_post(uri, {}, params)
2424

2525
return response.json()
2626

@@ -41,7 +41,7 @@ def _verify_provider(oauth_provider: str) -> str:
4141
return False
4242

4343
@staticmethod
44-
def _compose_start_body(provider: str, returnURL: str) -> dict:
44+
def _compose_start_params(provider: str, returnURL: str) -> dict:
4545
res = {"provider": provider}
4646
if returnURL:
4747
res["redirectURL"] = returnURL

descope/authmethod/otp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def verify_code(
121121

122122
uri = OTP._compose_verify_code_url(method)
123123
body = OTP._compose_verify_code_body(identifier, code, loginOptions)
124-
response = self._auth.do_post(uri, body, refreshToken)
124+
response = self._auth.do_post(uri, body, None, refreshToken)
125125

126126
resp = response.json()
127127
jwt_response = self._auth.generate_jwt_response(
@@ -153,7 +153,7 @@ def update_user_email(
153153

154154
uri = EndpointsV1.updateUserEmailOTPPath
155155
body = OTP._compose_update_user_email_body(identifier, email)
156-
self._auth.do_post(uri, body, refresh_token)
156+
self._auth.do_post(uri, body, None, refresh_token)
157157

158158
def update_user_phone(
159159
self, method: DeliveryMethod, identifier: str, phone: str, refresh_token: str
@@ -180,7 +180,7 @@ def update_user_phone(
180180

181181
uri = OTP._compose_update_phone_url(method)
182182
body = OTP._compose_update_user_phone_body(identifier, phone)
183-
self._auth.do_post(uri, body, refresh_token)
183+
self._auth.do_post(uri, body, None, refresh_token)
184184

185185
@staticmethod
186186
def _compose_signup_url(method: DeliveryMethod) -> str:

descope/authmethod/saml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def start(self, tenant: str, return_url: str = None) -> dict:
2424
)
2525

2626
uri = EndpointsV1.authSAMLStart
27-
body = SAML._compose_start_body(tenant, return_url)
28-
response = self._auth.do_post(uri, body)
27+
params = SAML._compose_start_params(tenant, return_url)
28+
response = self._auth.do_post(uri, {}, params)
2929

3030
return response.json()
3131

@@ -36,7 +36,7 @@ def exchange_token(
3636
return self._auth.exchange_token(uri, code, loginOptions, refreshToken)
3737

3838
@staticmethod
39-
def _compose_start_body(tenant: str, return_url: str) -> dict:
39+
def _compose_start_params(tenant: str, return_url: str) -> dict:
4040
res = {"tenant": tenant}
4141
if return_url is not None and return_url != "":
4242
res["redirectURL"] = return_url

descope/authmethod/totp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def sign_in_code(
5353

5454
uri = EndpointsV1.verifyTOTPPath
5555
body = TOTP._compose_signin_body(identifier, code, loginOptions)
56-
response = self._auth.do_post(uri, body, refreshToken)
56+
response = self._auth.do_post(uri, body, None, refreshToken)
5757

5858
resp = response.json()
5959
jwt_response = self._auth.generate_jwt_response(
@@ -78,7 +78,7 @@ def update_user(self, identifier: str, refresh_token: str) -> None:
7878

7979
uri = EndpointsV1.updateTOTPPath
8080
body = TOTP._compose_update_user_body(identifier)
81-
response = self._auth.do_post(uri, body, refresh_token)
81+
response = self._auth.do_post(uri, body, None, refresh_token)
8282

8383
return response.json()
8484
# Response should have these schema:

descope/authmethod/webauthn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def sign_up_finish(
5353
body = WebauthN._compose_sign_up_in_finish_body(
5454
transactionID, response, loginOptions
5555
)
56-
response = self._auth.do_post(uri, body, refreshToken)
56+
response = self._auth.do_post(uri, body, None, refreshToken)
5757

5858
resp = response.json()
5959
jwt_response = self._auth.generate_jwt_response(
@@ -105,7 +105,7 @@ def sign_in_finish(
105105
body = WebauthN._compose_sign_up_in_finish_body(
106106
transaction_id, response, loginOptions
107107
)
108-
response = self._auth.do_post(uri, body, refreshToken)
108+
response = self._auth.do_post(uri, body, None, refreshToken)
109109

110110
resp = response.json()
111111
jwt_response = self._auth.generate_jwt_response(
@@ -129,7 +129,7 @@ def update_start(self, identifier: str, refresh_token: str, origin: str):
129129

130130
uri = EndpointsV1.updateAuthWebauthnStart
131131
body = WebauthN._compose_update_start_body(identifier, origin)
132-
response = self._auth.do_post(uri, body, refresh_token)
132+
response = self._auth.do_post(uri, body, None, refresh_token)
133133

134134
return response.json()
135135

descope/descope_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def logout(self, refresh_token: str) -> requests.Response:
197197
)
198198

199199
uri = EndpointsV1.logoutPath
200-
return self._auth.do_post(uri, {}, refresh_token)
200+
return self._auth.do_post(uri, {}, None, refresh_token)
201201

202202
def me(self, refresh_token: str) -> dict:
203203
"""

tests/test_magiclink.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ def test_sign_in_cross_device(self):
263263
"Content-Type": "application/json",
264264
"Authorization": f"Bearer {self.dummy_project_id}",
265265
},
266+
params=None,
266267
data=json.dumps(
267268
{
268269
"externalId": "dummy@dummy.com",
@@ -295,6 +296,7 @@ def test_sign_up_cross_device(self):
295296
"Content-Type": "application/json",
296297
"Authorization": f"Bearer {self.dummy_project_id}",
297298
},
299+
params=None,
298300
data=json.dumps(
299301
{
300302
"externalId": "dummy@dummy.com",
@@ -328,6 +330,7 @@ def test_sign_up_or_in_cross_device(self):
328330
"Content-Type": "application/json",
329331
"Authorization": f"Bearer {self.dummy_project_id}",
330332
},
333+
params=None,
331334
data=json.dumps(
332335
{
333336
"externalId": "dummy@dummy.com",

tests/test_oauth.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def setUp(self) -> None:
2424

2525
def test_compose_start_params(self):
2626
self.assertEqual(
27-
OAuth._compose_start_body("google", "http://example.com"),
27+
OAuth._compose_start_params("google", "http://example.com"),
2828
{"provider": "google", "redirectURL": "http://example.com"},
2929
)
3030

@@ -74,7 +74,8 @@ def test_oauth_start(self):
7474
"Content-Type": "application/json",
7575
"Authorization": f"Bearer {self.dummy_project_id}",
7676
},
77-
data=json.dumps({"provider": "facebook"}),
77+
params={"provider": "facebook"},
78+
data=json.dumps({}),
7879
allow_redirects=False,
7980
verify=True,
8081
)
@@ -114,6 +115,7 @@ def test_exchange_token(self):
114115
"Content-Type": "application/json",
115116
"Authorization": f"Bearer {self.dummy_project_id}",
116117
},
118+
params=None,
117119
data=json.dumps(
118120
{
119121
"code": "c1",

0 commit comments

Comments
 (0)