Skip to content

Commit 0dc29a3

Browse files
committed
fix: Migrate auth0 provider to new thirdparty interface
1 parent a9cf3c5 commit 0dc29a3

File tree

4 files changed

+48
-227
lines changed

4 files changed

+48
-227
lines changed

tests/auth-react/django3x/mysite/utils.py

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -167,52 +167,9 @@ async def check_for_general_error(
167167
return is_general_error
168168

169169

170-
# Migrate CustomAuth0Provider
171-
# class CustomAuth0Provider(Provider):
172-
# def __init__(self, client_id: str, client_secret: str, domain: str):
173-
# super().__init__("auth0", False)
174-
# self.domain = domain
175-
# self.client_id = client_id
176-
# self.client_secret = client_secret
177-
# self.authorisation_redirect_url = "https://" + self.domain + "/authorize"
178-
# self.access_token_api_url = "https://" + self.domain + "/oauth/token"
179-
180-
# async def get_profile_info(
181-
# self, auth_code_response: Dict[str, Any], user_context: Dict[str, Any]
182-
# ) -> UserInfo:
183-
# # we do not query auth0 here cause it reaches their rate limit.
184-
# return UserInfo("test-user-id-1", UserInfoEmail("[email protected]", True))
185-
186-
# def get_authorisation_redirect_api_info(
187-
# self, user_context: Dict[str, Any]
188-
# ) -> AuthorisationRedirectAPI:
189-
# params: Dict[str, Any] = {
190-
# "scope": "openid profile",
191-
# "response_type": "code",
192-
# "client_id": self.client_id,
193-
# }
194-
# return AuthorisationRedirectAPI(self.authorisation_redirect_url, params)
195-
196-
# def get_access_token_api_info(
197-
# self,
198-
# redirect_uri: str,
199-
# auth_code_from_request: str,
200-
# user_context: Dict[str, Any],
201-
# ) -> AccessTokenAPI:
202-
# params = {
203-
# "client_id": self.client_id,
204-
# "client_secret": self.client_secret,
205-
# "grant_type": "authorization_code",
206-
# "code": auth_code_from_request,
207-
# "redirect_uri": redirect_uri,
208-
# }
209-
# return AccessTokenAPI(self.access_token_api_url, params)
210-
211-
# def get_redirect_uri(self, user_context: Dict[str, Any]) -> Union[None, str]:
212-
# return None
213-
214-
# def get_client_id(self, user_context: Dict[str, Any]) -> str:
215-
# return self.client_id
170+
def auth0_provider_override(provider: Provider) -> Provider:
171+
# TODO: Finish when Node SDK is ready
172+
return provider
216173

217174

218175
providers_list: List[thirdparty.ProviderInput] = [
@@ -260,12 +217,19 @@ async def check_for_general_error(
260217
],
261218
)
262219
),
263-
# FIXME: Migrate this:
264-
# CustomAuth0Provider(
265-
# client_id=os.environ.get("AUTH0_CLIENT_ID"), # type: ignore
266-
# domain=os.environ.get("AUTH0_DOMAIN"), # type: ignore
267-
# client_secret=os.environ.get("AUTH0_CLIENT_SECRET"), # type: ignore
268-
# ),
220+
thirdparty.ProviderInput(
221+
config=thirdparty.ProviderConfig(
222+
third_party_id="auth0",
223+
clients=[
224+
thirdparty.ProviderClientConfig(
225+
client_id=os.environ["AUTH0_CLIENT_ID"],
226+
client_secret=os.environ["AUTH0_CLIENT_SECRET"],
227+
additional_config={"domain": os.environ["AUTH0_DOMAIN"]},
228+
)
229+
],
230+
),
231+
override=auth0_provider_override,
232+
),
269233
]
270234

271235

tests/auth-react/fastapi-server/app.py

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -236,52 +236,9 @@ async def validate_age(value: Any):
236236
]
237237

238238

