Skip to content

Commit 8c516bf

Browse files
committed
fix: Pyright errors and format
1 parent 4836f16 commit 8c516bf

File tree

4 files changed

+32
-174
lines changed

4 files changed

+32
-174
lines changed

supertokens_python/recipe/thirdparty/providers/bitbucket.py

Lines changed: 20 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -14,100 +14,33 @@
1414

1515
from __future__ import annotations
1616

17-
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Union
18-
19-
from httpx import AsyncClient
2017
from supertokens_python.recipe.thirdparty.provider import Provider
21-
from supertokens_python.recipe.thirdparty.types import (
22-
AccessTokenAPI,
23-
AuthorisationRedirectAPI,
24-
UserInfo,
25-
UserInfoEmail,
26-
)
18+
from .custom import GenericProvider, NewProvider
19+
from ..provider import Provider, ProviderInput
2720

28-
if TYPE_CHECKING:
29-
from supertokens_python.framework.request import BaseRequest
3021

22+
# TODO Implement when it's done in Node PR
23+
class BitbucketImpl(GenericProvider):
24+
pass
3125

32-
class Bitbucket(Provider):
33-
def __init__(
34-
self,
35-
client_id: str,
36-
client_secret: str,
37-
scope: Union[None, List[str]] = None,
38-
authorisation_redirect: Union[
39-
None, Dict[str, Union[str, Callable[[BaseRequest], str]]]
40-
] = None,
41-
is_default: bool = False,
42-
):
43-
super().__init__("bitbucket", is_default)
44-
self.client_id = client_id
45-
self.client_secret = client_secret
46-
self.scopes = ["account", "email"] if scope is None else list(set(scope))
47-
self.access_token_api_url = "https://bitbucket.org/site/oauth2/access_token"
48-
self.authorisation_redirect_url = "https://bitbucket.org/site/oauth2/authorize"
49-
self.authorisation_redirect_params = {}
50-
if authorisation_redirect is not None:
51-
self.authorisation_redirect_params = authorisation_redirect
5226

