Skip to content

Commit

Permalink
Drop Python 3.8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Oct 9, 2024
1 parent 61223f3 commit 7c576be
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 98 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python_version: [3.8, 3.9, '3.10', '3.11', '3.12']
python_version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.9'
- name: Install dependencies
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
10 changes: 5 additions & 5 deletions httpx_oauth/clients/discord.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple, cast
from typing import Any, Optional, cast

from httpx_oauth.exceptions import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2
Expand All @@ -19,7 +19,7 @@
"""


class DiscordOAuth2(BaseOAuth2[Dict[str, Any]]):
class DiscordOAuth2(BaseOAuth2[dict[str, Any]]):
"""OAuth2 client for Discord."""

display_name = "Discord"
Expand All @@ -29,7 +29,7 @@ def __init__(
self,
client_id: str,
client_secret: str,
scopes: Optional[List[str]] = BASE_SCOPES,
scopes: Optional[list[str]] = BASE_SCOPES,
name: str = "discord",
):
"""
Expand All @@ -52,7 +52,7 @@ def __init__(
revocation_endpoint_auth_method="client_secret_basic",
)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
async def get_id_email(self, token: str) -> tuple[str, Optional[str]]:
async with self.get_httpx_client() as client:
response = await client.get(
PROFILE_ENDPOINT,
Expand All @@ -62,7 +62,7 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
if response.status_code >= 400:
raise GetIdEmailError(response=response)

data = cast(Dict[str, Any], response.json())
data = cast(dict[str, Any], response.json())

user_id = data["id"]
user_email = data.get("email")
Expand Down
10 changes: 5 additions & 5 deletions httpx_oauth/clients/facebook.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple, cast
from typing import Any, Optional, cast

from httpx_oauth.exceptions import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2, OAuth2RequestError, OAuth2Token
Expand All @@ -23,7 +23,7 @@
class GetLongLivedAccessTokenError(OAuth2RequestError): ...


class FacebookOAuth2(BaseOAuth2[Dict[str, Any]]):
class FacebookOAuth2(BaseOAuth2[dict[str, Any]]):
"""OAuth2 client for Facebook."""

display_name = "Facebook"
Expand All @@ -33,7 +33,7 @@ def __init__(
self,
client_id: str,
client_secret: str,
scopes: Optional[List[str]] = BASE_SCOPES,
scopes: Optional[list[str]] = BASE_SCOPES,
name: str = "facebook",
):
"""
Expand Down Expand Up @@ -89,7 +89,7 @@ async def get_long_lived_access_token(self, token: str) -> OAuth2Token:
data = self.get_json(response, exc_class=GetLongLivedAccessTokenError)
return OAuth2Token(data)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
async def get_id_email(self, token: str) -> tuple[str, Optional[str]]:
async with self.get_httpx_client() as client:
response = await client.get(
PROFILE_ENDPOINT,
Expand All @@ -99,6 +99,6 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
if response.status_code >= 400:
raise GetIdEmailError(response=response)

data = cast(Dict[str, Any], response.json())
data = cast(dict[str, Any], response.json())

return data["id"], data.get("email")
10 changes: 5 additions & 5 deletions httpx_oauth/clients/franceconnect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import secrets
from typing import Any, Dict, List, Literal, Optional, Tuple, TypedDict
from typing import Any, Literal, Optional, TypedDict

from httpx_oauth.exceptions import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2
Expand Down Expand Up @@ -37,7 +37,7 @@ def __init__(
client_id: str,
client_secret: str,
integration: bool = False,
scopes: Optional[List[str]] = BASE_SCOPES,
scopes: Optional[list[str]] = BASE_SCOPES,
name="franceconnect",
):
endpoints = ENDPOINTS["integration"] if integration else ENDPOINTS["production"]
Expand All @@ -57,7 +57,7 @@ async def get_authorization_url(
self,
redirect_uri: str,
state: Optional[str] = None,
scope: Optional[List[str]] = None,
scope: Optional[list[str]] = None,
code_challenge: Optional[str] = None,
code_challenge_method: Optional[Literal["plain", "S256"]] = None,
extras_params: Optional[FranceConnectOAuth2AuthorizeParams] = None,
Expand All @@ -72,7 +72,7 @@ async def get_authorization_url(
redirect_uri, state, scope, extras_params=_extras_params
)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
async def get_id_email(self, token: str) -> tuple[str, Optional[str]]:
async with self.get_httpx_client() as client:
response = await client.get(
self.profile_endpoint,
Expand All @@ -82,6 +82,6 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
if response.status_code >= 400:
raise GetIdEmailError(response=response)

data: Dict[str, Any] = response.json()
data: dict[str, Any] = response.json()

return str(data["sub"]), data.get("email")
10 changes: 5 additions & 5 deletions httpx_oauth/clients/github.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple, TypedDict, cast
from typing import Any, Optional, TypedDict, cast

import httpx

Expand Down Expand Up @@ -36,7 +36,7 @@ def __init__(
self,
client_id: str,
client_secret: str,
scopes: Optional[List[str]] = BASE_SCOPES,
scopes: Optional[list[str]] = BASE_SCOPES,
name: str = "github",
):
"""
Expand Down Expand Up @@ -106,7 +106,7 @@ async def refresh_token(self, refresh_token: str) -> OAuth2Token:

return OAuth2Token(data)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
async def get_id_email(self, token: str) -> tuple[str, Optional[str]]:
"""
Returns the id and the email (if available) of the authenticated user
from the API provider.
Expand Down Expand Up @@ -140,7 +140,7 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
if response.status_code >= 400:
raise GetIdEmailError(response=response)

data = cast(Dict[str, Any], response.json())
data = cast(dict[str, Any], response.json())

id = data["id"]
email = data.get("email")
Expand All @@ -152,7 +152,7 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
if response.status_code >= 400:
raise GetIdEmailError(response=response)

emails = cast(List[Dict[str, Any]], response.json())
emails = cast(list[dict[str, Any]], response.json())

# Use the primary email if it exists, otherwise the first
email = next(
Expand Down
8 changes: 4 additions & 4 deletions httpx_oauth/clients/google.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Literal, Optional, Tuple, TypedDict, cast
from typing import Any, Literal, Optional, TypedDict, cast

from httpx_oauth.exceptions import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2
Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(
self,
client_id: str,
client_secret: str,
scopes: Optional[List[str]] = BASE_SCOPES,
scopes: Optional[list[str]] = BASE_SCOPES,
name: str = "google",
):
"""
Expand All @@ -65,7 +65,7 @@ def __init__(
revocation_endpoint_auth_method="client_secret_post",
)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
async def get_id_email(self, token: str) -> tuple[str, Optional[str]]:
async with self.get_httpx_client() as client:
response = await client.get(
PROFILE_ENDPOINT,
Expand All @@ -76,7 +76,7 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
if response.status_code >= 400:
raise GetIdEmailError(response=response)

data = cast(Dict[str, Any], response.json())
data = cast(dict[str, Any], response.json())

user_id = data["resourceName"]
user_email = next(
Expand Down
10 changes: 5 additions & 5 deletions httpx_oauth/clients/kakao.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Any, Dict, List, Optional, Tuple, cast
from typing import Any, Optional, cast

from httpx_oauth.exceptions import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2
Expand All @@ -19,7 +19,7 @@
"""


class KakaoOAuth2(BaseOAuth2[Dict[str, Any]]):
class KakaoOAuth2(BaseOAuth2[dict[str, Any]]):
"""OAuth2 client for Kakao."""

display_name = "Kakao"
Expand All @@ -29,7 +29,7 @@ def __init__(
self,
client_id: str,
client_secret: str,
scopes: Optional[List[str]] = BASE_SCOPES,
scopes: Optional[list[str]] = BASE_SCOPES,
name: str = "kakao",
):
"""
Expand All @@ -52,7 +52,7 @@ def __init__(
revocation_endpoint_auth_method="client_secret_post",
)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
async def get_id_email(self, token: str) -> tuple[str, Optional[str]]:
async with self.get_httpx_client() as client:
response = await client.post(
PROFILE_ENDPOINT,
Expand All @@ -63,7 +63,7 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
if response.status_code >= 400:
raise GetIdEmailError(response=response)

payload = cast(Dict[str, Any], response.json())
payload = cast(dict[str, Any], response.json())
account_id = str(payload["id"])
email = payload["kakao_account"].get("email")
return account_id, email
12 changes: 6 additions & 6 deletions httpx_oauth/clients/linkedin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple, cast
from typing import Any, Optional, cast

from httpx_oauth.exceptions import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2, OAuth2Token
Expand All @@ -19,7 +19,7 @@
"""


class LinkedInOAuth2(BaseOAuth2[Dict[str, Any]]):
class LinkedInOAuth2(BaseOAuth2[dict[str, Any]]):
"""OAuth2 client for LinkedIn."""

display_name = "LinkedIn"
Expand All @@ -29,7 +29,7 @@ def __init__(
self,
client_id: str,
client_secret: str,
scopes: Optional[List[str]] = BASE_SCOPES,
scopes: Optional[list[str]] = BASE_SCOPES,
name: str = "linkedin",
):
"""
Expand Down Expand Up @@ -74,7 +74,7 @@ async def refresh_token(self, refresh_token: str) -> OAuth2Token:
"""
return await super().refresh_token(refresh_token) # pragma: no cover

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
async def get_id_email(self, token: str) -> tuple[str, Optional[str]]:
async with self.get_httpx_client() as client:
profile_response = await client.get(
PROFILE_ENDPOINT,
Expand All @@ -94,10 +94,10 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
if email_response.status_code >= 400:
raise GetIdEmailError(response=email_response)

profile_data = cast(Dict[str, Any], profile_response.json())
profile_data = cast(dict[str, Any], profile_response.json())
user_id = profile_data["id"]

email_data = cast(Dict[str, Any], email_response.json())
email_data = cast(dict[str, Any], email_response.json())
user_email = email_data["elements"][0]["handle~"]["emailAddress"]

return user_id, user_email
10 changes: 5 additions & 5 deletions httpx_oauth/clients/microsoft.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Tuple, cast
from typing import Any, Optional, cast

from httpx_oauth.exceptions import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2
Expand All @@ -19,7 +19,7 @@
"""


class MicrosoftGraphOAuth2(BaseOAuth2[Dict[str, Any]]):
class MicrosoftGraphOAuth2(BaseOAuth2[dict[str, Any]]):
"""OAuth2 client for Microsoft Graph API."""

display_name = "Microsoft"
Expand All @@ -30,7 +30,7 @@ def __init__(
client_id: str,
client_secret: str,
tenant: str = "common",
scopes: Optional[List[str]] = BASE_SCOPES,
scopes: Optional[list[str]] = BASE_SCOPES,
name: str = "microsoft",
):
"""
Expand Down Expand Up @@ -63,7 +63,7 @@ def get_authorization_url(
redirect_uri, state=state, scope=scope, extras_params=extras_params
)

async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
async def get_id_email(self, token: str) -> tuple[str, Optional[str]]:
async with self.get_httpx_client() as client:
response = await client.get(
PROFILE_ENDPOINT,
Expand All @@ -73,6 +73,6 @@ async def get_id_email(self, token: str) -> Tuple[str, Optional[str]]:
if response.status_code >= 400:
raise GetIdEmailError(response=response)

data = cast(Dict[str, Any], response.json())
data = cast(dict[str, Any], response.json())

return data["id"], data["userPrincipalName"]
Loading

0 comments on commit 7c576be

Please sign in to comment.