239-
# Migrate CustomAuth0Provider
240-
# class CustomAuth0Provider(Provider):
241-
# def __init__(self, client_id: str, client_secret: str, domain: str):
242-
# super().__init__("auth0", False)
243-
# self.domain = domain
244-
# self.client_id = client_id
245-
# self.client_secret = client_secret
246-
# self.authorisation_redirect_url = "https://" + self.domain + "/authorize"
247-
# self.access_token_api_url = "https://" + self.domain + "/oauth/token"
248-
249-
# async def get_profile_info(
250-
# self, auth_code_response: Dict[str, Any], user_context: Dict[str, Any]
251-
# ) -> UserInfo:
252-
# # we do not query auth0 here cause it reaches their rate limit.
253-
# return UserInfo("test-user-id-1", UserInfoEmail("[email protected]", True))
254-
255-
# def get_authorisation_redirect_api_info(
256-
# self, user_context: Dict[str, Any]
257-
# ) -> AuthorisationRedirectAPI:
258-
# params: Dict[str, Any] = {
259-
# "scope": "openid profile",
260-
# "response_type": "code",
261-
# "client_id": self.client_id,
262-
# }
263-
# return AuthorisationRedirectAPI(self.authorisation_redirect_url, params)
264-
265-
# def get_access_token_api_info(
266-
# self,
267-
# redirect_uri: str,
268-
# auth_code_from_request: str,
269-
# user_context: Dict[str, Any],
270-
# ) -> AccessTokenAPI:
271-
# params = {
272-
# "client_id": self.client_id,
273-
# "client_secret": self.client_secret,
274-
# "grant_type": "authorization_code",
275-
# "code": auth_code_from_request,
276-
# "redirect_uri": redirect_uri,
277-
# }
278-
# return AccessTokenAPI(self.access_token_api_url, params)
279-
280-
# def get_redirect_uri(self, user_context: Dict[str, Any]) -> Union[None, str]:
281-
# return None
282-
283-
# def get_client_id(self, user_context: Dict[str, Any]) -> str:
284-
# return self.client_id
239+
def auth0_provider_override(provider: Provider) -> Provider:
240+
# TODO: Finish when Node SDK is ready
241+
return provider
285242

286243

287244
def custom_init(
@@ -348,12 +305,19 @@ def custom_init(
348305
],
349306
)
350307
),
351-
# FIXME: Migrate this:
352-
# CustomAuth0Provider(
353-
# client_id=os.environ.get("AUTH0_CLIENT_ID"), # type: ignore
354-
# domain=os.environ.get("AUTH0_DOMAIN"), # type: ignore
355-
# client_secret=os.environ.get("AUTH0_CLIENT_SECRET"), # type: ignore
356-
# ),
308+
thirdparty.ProviderInput(
309+
config=thirdparty.ProviderConfig(
310+
third_party_id="auth0",
311+
clients=[
312+
thirdparty.ProviderClientConfig(
313+
client_id=os.environ["AUTH0_CLIENT_ID"],
314+
client_secret=os.environ["AUTH0_CLIENT_SECRET"],
315+
additional_config={"domain": os.environ["AUTH0_DOMAIN"]},
316+
)
317+
],
318+
),
319+
override=auth0_provider_override,
320+
),
357321
]
358322