53-
async def get_profile_info(
54-
self, auth_code_response: Dict[str, Any], user_context: Dict[str, Any]
55-
) -> UserInfo:
56-
access_token: str = auth_code_response["access_token"]
57-
headers = {"Authorization": f"Bearer {access_token}"}
58-
async with AsyncClient() as client:
59-
response = await client.get( # type: ignore
60-
url="https://api.bitbucket.org/2.0/user",
61-
headers=headers,
62-
)
63-
user_info = response.json()
64-
user_id = user_info["uuid"]
65-
email_res = await client.get( # type: ignore
66-
url="https://api.bitbucket.org/2.0/user/emails",
67-
headers=headers,
68-
)
69-
email_data = email_res.json()
70-
email = None
71-
is_verified = False
72-
for email_info in email_data["values"]:
73-
if email_info.get("is_primary"):
74-
email = email_info["email"]
75-
is_verified = email_info["is_confirmed"]
76-
break
27+
# TODO Finish when it's done in Node PR
28+
def Bitbucket(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin
29+
if input.config.name is None:
30+
input.config.name = "Bitbucket"
7731

78-
if email is None:
79-
return UserInfo(user_id)
80-
return UserInfo(user_id, UserInfoEmail(email, is_verified))
32+
if input.config.authorization_endpoint is None:
33+
input.config.authorization_endpoint = (
34+
"https://bitbucket.org/site/oauth2/authorize"
35+
)
8136

82-
def get_authorisation_redirect_api_info(
83-
self, user_context: Dict[str, Any]
84-
) -> AuthorisationRedirectAPI:
85-
params = {
86-
"scope": " ".join(self.scopes),
87-
"response_type": "code",
88-
"client_id": self.client_id,
89-
"access_type": "offline",
90-
**self.authorisation_redirect_params,
91-
}
92-
return AuthorisationRedirectAPI(self.authorisation_redirect_url, params)
37+
if input.config.token_endpoint is None:
38+
input.config.token_endpoint = "https://bitbucket.org/site/oauth2/access_token"
9339

94-
def get_access_token_api_info(
95-
self,
96-
redirect_uri: str,
97-
auth_code_from_request: str,
98-
user_context: Dict[str, Any],
99-
) -> AccessTokenAPI:
100-
params = {
101-
"client_id": self.client_id,
102-
"client_secret": self.client_secret,
103-
"grant_type": "authorization_code",
104-
"code": auth_code_from_request,
105-
"redirect_uri": redirect_uri,
106-
}
107-
return AccessTokenAPI(self.access_token_api_url, params)
40+
if input.config.user_info_endpoint is None:
41+
input.config.user_info_endpoint = "https://api.bitbucket.org/2.0/user"
10842

109-
def get_redirect_uri(self, user_context: Dict[str, Any]) -> Union[None, str]:
110-
return None
43+
# TODO overrides and working of this
44+
# once done in Node PR
11145

112-
def get_client_id(self, user_context: Dict[str, Any]) -> str:
113-
return self.client_id
46+
return NewProvider(input, BitbucketImpl)

supertokens_python/recipe/thirdparty/providers/gitlab.py

Lines changed: 8 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -14,93 +14,16 @@
1414

1515
from __future__ import annotations
1616

17-
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Union
18-
19-
from supertokens_python.normalised_url_domain import NormalisedURLDomain
20-
21-
from httpx import AsyncClient
2217
from supertokens_python.recipe.thirdparty.provider import Provider
23-
from supertokens_python.recipe.thirdparty.types import (
24-
AccessTokenAPI,
25-
AuthorisationRedirectAPI,
26-
UserInfo,
27-
UserInfoEmail,
28-
)
29-
30-
if TYPE_CHECKING:
31-
from supertokens_python.framework.request import BaseRequest
32-
33-
34-
class GitLab(Provider):
35-
def __init__(
36-
self,
37-
client_id: str,
38-
client_secret: str,
39-
scope: Union[None, List[str]] = None,
40-
authorisation_redirect: Union[
41-
None, Dict[str, Union[str, Callable[[BaseRequest], str]]]
42-
] = None,
43-
gitlab_base_url: str = "https://gitlab.com",
44-
is_default: bool = False,
45-
):
46-
super().__init__("gitlab", is_default)
47-
default_scopes = ["read_user"]
48-
if scope is None:
49-
scope = default_scopes
50-
self.client_id = client_id
51-
self.client_secret = client_secret
52-
self.scopes = list(set(scope))
53-
gitlab_base_url = NormalisedURLDomain(gitlab_base_url).get_as_string_dangerous()
54-
self.gitlab_base_url = gitlab_base_url
55-
self.access_token_api_url = f"{gitlab_base_url}/oauth/token"
56-
self.authorisation_redirect_url = f"{gitlab_base_url}/oauth/authorize"
57-
self.authorisation_redirect_params = {}
58-
if authorisation_redirect is not None:
59-
self.authorisation_redirect_params = authorisation_redirect
60-
61-
async def get_profile_info(
62-
self, auth_code_response: Dict[str, Any], user_context: Dict[str, Any]
63-
) -> UserInfo:
64-
access_token: str = auth_code_response["access_token"]
65-
headers = {"Authorization": f"Bearer {access_token}"}
66-
async with AsyncClient() as client:
67-
response = await client.get(f"{self.gitlab_base_url}/api/v4/user", headers=headers) # type: ignore
68-
user_info = response.json()
69-
user_id = str(user_info["id"])
70-
email = user_info.get("email")
71-
if email is None:
72-
return UserInfo(user_id)
73-
is_email_verified = user_info.get("confirmed_at") is not None
74-
return UserInfo(user_id, UserInfoEmail(email, is_email_verified))
18+
from .custom import GenericProvider, NewProvider
19+
from ..provider import Provider, ProviderInput
7520

76-
def get_authorisation_redirect_api_info(
77-
self, user_context: Dict[str, Any]
78-
) -> AuthorisationRedirectAPI:
79-
params = {
80-
"scope": " ".join(self.scopes),
81-
"response_type": "code",
82-
"client_id": self.client_id,
83-
**self.authorisation_redirect_params,
84-
}
85-
return AuthorisationRedirectAPI(self.authorisation_redirect_url, params)
8621

87-
def get_access_token_api_info(
88-
self,
89-
redirect_uri: str,
90-
auth_code_from_request: str,
91-
user_context: Dict[str, Any],
92-
) -> AccessTokenAPI:
93-
params = {
94-
"client_id": self.client_id,
95-
"client_secret": self.client_secret,
96-
"grant_type": "authorization_code",
97-
"code": auth_code_from_request,
98-
"redirect_uri": redirect_uri,
99-
}
100-
return AccessTokenAPI(self.access_token_api_url, params)
22+
# TODO Implement when it's done in Node PR
23+
class GitlabImpl(GenericProvider):
24+
pass
10125

102-
def get_redirect_uri(self, user_context: Dict[str, Any]) -> Union[None, str]:
103-
return None
10426

105-
def get_client_id(self, user_context: Dict[str, Any]) -> str:
106-
return self.client_id
27+
# TODO Implement when it's done in Node PR
28+
def Gitlab(input: ProviderInput) -> Provider: # pylint: disable=redefined-builtin
29+
return NewProvider(input, GitlabImpl)

supertokens_python/recipe/thirdpartyemailpassword/recipe.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def get_emailpassword_config() -> EmailPasswordConfig:
111111
Querier.get_instance(EmailPasswordRecipe.recipe_id),
112112
Querier.get_instance(ThirdPartyRecipe.recipe_id),
113113
self.config.providers,
114+
get_emailpassword_config,
114115
)
115116
self.recipe_implementation: RecipeInterface = (
116117
recipe_implementation

supertokens_python/recipe/thirdpartyemailpassword/recipeimplementation/implementation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
# under the License.
1414
from __future__ import annotations
1515

16-
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
16+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, Callable
1717

1818
import supertokens_python.recipe.emailpassword.interfaces as EPInterfaces
1919
from supertokens_python.recipe.thirdparty.interfaces import GetProviderOkResult
2020
from supertokens_python.recipe.thirdparty.provider import ProviderInput
2121
from supertokens_python.recipe.thirdparty.types import RawUserInfoFromProvider
22+
from supertokens_python.recipe.emailpassword.utils import EmailPasswordConfig
2223

2324
if TYPE_CHECKING:
2425
from supertokens_python.querier import Querier
@@ -54,7 +55,6 @@
5455
from .third_party_recipe_implementation import (
5556
RecipeImplementation as DerivedThirdPartyImplementation,
5657
)
57-
from supertokens_python.recipe.emailpassword.utils import EmailPasswordConfig
5858

5959

6060
class RecipeImplementation(RecipeInterface):
@@ -63,6 +63,7 @@ def __init__(
6363
emailpassword_querier: Querier,
6464
thirdparty_querier: Querier,
6565
providers: List[ProviderInput],
66+
get_emailpassword_config: Callable[[], EmailPasswordConfig],
6667
):
6768
super().__init__()
6869
emailpassword_implementation = EmailPasswordImplementation(

0 commit comments

Comments
 (0)