from typing import Any, Dict, List, Optional, Tuple, cast

from httpx_oauth.errors import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2

AUTHORIZE_ENDPOINT = "https://discord.com/api/oauth2/authorize"
ACCESS_TOKEN_ENDPOINT = "https://discord.com/api/oauth2/token"
REVOKE_TOKEN_ENDPOINT = "https://discord.com/api/oauth2/token/revoke"
BASE_SCOPES = ["identify", "email"]
PROFILE_ENDPOINT = "https://discord.com/api/users/@me"


LOGO_SVG = """
<svg width="256px" height="199px" viewBox="0 0 256 199" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
    <g>
        <path d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z" fill="#5865F2" fill-rule="nonzero"></path>
    </g>
</svg>
"""


class DiscordOAuth2(BaseOAuth2[Dict[str, Any]]):
    display_name = "Discord"
    logo_svg = LOGO_SVG

    def __init__(
        self,
        client_id: str,
        client_secret: str,
        scopes: Optional[List[str]] = BASE_SCOPES,
        name: str = "discord",
    ):
        super().__init__(
            client_id,
            client_secret,
            AUTHORIZE_ENDPOINT,
            ACCESS_TOKEN_ENDPOINT,
            ACCESS_TOKEN_ENDPOINT,
            REVOKE_TOKEN_ENDPOINT,
            name=name,
            base_scopes=scopes,
        )

    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,
                headers={**self.request_headers, "Authorization": f"Bearer {token}"},
            )

            if response.status_code >= 400:
                raise GetIdEmailError(response.json())

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

            user_id = data["id"]
            user_email = data.get("email")

            if not data.get("verified", False):
                user_email = None

            return user_id, user_email

a30d9cd91bec5860ebb95fd5427011ed10e2b74b
<mask token>


class DiscordOAuth2(BaseOAuth2[Dict[str, Any]]):
    <mask token>
    <mask token>

    def __init__(self, client_id: str, client_secret: str, scopes: Optional
        [List[str]]=BASE_SCOPES, name: str='discord'):
        super().__init__(client_id, client_secret, AUTHORIZE_ENDPOINT,
            ACCESS_TOKEN_ENDPOINT, ACCESS_TOKEN_ENDPOINT,
            REVOKE_TOKEN_ENDPOINT, name=name, base_scopes=scopes)

    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, headers={**self.
                request_headers, 'Authorization': f'Bearer {token}'})
            if response.status_code >= 400:
                raise GetIdEmailError(response.json())
            data = cast(Dict[str, Any], response.json())
            user_id = data['id']
            user_email = data.get('email')
            if not data.get('verified', False):
                user_email = None
            return user_id, user_email

<mask token>


class DiscordOAuth2(BaseOAuth2[Dict[str, Any]]):
    display_name = 'Discord'
    logo_svg = LOGO_SVG

    def __init__(self, client_id: str, client_secret: str, scopes: Optional
        [List[str]]=BASE_SCOPES, name: str='discord'):
        super().__init__(client_id, client_secret, AUTHORIZE_ENDPOINT,
            ACCESS_TOKEN_ENDPOINT, ACCESS_TOKEN_ENDPOINT,
            REVOKE_TOKEN_ENDPOINT, name=name, base_scopes=scopes)

    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, headers={**self.
                request_headers, 'Authorization': f'Bearer {token}'})
            if response.status_code >= 400:
                raise GetIdEmailError(response.json())
            data = cast(Dict[str, Any], response.json())
            user_id = data['id']
            user_email = data.get('email')
            if not data.get('verified', False):
                user_email = None
            return user_id, user_email

<mask token>
AUTHORIZE_ENDPOINT = 'https://discord.com/api/oauth2/authorize'
ACCESS_TOKEN_ENDPOINT = 'https://discord.com/api/oauth2/token'
REVOKE_TOKEN_ENDPOINT = 'https://discord.com/api/oauth2/token/revoke'
BASE_SCOPES = ['identify', 'email']
PROFILE_ENDPOINT = 'https://discord.com/api/users/@me'
LOGO_SVG = """
<svg width="256px" height="199px" viewBox="0 0 256 199" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
    <g>
        <path d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z" fill="#5865F2" fill-rule="nonzero"></path>
    </g>
</svg>
"""