359323
def override_email_verification_apis(

tests/auth-react/flask-server/app.py

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -229,52 +229,9 @@ async def check_for_general_error(
229229
return is_general_error
230230

231231

232-
# FIXME: Migrate CustomAuth0Provider
233-
# class CustomAuth0Provider(Provider):
234-
# def __init__(self, client_id: str, client_secret: str, domain: str):
235-
# super().__init__("auth0")
236-
# self.domain = domain
237-
# self.client_id = client_id
238-
# self.client_secret = client_secret
239-
# self.authorisation_redirect_url = "https://" + self.domain + "/authorize"
240-
# self.access_token_api_url = "https://" + self.domain + "/oauth/token"
241-
242-
# async def get_profile_info(
243-
# self, auth_code_response: Dict[str, Any], user_context: Dict[str, Any]
244-
# ) -> UserInfo:
245-
# # we do not query auth0 here cause it reaches their rate limit.
246-
# return UserInfo("test-user-id-1", UserInfoEmail("[email protected]", True))
247-
248-
# def get_authorisation_redirect_api_info(
249-
# self, user_context: Dict[str, Any]
250-
# ) -> AuthorisationRedirectAPI:
251-
# params: Dict[str, Any] = {
252-
# "scope": "openid profile",
253-
# "response_type": "code",
254-
# "client_id": self.client_id,
255-
# }
256-
# return AuthorisationRedirectAPI(self.authorisation_redirect_url, params)
257-
258-
# def get_access_token_api_info(
259-
# self,
260-
# redirect_uri: str,
261-
# auth_code_from_request: str,
262-
# user_context: Dict[str, Any],
263-
# ) -> AccessTokenAPI:
264-
# params = {
265-
# "client_id": self.client_id,
266-
# "client_secret": self.client_secret,
267-
# "grant_type": "authorization_code",
268-
# "code": auth_code_from_request,
269-
# "redirect_uri": redirect_uri,
270-
# }
271-
# return AccessTokenAPI(self.access_token_api_url, params)
272-
273-
# def get_redirect_uri(self, user_context: Dict[str, Any]) -> Union[None, str]:
274-
# return None
275-
276-
# def get_client_id(self, user_context: Dict[str, Any]) -> str:
277-
# return self.client_id
232+
def auth0_provider_override(provider: Provider) -> Provider:
233+
# TODO: Finish when Node SDK is ready
234+
return provider
278235

279236

280237
def custom_init(
@@ -854,12 +811,19 @@ async def authorisation_url_get(
854811
],
855812
)
856813
),
857-
# FIXME: Migrate this:
858-
# CustomAuth0Provider(
859-
# client_id=os.environ.get("AUTH0_CLIENT_ID"), # type: ignore
860-
# domain=os.environ.get("AUTH0_DOMAIN"), # type: ignore
861-
# client_secret=os.environ.get("AUTH0_CLIENT_SECRET"), # type: ignore
862-
# ),
814+
thirdparty.ProviderInput(
815+
config=thirdparty.ProviderConfig(
816+
third_party_id="auth0",
817+
clients=[
818+
thirdparty.ProviderClientConfig(
819+
client_id=os.environ["AUTH0_CLIENT_ID"],
820+
client_secret=os.environ["AUTH0_CLIENT_SECRET"],
821+
additional_config={"domain": os.environ["AUTH0_DOMAIN"]},
822+
)
823+
],
824+
),
825+
override=auth0_provider_override,
826+
),
863827
]
864828

865829
if contact_method is not None and flow_type is not None:

