Module supertokens_python.recipe.totp.types

Expand source code
# Copyright (c) 2024, VRAI Labs and/or its affiliates. All rights reserved.
#
# This software is licensed under the Apache License, Version 2.0 (the
# "License") as published by the Apache Software Foundation.
#
# You may not use this file except in compliance with the License. You may
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from typing import List, Dict, Any, Callable, Optional
from typing_extensions import Literal
from .interfaces import RecipeInterface, APIInterface

from supertokens_python.types import APIResponse


class OkResult(APIResponse):
    def __init__(self):
        self.status: Literal["OK"] = "OK"


class UserIdentifierInfoOkResult(OkResult):
    def __init__(self, info: str):
        super().__init__()
        self.info: str = info

    def to_json(self) -> Dict[str, Any]:
        raise NotImplementedError()


class UnknownUserIdError(APIResponse):
    def __init__(self):
        self.status: Literal["UNKNOWN_USER_ID_ERROR"] = "UNKNOWN_USER_ID_ERROR"

    def to_json(self) -> Dict[str, Any]:
        return {"status": self.status}


class UserIdentifierInfoDoesNotExistError:
    def __init__(self):
        self.status: Literal[
            "USER_IDENTIFIER_INFO_DOES_NOT_EXIST_ERROR"
        ] = "USER_IDENTIFIER_INFO_DOES_NOT_EXIST_ERROR"


class CreateDeviceOkResult(OkResult):
    def __init__(self, device_name: str, secret: str, qr_code_string: str):
        super().__init__()
        self.device_name: str = device_name
        self.secret: str = secret
        self.qr_code_string: str = qr_code_string

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "deviceName": self.device_name,
            "secret": self.secret,
            "qrCodeString": self.qr_code_string,
        }


class DeviceAlreadyExistsError(APIResponse):
    def __init__(self):
        self.status: Literal[
            "DEVICE_ALREADY_EXISTS_ERROR"
        ] = "DEVICE_ALREADY_EXISTS_ERROR"

    def to_json(self) -> Dict[str, Any]:
        return {"status": self.status}


class UpdateDeviceOkResult(OkResult):
    def to_json(self) -> Dict[str, Any]:
        raise NotImplementedError()


class UnknownDeviceError(APIResponse):
    def __init__(self):
        self.status: Literal["UNKNOWN_DEVICE_ERROR"] = "UNKNOWN_DEVICE_ERROR"

    def to_json(self) -> Dict[str, Any]:
        return {"status": self.status}


class Device(APIResponse):
    def __init__(self, name: str, period: int, skew: int, verified: bool):
        self.name: str = name
        self.period: int = period
        self.skew: int = skew
        self.verified: bool = verified

    def to_json(self) -> Dict[str, Any]:
        return {
            "name": self.name,
            "period": self.period,
            "skew": self.skew,
            "verified": self.verified,
        }


class ListDevicesOkResult(OkResult):
    def __init__(self, devices: List[Device]):
        super().__init__()
        self.devices: List[Device] = devices

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "devices": [device.to_json() for device in self.devices],
        }


class RemoveDeviceOkResult(OkResult):
    def __init__(self, did_device_exist: bool):
        super().__init__()
        self.did_device_exist: bool = did_device_exist

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "didDeviceExist": self.did_device_exist,
        }


class VerifyDeviceOkResult(OkResult):
    def __init__(
        self,
        was_already_verified: bool,
    ):
        super().__init__()
        self.was_already_verified: bool = was_already_verified

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "wasAlreadyVerified": self.was_already_verified,
        }


class InvalidTOTPError(APIResponse):
    def __init__(
        self, current_number_of_failed_attempts: int, max_number_of_failed_attempts: int
    ):
        self.status: Literal["INVALID_TOTP_ERROR"] = "INVALID_TOTP_ERROR"
        self.current_number_of_failed_attempts: int = current_number_of_failed_attempts
        self.max_number_of_failed_attempts: int = max_number_of_failed_attempts

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "currentNumberOfFailedAttempts": self.current_number_of_failed_attempts,
            "maxNumberOfFailedAttempts": self.max_number_of_failed_attempts,
        }


class LimitReachedError(APIResponse):
    def __init__(self, retry_after_ms: int):
        self.status: Literal["LIMIT_REACHED_ERROR"] = "LIMIT_REACHED_ERROR"
        self.retry_after_ms: int = retry_after_ms

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "retryAfterMs": self.retry_after_ms,
        }