class DiscordOAuth2(BaseOAuth2[Dict[str, Any]]):
    display_name = 'Discord'
    logo_svg = LOGO_SVG

    def __init__(self, client_id: str, client_secret: str, scopes: Optional
        [List[str]]=BASE_SCOPES, name: str='discord'):
        super().__init__(client_id, client_secret, AUTHORIZE_ENDPOINT,
            ACCESS_TOKEN_ENDPOINT, ACCESS_TOKEN_ENDPOINT,
            REVOKE_TOKEN_ENDPOINT, name=name, base_scopes=scopes)

    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, headers={**self.
                request_headers, 'Authorization': f'Bearer {token}'})
            if response.status_code >= 400:
                raise GetIdEmailError(response.json())
            data = cast(Dict[str, Any], response.json())
            user_id = data['id']
            user_email = data.get('email')
            if not data.get('verified', False):
                user_email = None
            return user_id, user_email

from typing import Any, Dict, List, Optional, Tuple, cast
from httpx_oauth.errors import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2
AUTHORIZE_ENDPOINT = 'https://discord.com/api/oauth2/authorize'
ACCESS_TOKEN_ENDPOINT = 'https://discord.com/api/oauth2/token'
REVOKE_TOKEN_ENDPOINT = 'https://discord.com/api/oauth2/token/revoke'
BASE_SCOPES = ['identify', 'email']
PROFILE_ENDPOINT = 'https://discord.com/api/users/@me'
LOGO_SVG = """
<svg width="256px" height="199px" viewBox="0 0 256 199" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
    <g>
        <path d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z" fill="#5865F2" fill-rule="nonzero"></path>
    </g>
</svg>
"""


class DiscordOAuth2(BaseOAuth2[Dict[str, Any]]):
    display_name = 'Discord'
    logo_svg = LOGO_SVG

    def __init__(self, client_id: str, client_secret: str, scopes: Optional
        [List[str]]=BASE_SCOPES, name: str='discord'):
        super().__init__(client_id, client_secret, AUTHORIZE_ENDPOINT,
            ACCESS_TOKEN_ENDPOINT, ACCESS_TOKEN_ENDPOINT,
            REVOKE_TOKEN_ENDPOINT, name=name, base_scopes=scopes)

    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, headers={**self.
                request_headers, 'Authorization': f'Bearer {token}'})
            if response.status_code >= 400:
                raise GetIdEmailError(response.json())
            data = cast(Dict[str, Any], response.json())
            user_id = data['id']
            user_email = data.get('email')
            if not data.get('verified', False):
                user_email = None
            return user_id, user_email

from typing import Any, Dict, List, Optional, Tuple, cast

from httpx_oauth.errors import GetIdEmailError
from httpx_oauth.oauth2 import BaseOAuth2

AUTHORIZE_ENDPOINT = "https://discord.com/api/oauth2/authorize"
ACCESS_TOKEN_ENDPOINT = "https://discord.com/api/oauth2/token"
REVOKE_TOKEN_ENDPOINT = "https://discord.com/api/oauth2/token/revoke"
BASE_SCOPES = ["identify", "email"]
PROFILE_ENDPOINT = "https://discord.com/api/users/@me"


LOGO_SVG = """
<svg width="256px" height="199px" viewBox="0 0 256 199" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
    <g>
        <path d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z" fill="#5865F2" fill-rule="nonzero"></path>
    </g>
</svg>
"""


class DiscordOAuth2(BaseOAuth2[Dict[str, Any]]):
    display_name = "Discord"
    logo_svg = LOGO_SVG

    def __init__(
        self,
        client_id: str,
        client_secret: str,
        scopes: Optional[List[str]] = BASE_SCOPES,
        name: str = "discord",
    ):
        super().__init__(
            client_id,
            client_secret,
            AUTHORIZE_ENDPOINT,
            ACCESS_TOKEN_ENDPOINT,
            ACCESS_TOKEN_ENDPOINT,
            REVOKE_TOKEN_ENDPOINT,
            name=name,
            base_scopes=scopes,
        )

    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,
                headers={**self.request_headers, "Authorization": f"Bearer {token}"},
            )

            if response.status_code >= 400:
                raise GetIdEmailError(response.json())

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

            user_id = data["id"]
            user_email = data.get("email")

            if not data.get("verified", False):
                user_email = None

            return user_id, user_email