tests/thirdparty/test_thirdparty.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -78,74 +78,3 @@ async def test_thirdpary_parsing_works(fastapi_client: TestClient):
7878
res.content
7979
== b'<html><head><script>window.location.replace("http://supertokens.io/auth/callback/apple?state=afc596274293e1587315c&code=c7685e261f98e4b3b94e34b3a69ff9cf4.0.rvxt.eE8rO__6hGoqaX1B7ODPmA");</script></head></html>'
8080
)
81-
82-
83-
async def test_apple_provider_can_fetch_keys():
84-
from supertokens_python.recipe.thirdparty.providers.apple import Apple
85-
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
86-
87-
def api_side_effect(_: httpx.Request):
88-
return httpx.Response(
89-
200,
90-
json={
91-
"keys": [
92-
{
93-
"kty": "RSA",
94-
"kid": "W6WcOKB",
95-
"use": "sig",
96-
"alg": "RS256",
97-
"n": "2Zc5d0-zkZ5AKmtYTvxHc3vRc41YfbklflxG9SWsg5qXUxvfgpktGAcxXLFAd9Uglzow9ezvmTGce5d3DhAYKwHAEPT9hbaMDj7DfmEwuNO8UahfnBkBXsCoUaL3QITF5_DAPsZroTqs7tkQQZ7qPkQXCSu2aosgOJmaoKQgwcOdjD0D49ne2B_dkxBcNCcJT9pTSWJ8NfGycjWAQsvC8CGstH8oKwhC5raDcc2IGXMOQC7Qr75d6J5Q24CePHj_JD7zjbwYy9KNH8wyr829eO_G4OEUW50FAN6HKtvjhJIguMl_1BLZ93z2KJyxExiNTZBUBQbbgCNBfzTv7JrxMw",
98-
"e": "AQAB",
99-
},
100-
{
101-
"kty": "RSA",
102-
"kid": "fh6Bs8C",
103-
"use": "sig",
104-
"alg": "RS256",
105-
"n": "u704gotMSZc6CSSVNCZ1d0S9dZKwO2BVzfdTKYz8wSNm7R_KIufOQf3ru7Pph1FjW6gQ8zgvhnv4IebkGWsZJlodduTC7c0sRb5PZpEyM6PtO8FPHowaracJJsK1f6_rSLstLdWbSDXeSq7vBvDu3Q31RaoV_0YlEzQwPsbCvD45oVy5Vo5oBePUm4cqi6T3cZ-10gr9QJCVwvx7KiQsttp0kUkHM94PlxbG_HAWlEZjvAlxfEDc-_xZQwC6fVjfazs3j1b2DZWsGmBRdx1snO75nM7hpyRRQB4jVejW9TuZDtPtsNadXTr9I5NjxPdIYMORj9XKEh44Z73yfv0gtw",
106-
"e": "AQAB",
107-
},
108-
{
109-
"kty": "RSA",
110-
"kid": "YuyXoY",
111-
"use": "sig",
112-
"alg": "RS256",
113-
"n": "1JiU4l3YCeT4o0gVmxGTEK1IXR-Ghdg5Bzka12tzmtdCxU00ChH66aV-4HRBjF1t95IsaeHeDFRgmF0lJbTDTqa6_VZo2hc0zTiUAsGLacN6slePvDcR1IMucQGtPP5tGhIbU-HKabsKOFdD4VQ5PCXifjpN9R-1qOR571BxCAl4u1kUUIePAAJcBcqGRFSI_I1j_jbN3gflK_8ZNmgnPrXA0kZXzj1I7ZHgekGbZoxmDrzYm2zmja1MsE5A_JX7itBYnlR41LOtvLRCNtw7K3EFlbfB6hkPL-Swk5XNGbWZdTROmaTNzJhV-lWT0gGm6V1qWAK2qOZoIDa_3Ud0Gw",
114-
"e": "AQAB",
115-
},
116-
]
117-
},
118-
)
119-
120-
with respx_mock(assert_all_mocked=False) as mocker:
121-
mocked_route = mocker.get("https://appleid.apple.com/auth/keys").mock(
122-
side_effect=api_side_effect
123-
)
124-
125-
# apple = Apple(
126-
# "client-id", "client-key-id", "client-private-key", "client-team-id"
127-
# )
128-
# FIXME: Migrate this test properly
129-
apple = Apple(
130-
thirdparty.ProviderInput(
131-
config=thirdparty.ProviderConfig(
132-
third_party_id="apple",
133-
clients=[
134-
thirdparty.ProviderClientConfig(
135-
client_id="client-id",
136-
additional_config={
137-
"keyId": "client-key-id",
138-
"privateKey": "client-private-key",
139-
"teamId": "client-team-id",
140-
},
141-
)
142-
],
143-
)
144-
)
145-
)
146-
# pylint: disable=protected-access
147-
keys = await apple._fetch_apple_public_keys() # type: ignore
148-
149-
assert mocked_route.call_count == 1
150-
assert len(keys) == 3
151-
assert isinstance(keys[0], RSAPublicKey)

0 commit comments

Comments
 (0)