Skip to content

Commit

Permalink
refactor: move magic link types to models folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ctran88 committed Dec 6, 2024
1 parent b5ae906 commit 925d83c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 48 deletions.
3 changes: 3 additions & 0 deletions passageidentity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""Initializes the Passage identity package."""

from .errors import PassageError
from .models import MagicLinkArgs, MagicLinkOptions
from .passage import Passage

__all__ = [
"MagicLinkArgs",
"MagicLinkOptions",
"Passage",
"PassageError",
]
45 changes: 4 additions & 41 deletions passageidentity/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,21 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Union
from typing import TYPE_CHECKING

import jwt
import jwt.algorithms

from passageidentity.errors import PassageError
from passageidentity.helper import fetch_app
from passageidentity.models.magic_link_args import MagicLinkWithEmailArgs, MagicLinkWithPhoneArgs, MagicLinkWithUserArgs
from passageidentity.openapi_client.api.magic_links_api import MagicLinksApi
from passageidentity.openapi_client.exceptions import ApiException

if TYPE_CHECKING:
from passageidentity.models.magic_link_args import MagicLinkArgs
from passageidentity.models.magic_link_options import MagicLinkOptions
from passageidentity.openapi_client.models.magic_link import MagicLink
from passageidentity.openapi_client.models.magic_link_channel import MagicLinkChannel
from passageidentity.openapi_client.models.magic_link_type import MagicLinkType


class MagicLinkArgsBase:
"""Base class for MagicLinkArgs."""

type: MagicLinkType
send: bool


class MagicLinkWithEmailArgs(MagicLinkArgsBase):
"""Arguments for creating a Magic Link with an email."""

email: str


class MagicLinkWithPhoneArgs(MagicLinkArgsBase):
"""Arguments for creating a Magic Link with a phone number."""

phone: str


class MagicLinkWithUserArgs(MagicLinkArgsBase):
"""Arguments for creating a Magic Link with a user ID."""

user_id: str
channel: MagicLinkChannel


MagicLinkArgs = Union[MagicLinkWithEmailArgs, MagicLinkWithPhoneArgs, MagicLinkWithUserArgs]


class MagicLinkOptions:
"""Options for creating a Magic Link."""

language: str | None
magic_link_path: str | None
redirect_url: str | None
ttl: int | None


class Auth:
Expand Down
2 changes: 2 additions & 0 deletions passageidentity/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
)
from passageidentity.models.update_passkey_auth_method import UpdatePasskeysAuthMethod
from passageidentity.models.update_otp_auth_method import UpdateOtpAuthMethod
from passageidentity.models.magic_link_args import MagicLinkArgs
from passageidentity.models.magic_link_options import MagicLinkOptions
35 changes: 35 additions & 0 deletions passageidentity/models/magic_link_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Defines required arguments for creating a Magic Link."""

from typing import Union

from passageidentity.openapi_client.models.magic_link_channel import MagicLinkChannel
from passageidentity.openapi_client.models.magic_link_type import MagicLinkType


class MagicLinkArgsBase:
"""Base class for MagicLinkArgs."""

type: MagicLinkType
send: bool


class MagicLinkWithEmailArgs(MagicLinkArgsBase):
"""Arguments for creating a Magic Link with an email."""

email: str


class MagicLinkWithPhoneArgs(MagicLinkArgsBase):
"""Arguments for creating a Magic Link with a phone number."""

phone: str


class MagicLinkWithUserArgs(MagicLinkArgsBase):
"""Arguments for creating a Magic Link with a user ID."""

user_id: str
channel: MagicLinkChannel


MagicLinkArgs = Union[MagicLinkWithEmailArgs, MagicLinkWithPhoneArgs, MagicLinkWithUserArgs]
12 changes: 12 additions & 0 deletions passageidentity/models/magic_link_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Defines options for creating a Magic Link."""

from __future__ import annotations


class MagicLinkOptions:
"""Options for creating a Magic Link."""

language: str | None
magic_link_path: str | None
redirect_url: str | None
ttl: int | None
10 changes: 3 additions & 7 deletions passageidentity/passage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@

import typing_extensions

from passageidentity.auth import (
Auth,
MagicLinkOptions,
MagicLinkWithEmailArgs,
MagicLinkWithPhoneArgs,
MagicLinkWithUserArgs,
)
from passageidentity.auth import Auth
from passageidentity.errors import PassageError
from passageidentity.helper import get_auth_token_from_request
from passageidentity.models.magic_link_args import MagicLinkWithEmailArgs, MagicLinkWithPhoneArgs, MagicLinkWithUserArgs
from passageidentity.models.magic_link_options import MagicLinkOptions
from passageidentity.openapi_client.models.magic_link_channel import MagicLinkChannel
from passageidentity.user import User

Expand Down

0 comments on commit 925d83c

Please sign in to comment.