class VerifyTOTPOkResult(OkResult):
    def to_json(self) -> Dict[str, Any]:
        return {"status": self.status}


class OverrideConfig:
    def __init__(
        self,
        functions: Optional[Callable[[RecipeInterface], RecipeInterface]] = None,
        apis: Optional[Callable[[APIInterface], APIInterface]] = None,
    ):
        self.functions = functions
        self.apis = apis


class TOTPConfig:
    def __init__(
        self,
        issuer: Optional[str] = None,
        default_skew: Optional[int] = None,
        default_period: Optional[int] = None,
        override: Optional[OverrideConfig] = None,
    ):
        self.issuer = issuer
        self.default_skew = default_skew
        self.default_period = default_period
        self.override = override


class TOTPNormalisedConfig:
    def __init__(
        self,
        issuer: str,
        default_skew: int,
        default_period: int,
        override: OverrideConfig,
    ):
        self.issuer = issuer
        self.default_skew = default_skew
        self.default_period = default_period
        self.override = override

Classes

class CreateDeviceOkResult (device_name: str, secret: str, qr_code_string: str)

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class CreateDeviceOkResult(OkResult):
    def __init__(self, device_name: str, secret: str, qr_code_string: str):
        super().__init__()
        self.device_name: str = device_name
        self.secret: str = secret
        self.qr_code_string: str = qr_code_string

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "deviceName": self.device_name,
            "secret": self.secret,
            "qrCodeString": self.qr_code_string,
        }

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {
        "status": self.status,
        "deviceName": self.device_name,
        "secret": self.secret,
        "qrCodeString": self.qr_code_string,
    }
class Device (name: str, period: int, skew: int, verified: bool)

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class Device(APIResponse):
    def __init__(self, name: str, period: int, skew: int, verified: bool):
        self.name: str = name
        self.period: int = period
        self.skew: int = skew
        self.verified: bool = verified

    def to_json(self) -> Dict[str, Any]:
        return {
            "name": self.name,
            "period": self.period,
            "skew": self.skew,
            "verified": self.verified,
        }

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {
        "name": self.name,
        "period": self.period,
        "skew": self.skew,
        "verified": self.verified,
    }
class DeviceAlreadyExistsError

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class DeviceAlreadyExistsError(APIResponse):
    def __init__(self):
        self.status: Literal[
            "DEVICE_ALREADY_EXISTS_ERROR"
        ] = "DEVICE_ALREADY_EXISTS_ERROR"

    def to_json(self) -> Dict[str, Any]:
        return {"status": self.status}

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {"status": self.status}
class InvalidTOTPError (current_number_of_failed_attempts: int, max_number_of_failed_attempts: int)

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class InvalidTOTPError(APIResponse):
    def __init__(
        self, current_number_of_failed_attempts: int, max_number_of_failed_attempts: int
    ):
        self.status: Literal["INVALID_TOTP_ERROR"] = "INVALID_TOTP_ERROR"
        self.current_number_of_failed_attempts: int = current_number_of_failed_attempts
        self.max_number_of_failed_attempts: int = max_number_of_failed_attempts

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "currentNumberOfFailedAttempts": self.current_number_of_failed_attempts,
            "maxNumberOfFailedAttempts": self.max_number_of_failed_attempts,
        }

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {
        "status": self.status,
        "currentNumberOfFailedAttempts": self.current_number_of_failed_attempts,
        "maxNumberOfFailedAttempts": self.max_number_of_failed_attempts,
    }
class LimitReachedError (retry_after_ms: int)

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class LimitReachedError(APIResponse):
    def __init__(self, retry_after_ms: int):
        self.status: Literal["LIMIT_REACHED_ERROR"] = "LIMIT_REACHED_ERROR"
        self.retry_after_ms: int = retry_after_ms

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "retryAfterMs": self.retry_after_ms,
        }

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {
        "status": self.status,
        "retryAfterMs": self.retry_after_ms,
    }
class ListDevicesOkResult (devices: List[Device])

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class ListDevicesOkResult(OkResult):
    def __init__(self, devices: List[Device]):
        super().__init__()
        self.devices: List[Device] = devices

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "devices": [device.to_json() for device in self.devices],
        }

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {
        "status": self.status,
        "devices": [device.to_json() for device in self.devices],
    }
