diff --git a/examples/facebook.py b/examples/facebook.py index bbd0fca..4ce2958 100644 --- a/examples/facebook.py +++ b/examples/facebook.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.facebook import FacebookSSO +from litestar_sso.providers.facebook import FacebookSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/fitbit.py b/examples/fitbit.py index 39a971d..39d6e0c 100644 --- a/examples/fitbit.py +++ b/examples/fitbit.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.fitbit import FitbitSSO +from litestar_sso.providers.fitbit import FitbitSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/generic.py b/examples/generic.py index 6dcc23d..8df8cc3 100644 --- a/examples/generic.py +++ b/examples/generic.py @@ -8,7 +8,7 @@ from litestar.exceptions import HTTPException from litestar_sso.base import DiscoveryDocument, OpenID -from litestar_sso.sso.generic import create_provider +from litestar_sso.providers.generic import create_provider app = Litestar() diff --git a/examples/github.py b/examples/github.py index 3860dab..b1f08d6 100644 --- a/examples/github.py +++ b/examples/github.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.github import GithubSSO +from litestar_sso.providers.github import GithubSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/gitlab.py b/examples/gitlab.py index f921b66..e9aaa8b 100644 --- a/examples/gitlab.py +++ b/examples/gitlab.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.gitlab import GitlabSSO +from litestar_sso.providers.gitlab import GitlabSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/google.py b/examples/google.py index daeb555..0b468a7 100644 --- a/examples/google.py +++ b/examples/google.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.google import GoogleSSO +from litestar_sso.providers.google import GoogleSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/kakao.py b/examples/kakao.py index 82f3ba2..8d4b918 100644 --- a/examples/kakao.py +++ b/examples/kakao.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.kakao import KakaoSSO +from litestar_sso.providers.kakao import KakaoSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/line.py b/examples/line.py index 924c0db..0579157 100644 --- a/examples/line.py +++ b/examples/line.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.line import LineSSO +from litestar_sso.providers.line import LineSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/linkedin.py b/examples/linkedin.py index 8cd4122..d492aac 100644 --- a/examples/linkedin.py +++ b/examples/linkedin.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.linkedin import LinkedInSSO +from litestar_sso.providers.linkedin import LinkedInSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/microsoft.py b/examples/microsoft.py index ef04a0d..7a024f9 100644 --- a/examples/microsoft.py +++ b/examples/microsoft.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.microsoft import MicrosoftSSO +from litestar_sso.providers.microsoft import MicrosoftSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/naver.py b/examples/naver.py index 8d66eb3..3f17fee 100644 --- a/examples/naver.py +++ b/examples/naver.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.naver import NaverSSO +from litestar_sso.providers.naver import NaverSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/notion.py b/examples/notion.py index 6488b0f..fa6d4bd 100644 --- a/examples/notion.py +++ b/examples/notion.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.notion import NotionSSO +from litestar_sso.providers.notion import NotionSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/seznam.py b/examples/seznam.py index 1444b9e..959dcce 100644 --- a/examples/seznam.py +++ b/examples/seznam.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.seznam import SeznamSSO +from litestar_sso.providers.seznam import SeznamSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/twitter.py b/examples/twitter.py index e58800c..33e9180 100644 --- a/examples/twitter.py +++ b/examples/twitter.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.twitter import TwitterSSO +from litestar_sso.providers.twitter import TwitterSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/examples/yandex.py b/examples/yandex.py index 2ccb005..3a41ec1 100644 --- a/examples/yandex.py +++ b/examples/yandex.py @@ -5,7 +5,7 @@ import uvicorn from litestar import Litestar, Request, get -from litestar_sso.sso.yandex import YandexSSO +from litestar_sso.providers.yandex import YandexSSO CLIENT_ID = os.environ["CLIENT_ID"] CLIENT_SECRET = os.environ["CLIENT_SECRET"] diff --git a/litestar_sso/__init__.py b/litestar_sso/__init__.py index aaee94f..0b09732 100644 --- a/litestar_sso/__init__.py +++ b/litestar_sso/__init__.py @@ -4,20 +4,20 @@ """ from .base import OpenID, SSOBase, SSOLoginError -from .sso.facebook import FacebookSSO -from .sso.fitbit import FitbitSSO -from .sso.generic import create_provider -from .sso.github import GithubSSO -from .sso.gitlab import GitlabSSO -from .sso.google import GoogleSSO -from .sso.kakao import KakaoSSO -from .sso.line import LineSSO -from .sso.linkedin import LinkedInSSO -from .sso.microsoft import MicrosoftSSO -from .sso.naver import NaverSSO -from .sso.notion import NotionSSO -from .sso.spotify import SpotifySSO -from .sso.twitter import TwitterSSO +from .providers.facebook import FacebookSSO +from .providers.fitbit import FitbitSSO +from .providers.generic import create_provider +from .providers.github import GithubSSO +from .providers.gitlab import GitlabSSO +from .providers.google import GoogleSSO +from .providers.kakao import KakaoSSO +from .providers.line import LineSSO +from .providers.linkedin import LinkedInSSO +from .providers.microsoft import MicrosoftSSO +from .providers.naver import NaverSSO +from .providers.notion import NotionSSO +from .providers.spotify import SpotifySSO +from .providers.twitter import TwitterSSO __all__ = [ "OpenID", diff --git a/litestar_sso/base.py b/litestar_sso/base.py index 9ef82b0..296a3cb 100644 --- a/litestar_sso/base.py +++ b/litestar_sso/base.py @@ -12,12 +12,12 @@ import httpx import pydantic from litestar import Request -from litestar.exceptions import HTTPException from litestar.response import Redirect from oauthlib.oauth2 import WebApplicationClient from litestar_sso.pkce import get_pkce_challenge_pair -from litestar_sso.state import generate_random_state +from litestar_sso.utils import generate_random_state +from litestar_sso.exceptions import SecurityWarning, UnsetStateWarning, ReusedOauthClientWarning, SSOLoginError if sys.version_info < (3, 10): from typing import Callable @@ -41,21 +41,6 @@ class DiscoveryDocument(TypedDict): userinfo_endpoint: str -class UnsetStateWarning(UserWarning): - """Warning about unset state parameter.""" - - -class ReusedOauthClientWarning(UserWarning): - """Warning about reused oauth client instance.""" - - -class SSOLoginError(HTTPException): - """Raised when any login-related error ocurrs. - - Such as when user is not verified or if there was an attempt for fake login. - """ - - class OpenID(pydantic.BaseModel): """Class (schema) to represent information got from sso provider in a common form.""" @@ -68,10 +53,6 @@ class OpenID(pydantic.BaseModel): provider: Optional[str] = None -class SecurityWarning(UserWarning): - """Raised when insecure usage is detected""" - - def requires_async_context(func: Callable[P, T]) -> Callable[P, T]: def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: if not args or not isinstance(args[0], SSOBase): diff --git a/litestar_sso/exceptions.py b/litestar_sso/exceptions.py new file mode 100644 index 0000000..4aac8ac --- /dev/null +++ b/litestar_sso/exceptions.py @@ -0,0 +1,20 @@ +from litestar.exceptions import HTTPException + + +class UnsetStateWarning(UserWarning): + """Warning about unset state parameter.""" + + +class ReusedOauthClientWarning(UserWarning): + """Warning about reused oauth client instance.""" + + +class SSOLoginError(HTTPException): + """Raised when any login-related error ocurrs. + + Such as when user is not verified or if there was an attempt for fake login. + """ + + +class SecurityWarning(UserWarning): + """Raised when insecure usage is detected""" diff --git a/litestar_sso/sso/__init__.py b/litestar_sso/providers/__init__.py similarity index 100% rename from litestar_sso/sso/__init__.py rename to litestar_sso/providers/__init__.py diff --git a/litestar_sso/sso/facebook.py b/litestar_sso/providers/facebook.py similarity index 100% rename from litestar_sso/sso/facebook.py rename to litestar_sso/providers/facebook.py diff --git a/litestar_sso/sso/fitbit.py b/litestar_sso/providers/fitbit.py similarity index 100% rename from litestar_sso/sso/fitbit.py rename to litestar_sso/providers/fitbit.py diff --git a/litestar_sso/sso/generic.py b/litestar_sso/providers/generic.py similarity index 100% rename from litestar_sso/sso/generic.py rename to litestar_sso/providers/generic.py diff --git a/litestar_sso/sso/github.py b/litestar_sso/providers/github.py similarity index 100% rename from litestar_sso/sso/github.py rename to litestar_sso/providers/github.py diff --git a/litestar_sso/sso/gitlab.py b/litestar_sso/providers/gitlab.py similarity index 100% rename from litestar_sso/sso/gitlab.py rename to litestar_sso/providers/gitlab.py diff --git a/litestar_sso/sso/google.py b/litestar_sso/providers/google.py similarity index 100% rename from litestar_sso/sso/google.py rename to litestar_sso/providers/google.py diff --git a/litestar_sso/sso/kakao.py b/litestar_sso/providers/kakao.py similarity index 100% rename from litestar_sso/sso/kakao.py rename to litestar_sso/providers/kakao.py diff --git a/litestar_sso/sso/line.py b/litestar_sso/providers/line.py similarity index 100% rename from litestar_sso/sso/line.py rename to litestar_sso/providers/line.py diff --git a/litestar_sso/sso/linkedin.py b/litestar_sso/providers/linkedin.py similarity index 100% rename from litestar_sso/sso/linkedin.py rename to litestar_sso/providers/linkedin.py diff --git a/litestar_sso/sso/microsoft.py b/litestar_sso/providers/microsoft.py similarity index 100% rename from litestar_sso/sso/microsoft.py rename to litestar_sso/providers/microsoft.py diff --git a/litestar_sso/sso/naver.py b/litestar_sso/providers/naver.py similarity index 100% rename from litestar_sso/sso/naver.py rename to litestar_sso/providers/naver.py diff --git a/litestar_sso/sso/notion.py b/litestar_sso/providers/notion.py similarity index 100% rename from litestar_sso/sso/notion.py rename to litestar_sso/providers/notion.py diff --git a/litestar_sso/sso/seznam.py b/litestar_sso/providers/seznam.py similarity index 100% rename from litestar_sso/sso/seznam.py rename to litestar_sso/providers/seznam.py diff --git a/litestar_sso/sso/spotify.py b/litestar_sso/providers/spotify.py similarity index 100% rename from litestar_sso/sso/spotify.py rename to litestar_sso/providers/spotify.py diff --git a/litestar_sso/sso/twitter.py b/litestar_sso/providers/twitter.py similarity index 100% rename from litestar_sso/sso/twitter.py rename to litestar_sso/providers/twitter.py diff --git a/litestar_sso/sso/yandex.py b/litestar_sso/providers/yandex.py similarity index 100% rename from litestar_sso/sso/yandex.py rename to litestar_sso/providers/yandex.py diff --git a/litestar_sso/state.py b/litestar_sso/utils.py similarity index 100% rename from litestar_sso/state.py rename to litestar_sso/utils.py diff --git a/tests/test_generic_provider.py b/tests/test_generic_provider.py index e64f9e5..0c51ef3 100644 --- a/tests/test_generic_provider.py +++ b/tests/test_generic_provider.py @@ -1,5 +1,5 @@ from litestar_sso.base import OpenID -from litestar_sso.sso.generic import create_provider +from litestar_sso.providers.generic import create_provider DISCOVERY = { "authorization_endpoint": "http://localhost:9090/auth", diff --git a/tests/test_openid_responses.py b/tests/test_openid_responses.py index a71154a..250a1a0 100644 --- a/tests/test_openid_responses.py +++ b/tests/test_openid_responses.py @@ -3,18 +3,18 @@ import pytest from litestar_sso.base import OpenID, SSOBase -from litestar_sso.sso.facebook import FacebookSSO -from litestar_sso.sso.fitbit import FitbitSSO -from litestar_sso.sso.github import GithubSSO -from litestar_sso.sso.gitlab import GitlabSSO -from litestar_sso.sso.kakao import KakaoSSO -from litestar_sso.sso.line import LineSSO -from litestar_sso.sso.linkedin import LinkedInSSO -from litestar_sso.sso.microsoft import MicrosoftSSO -from litestar_sso.sso.naver import NaverSSO -from litestar_sso.sso.spotify import SpotifySSO -from litestar_sso.sso.twitter import TwitterSSO -from litestar_sso.sso.yandex import YandexSSO +from litestar_sso.providers.facebook import FacebookSSO +from litestar_sso.providers.fitbit import FitbitSSO +from litestar_sso.providers.github import GithubSSO +from litestar_sso.providers.gitlab import GitlabSSO +from litestar_sso.providers.kakao import KakaoSSO +from litestar_sso.providers.line import LineSSO +from litestar_sso.providers.linkedin import LinkedInSSO +from litestar_sso.providers.microsoft import MicrosoftSSO +from litestar_sso.providers.naver import NaverSSO +from litestar_sso.providers.spotify import SpotifySSO +from litestar_sso.providers.twitter import TwitterSSO +from litestar_sso.providers.yandex import YandexSSO sso_test_cases: Tuple[Tuple[Type[SSOBase], Dict[str, Any], OpenID], ...] = ( ( diff --git a/tests/test_providers.py b/tests/test_providers.py index 2b77835..6c813db 100644 --- a/tests/test_providers.py +++ b/tests/test_providers.py @@ -11,22 +11,22 @@ from litestar_sso.base import OpenID from litestar_sso.base import SSOBase from litestar_sso.base import SecurityWarning -from litestar_sso.sso.facebook import FacebookSSO -from litestar_sso.sso.fitbit import FitbitSSO -from litestar_sso.sso.generic import create_provider -from litestar_sso.sso.github import GithubSSO -from litestar_sso.sso.gitlab import GitlabSSO -from litestar_sso.sso.google import GoogleSSO -from litestar_sso.sso.kakao import KakaoSSO -from litestar_sso.sso.line import LineSSO -from litestar_sso.sso.linkedin import LinkedInSSO -from litestar_sso.sso.microsoft import MicrosoftSSO -from litestar_sso.sso.naver import NaverSSO -from litestar_sso.sso.notion import NotionSSO -from litestar_sso.sso.seznam import SeznamSSO -from litestar_sso.sso.spotify import SpotifySSO -from litestar_sso.sso.twitter import TwitterSSO -from litestar_sso.sso.yandex import YandexSSO +from litestar_sso.providers.facebook import FacebookSSO +from litestar_sso.providers.fitbit import FitbitSSO +from litestar_sso.providers.generic import create_provider +from litestar_sso.providers.github import GithubSSO +from litestar_sso.providers.gitlab import GitlabSSO +from litestar_sso.providers.google import GoogleSSO +from litestar_sso.providers.kakao import KakaoSSO +from litestar_sso.providers.line import LineSSO +from litestar_sso.providers.linkedin import LinkedInSSO +from litestar_sso.providers.microsoft import MicrosoftSSO +from litestar_sso.providers.naver import NaverSSO +from litestar_sso.providers.notion import NotionSSO +from litestar_sso.providers.seznam import SeznamSSO +from litestar_sso.providers.spotify import SpotifySSO +from litestar_sso.providers.twitter import TwitterSSO +from litestar_sso.providers.yandex import YandexSSO GenericProvider = create_provider( name="generic",