6
6
import respx
7
7
from fastapi import FastAPI
8
8
from pytest import fixture , mark
9
+ from pytest_mock import MockerFixture
9
10
from starlette .testclient import TestClient
10
11
11
12
from supertokens_python import init
@@ -106,18 +107,6 @@ async def exchange_auth_code_for_valid_oauth_tokens( # pylint: disable=unused-a
106
107
}
107
108
108
109
109
- async def get_user_info ( # pylint: disable=unused-argument
110
- oauth_tokens : Dict [str , Any ],
111
- user_context : Dict [str , Any ],
112
- ) -> UserInfo :
113
- time = str (datetime .datetime .now ())
114
- return UserInfo (
115
- "" + time ,
116
- UserInfoEmail (f"johndoeprovidertest+{ time } @supertokens.com" , True ),
117
- RawUserInfoFromProvider ({}, {}),
118
- )
119
-
120
-
121
110
async def exchange_auth_code_for_invalid_oauth_tokens ( # pylint: disable=unused-argument
122
111
redirect_uri_info : RedirectUriInfo ,
123
112
user_context : Dict [str , Any ],
@@ -139,7 +128,6 @@ def get_custom_valid_token_provider(provider: Provider) -> Provider:
139
128
provider .exchange_auth_code_for_oauth_tokens = (
140
129
exchange_auth_code_for_valid_oauth_tokens
141
130
)
142
- provider .get_user_info = get_user_info
143
131
return provider
144
132
145
133
@@ -153,7 +141,9 @@ async def invalid_access_token( # pylint: disable=unused-argument
153
141
154
142
155
143
async def valid_access_token ( # pylint: disable=unused-argument
156
- access_token : str , config : ProviderConfig , user_context : Optional [Dict [str , Any ]]
144
+ access_token : str ,
145
+ config : ProviderConfigForClient ,
146
+ user_context : Optional [Dict [str , Any ]],
157
147
):
158
148
if access_token == "accesstoken" :
159
149
return
@@ -210,53 +200,66 @@ async def test_signinup_when_validate_access_token_throws(fastapi_client: TestCl
210
200
assert res .status_code == 500
211
201
212
202
213
- # async def test_signinup_works_when_validate_access_token_does_not_throw(fastapi_client: TestClient):
214
- # st_init_args = {
215
- # **st_init_common_args,
216
- # "recipe_list": [
217
- # session.init(),
218
- # thirdpartyemailpassword.init(
219
- # providers=[
220
- # ProviderInput(
221
- # config=ProviderConfig(
222
- # third_party_id="custom",
223
- # clients=[
224
- # ProviderClientConfig(
225
- # client_id="test",
226
- # client_secret="test-secret",
227
- # scope=["profile", "email"],
228
- # ),
229
- # ],
230
- # authorization_endpoint="https://example.com/oauth/authorize",
231
- # validate_access_token=valid_access_token,
232
- # authorization_endpoint_query_params={
233
- # "response_type": "token", # Changing an existing parameter
234
- # "response_mode": "form", # Adding a new parameter
235
- # "scope": None, # Removing a parameter
236
- # },
237
- # token_endpoint="https://example.com/oauth/token",
238
- # ),
239
- # override=get_custom_valid_token_provider
240
- # )
241
- # ]
242
- # ),
243
- # ],
244
- # }
245
- #
246
- # init(**st_init_args) # type: ignore
247
- # start_st()
248
- #
249
- # res = fastapi_client.post(
250
- # "/auth/signinup",
251
- # json={
252
- # "thirdPartyId": "custom",
253
- # "redirectURIInfo": {
254
- # "redirectURIOnProviderDashboard": "http://127.0.0.1/callback",
255
- # "redirectURIQueryParams": {
256
- # "code": "abcdefghj",
257
- # },
258
- # },
259
- # }
260
- # )
261
- # assert res.status_code == 200
262
- # assert res.json()["status"] == "OK"
203
+ async def test_signinup_works_when_validate_access_token_does_not_throw (
204
+ fastapi_client : TestClient , mocker : MockerFixture
205
+ ):
206
+ time = str (datetime .datetime .now ())
207
+ mocker .patch (
208
+ "supertokens_python.recipe.thirdparty.providers.custom.get_supertokens_user_info_result_from_raw_user_info" ,
209
+ return_value = UserInfo (
210
+ "" + time ,
211
+ UserInfoEmail (f"johndoeprovidertest+{ time } @supertokens.com" , True ),
212
+ RawUserInfoFromProvider ({}, {}),
213
+ ),
214
+ )
215
+
216
+ st_init_args = {
217
+ ** st_init_common_args ,
218
+ "recipe_list" : [
219
+ session .init (),
220
+ thirdpartyemailpassword .init (
221
+ providers = [
222
+ ProviderInput (
223
+ config = ProviderConfig (
224
+ third_party_id = "custom" ,
225
+ clients = [
226
+ ProviderClientConfig (
227
+ client_id = "test" ,
228
+ client_secret = "test-secret" ,
229
+ scope = ["profile" , "email" ],
230
+ ),
231
+ ],
232
+ authorization_endpoint = "https://example.com/oauth/authorize" ,
233
+ validate_access_token = valid_access_token ,
234
+ authorization_endpoint_query_params = {
235
+ "response_type" : "token" , # Changing an existing parameter
236
+ "response_mode" : "form" , # Adding a new parameter
237
+ "scope" : None , # Removing a parameter
238
+ },
239
+ token_endpoint = "https://example.com/oauth/token" ,
240
+ ),
241
+ override = get_custom_valid_token_provider ,
242
+ )
243
+ ]
244
+ ),
245
+ ],
246
+ }
247
+
248
+ init (** st_init_args ) # type: ignore
249
+ start_st ()
250
+
251
+ res = fastapi_client .post (
252
+ "/auth/signinup" ,
253
+ json = {
254
+ "thirdPartyId" : "custom" ,
255
+ "redirectURIInfo" : {
256
+ "redirectURIOnProviderDashboard" : "http://127.0.0.1/callback" ,
257
+ "redirectURIQueryParams" : {
258
+ "code" : "abcdefghj" ,
259
+ },
260
+ },
261
+ },
262
+ )
263
+
264
+ assert res .status_code == 200
265
+ assert res .json ()["status" ] == "OK"
0 commit comments