Skip to content

Commit

Permalink
feat: to providers
Browse files Browse the repository at this point in the history
  • Loading branch information
ccrvlh committed Nov 3, 2024
1 parent 5fbce08 commit ff16b41
Show file tree
Hide file tree
Showing 39 changed files with 80 additions and 79 deletions.
2 changes: 1 addition & 1 deletion examples/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/fitbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion examples/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/kakao.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/microsoft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/naver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/seznam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/yandex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
28 changes: 14 additions & 14 deletions litestar_sso/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 2 additions & 21 deletions litestar_sso/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""

Expand All @@ -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):
Expand Down
20 changes: 20 additions & 0 deletions litestar_sso/exceptions.py
Original file line number Diff line number Diff line change
@@ -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"""
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_generic_provider.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 12 additions & 12 deletions tests/test_openid_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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], ...] = (
(
Expand Down
32 changes: 16 additions & 16 deletions tests/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ff16b41

Please sign in to comment.