class OkResult

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class OkResult(APIResponse):
    def __init__(self):
        self.status: Literal["OK"] = "OK"

Ancestors

Subclasses

class OverrideConfig (functions: Optional[Callable[[RecipeInterface], RecipeInterface]] = None, apis: Optional[Callable[[APIInterface], APIInterface]] = None)
Expand source code
class OverrideConfig:
    def __init__(
        self,
        functions: Optional[Callable[[RecipeInterface], RecipeInterface]] = None,
        apis: Optional[Callable[[APIInterface], APIInterface]] = None,
    ):
        self.functions = functions
        self.apis = apis
class RemoveDeviceOkResult (did_device_exist: bool)

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class RemoveDeviceOkResult(OkResult):
    def __init__(self, did_device_exist: bool):
        super().__init__()
        self.did_device_exist: bool = did_device_exist

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "didDeviceExist": self.did_device_exist,
        }

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {
        "status": self.status,
        "didDeviceExist": self.did_device_exist,
    }
class TOTPConfig (issuer: Optional[str] = None, default_skew: Optional[int] = None, default_period: Optional[int] = None, override: Optional[OverrideConfig] = None)
Expand source code
class TOTPConfig:
    def __init__(
        self,
        issuer: Optional[str] = None,
        default_skew: Optional[int] = None,
        default_period: Optional[int] = None,
        override: Optional[OverrideConfig] = None,
    ):
        self.issuer = issuer
        self.default_skew = default_skew
        self.default_period = default_period
        self.override = override
class TOTPNormalisedConfig (issuer: str, default_skew: int, default_period: int, override: OverrideConfig)
Expand source code
class TOTPNormalisedConfig:
    def __init__(
        self,
        issuer: str,
        default_skew: int,
        default_period: int,
        override: OverrideConfig,
    ):
        self.issuer = issuer
        self.default_skew = default_skew
        self.default_period = default_period
        self.override = override
class UnknownDeviceError

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class UnknownDeviceError(APIResponse):
    def __init__(self):
        self.status: Literal["UNKNOWN_DEVICE_ERROR"] = "UNKNOWN_DEVICE_ERROR"

    def to_json(self) -> Dict[str, Any]:
        return {"status": self.status}

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {"status": self.status}
class UnknownUserIdError

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class UnknownUserIdError(APIResponse):
    def __init__(self):
        self.status: Literal["UNKNOWN_USER_ID_ERROR"] = "UNKNOWN_USER_ID_ERROR"

    def to_json(self) -> Dict[str, Any]:
        return {"status": self.status}

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {"status": self.status}
class UpdateDeviceOkResult

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class UpdateDeviceOkResult(OkResult):
    def to_json(self) -> Dict[str, Any]:
        raise NotImplementedError()

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    raise NotImplementedError()
class UserIdentifierInfoDoesNotExistError
Expand source code
class UserIdentifierInfoDoesNotExistError:
    def __init__(self):
        self.status: Literal[
            "USER_IDENTIFIER_INFO_DOES_NOT_EXIST_ERROR"
        ] = "USER_IDENTIFIER_INFO_DOES_NOT_EXIST_ERROR"
class UserIdentifierInfoOkResult (info: str)

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class UserIdentifierInfoOkResult(OkResult):
    def __init__(self, info: str):
        super().__init__()
        self.info: str = info

    def to_json(self) -> Dict[str, Any]:
        raise NotImplementedError()

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    raise NotImplementedError()
class VerifyDeviceOkResult (was_already_verified: bool)

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class VerifyDeviceOkResult(OkResult):
    def __init__(
        self,
        was_already_verified: bool,
    ):
        super().__init__()
        self.was_already_verified: bool = was_already_verified

    def to_json(self) -> Dict[str, Any]:
        return {
            "status": self.status,
            "wasAlreadyVerified": self.was_already_verified,
        }

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {
        "status": self.status,
        "wasAlreadyVerified": self.was_already_verified,
    }
class VerifyTOTPOkResult

Helper class that provides a standard way to create an ABC using inheritance.

Expand source code
class VerifyTOTPOkResult(OkResult):
    def to_json(self) -> Dict[str, Any]:
        return {"status": self.status}

Ancestors

Methods

def to_json(self) ‑> Dict[str, Any]
Expand source code
def to_json(self) -> Dict[str, Any]:
    return {"status": self.status}