Module redvox.cloud.auth_api

This module contains classes and functions for interacting with the RedVox Cloud API authentication endpoints.

Expand source code
"""
This module contains classes and functions for interacting with the RedVox Cloud API authentication endpoints.
"""

from dataclasses import dataclass
from typing import Callable, Optional

from dataclasses_json import dataclass_json
import requests

from redvox.cloud.api import post_req
from redvox.cloud.config import RedVoxConfig
from redvox.cloud.routes import RoutesV1


@dataclass_json
@dataclass
class AuthReq:
    """
    An authentication request.
    """

    email: str
    password: str


@dataclass_json
@dataclass
class AuthResp:
    """
    An authentication response.
    """

    status: int
    auth_token: Optional[str]
    claims: Optional["ValidateTokenResp"]

    def is_success(self) -> bool:
        """
        :return: Returns true if the auth response was a success, false otherwise.
        """
        return (
            self.status == 200
            and self.auth_token is not None
            and len(self.auth_token) > 0
        )


@dataclass_json
@dataclass
class ValidateTokenReq:
    """
    A token validation request.
    """

    auth_token: str


@dataclass_json
@dataclass
class ValidateTokenResp:
    """
    A verified token response.
    """

    aud: str
    exp: str
    iat: str
    iss: str
    nbf: str
    sub: str
    tier: str


@dataclass_json
@dataclass
class RefreshTokenReq:
    """
    A token validation request.
    """

    auth_token: str


@dataclass_json
@dataclass
class RefreshTokenResp:
    """
    A token validation request.
    """

    auth_token: Optional[str]
    claims: Optional[ValidateTokenResp]


def authenticate_user(
    redvox_config: RedVoxConfig,
    authentication_request: AuthReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> AuthResp:
    """
    Attempts to authenticate a RedVox user.
    :param redvox_config: Api configuration.
    :param authentication_request: An instance of an authentication request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: An instance of an authentication response.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response], AuthResp
    ] = lambda resp: AuthResp.from_dict(resp.json())
    res: Optional[AuthResp] = post_req(
        redvox_config,
        RoutesV1.AUTH_USER,
        authentication_request,
        handle_resp,
        session,
        timeout,
    )

    return res if res else AuthResp(401, None, None)


def validate_token(
    redvox_config: RedVoxConfig,
    validate_token_req: ValidateTokenReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[ValidateTokenResp]:
    """
    Attempt to validate the provided auth token.
    :param redvox_config: The Api config.
    :param validate_token_req: A validation token req.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: A ValidateTokenResp when the token is valid, None otherwise.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response], ValidateTokenResp
    ] = lambda resp: ValidateTokenResp.from_dict(resp.json())
    return post_req(
        redvox_config,
        RoutesV1.VALIDATE_TOKEN,
        validate_token_req,
        handle_resp,
        session,
        timeout,
    )


def refresh_token(
    redvox_config: RedVoxConfig,
    refresh_token_req: RefreshTokenReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[RefreshTokenResp]:
    """
    Attempt to refresh the given authentication token.
    :param redvox_config: The Api config.
    :param refresh_token_req: The request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: An instance of a RefreshTokenResp.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response], RefreshTokenResp
    ] = lambda resp: RefreshTokenResp.from_dict(resp.json())
    return post_req(
        redvox_config,
        RoutesV1.REFRESH_TOKEN,
        refresh_token_req,
        handle_resp,
        session,
        timeout,
    )

Functions

def authenticate_user(redvox_config: RedVoxConfig, authentication_request: AuthReq, session: Optional[requests.sessions.Session] = None, timeout: Optional[float] = None) ‑> AuthResp

Attempts to authenticate a RedVox user. :param redvox_config: Api configuration. :param authentication_request: An instance of an authentication request. :param session: An (optional) session for re-using an HTTP client. :param timeout: An (optional) timeout. :return: An instance of an authentication response.

Expand source code
def authenticate_user(
    redvox_config: RedVoxConfig,
    authentication_request: AuthReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> AuthResp:
    """
    Attempts to authenticate a RedVox user.
    :param redvox_config: Api configuration.
    :param authentication_request: An instance of an authentication request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: An instance of an authentication response.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response], AuthResp
    ] = lambda resp: AuthResp.from_dict(resp.json())
    res: Optional[AuthResp] = post_req(
        redvox_config,
        RoutesV1.AUTH_USER,
        authentication_request,
        handle_resp,
        session,
        timeout,
    )

    return res if res else AuthResp(401, None, None)
def refresh_token(redvox_config: RedVoxConfig, refresh_token_req: RefreshTokenReq, session: Optional[requests.sessions.Session] = None, timeout: Optional[float] = None) ‑> Optional[RefreshTokenResp]

Attempt to refresh the given authentication token. :param redvox_config: The Api config. :param refresh_token_req: The request. :param session: An (optional) session for re-using an HTTP client. :param timeout: An (optional) timeout. :return: An instance of a RefreshTokenResp.

Expand source code
def refresh_token(
    redvox_config: RedVoxConfig,
    refresh_token_req: RefreshTokenReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[RefreshTokenResp]:
    """
    Attempt to refresh the given authentication token.
    :param redvox_config: The Api config.
    :param refresh_token_req: The request.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: An instance of a RefreshTokenResp.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response], RefreshTokenResp
    ] = lambda resp: RefreshTokenResp.from_dict(resp.json())
    return post_req(
        redvox_config,
        RoutesV1.REFRESH_TOKEN,
        refresh_token_req,
        handle_resp,
        session,
        timeout,
    )
def validate_token(redvox_config: RedVoxConfig, validate_token_req: ValidateTokenReq, session: Optional[requests.sessions.Session] = None, timeout: Optional[float] = None) ‑> Optional[ValidateTokenResp]

Attempt to validate the provided auth token. :param redvox_config: The Api config. :param validate_token_req: A validation token req. :param session: An (optional) session for re-using an HTTP client. :param timeout: An (optional) timeout. :return: A ValidateTokenResp when the token is valid, None otherwise.

Expand source code
def validate_token(
    redvox_config: RedVoxConfig,
    validate_token_req: ValidateTokenReq,
    session: Optional[requests.Session] = None,
    timeout: Optional[float] = None,
) -> Optional[ValidateTokenResp]:
    """
    Attempt to validate the provided auth token.
    :param redvox_config: The Api config.
    :param validate_token_req: A validation token req.
    :param session: An (optional) session for re-using an HTTP client.
    :param timeout: An (optional) timeout.
    :return: A ValidateTokenResp when the token is valid, None otherwise.
    """
    # noinspection Mypy
    # pylint: disable=E1101
    handle_resp: Callable[
        [requests.Response], ValidateTokenResp
    ] = lambda resp: ValidateTokenResp.from_dict(resp.json())
    return post_req(
        redvox_config,
        RoutesV1.VALIDATE_TOKEN,
        validate_token_req,
        handle_resp,
        session,
        timeout,
    )

Classes

class AuthReq (email: str, password: str)

An authentication request.

Expand source code
@dataclass_json
@dataclass
class AuthReq:
    """
    An authentication request.
    """

    email: str
    password: str

Class variables

var email : str
var password : str

Static methods

def from_dict(kvs: Union[dict, list, str, int, float, bool, ForwardRef(None)], *, infer_missing=False) ‑> ~A
Expand source code
@classmethod
def from_dict(cls: Type[A],
              kvs: Json,
              *,
              infer_missing=False) -> A:
    return _decode_dataclass(cls, kvs, infer_missing)
def from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) ‑> ~A
Expand source code
@classmethod
def from_json(cls: Type[A],
              s: JsonData,
              *,
              parse_float=None,
              parse_int=None,
              parse_constant=None,
              infer_missing=False,
              **kw) -> A:
    kvs = json.loads(s,
                     parse_float=parse_float,
                     parse_int=parse_int,
                     parse_constant=parse_constant,
                     **kw)
    return cls.from_dict(kvs, infer_missing=infer_missing)
def schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) ‑> dataclasses_json.mm.SchemaF[~A]
Expand source code
@classmethod
def schema(cls: Type[A],
           *,
           infer_missing: bool = False,
           only=None,
           exclude=(),
           many: bool = False,
           context=None,
           load_only=(),
           dump_only=(),
           partial: bool = False,
           unknown=None) -> SchemaType:
    Schema = build_schema(cls, DataClassJsonMixin, infer_missing, partial)

    if unknown is None:
        undefined_parameter_action = _undefined_parameter_action_safe(cls)
        if undefined_parameter_action is not None:
            # We can just make use of the same-named mm keywords
            unknown = undefined_parameter_action.name.lower()

    return Schema(only=only,
                  exclude=exclude,
                  many=many,
                  context=context,
                  load_only=load_only,
                  dump_only=dump_only,
                  partial=partial,
                  unknown=unknown)

Methods

def to_dict(self, encode_json=False) ‑> Dict[str, Union[dict, list, str, int, float, bool, ForwardRef(None)]]
Expand source code
def to_dict(self, encode_json=False) -> Dict[str, Json]:
    return _asdict(self, encode_json=encode_json)
def to_json(self, *, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Union[int, str, ForwardRef(None)] = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) ‑> str
Expand source code
def to_json(self,
            *,
            skipkeys: bool = False,
            ensure_ascii: bool = True,
            check_circular: bool = True,
            allow_nan: bool = True,
            indent: Optional[Union[int, str]] = None,
            separators: Tuple[str, str] = None,
            default: Callable = None,
            sort_keys: bool = False,
            **kw) -> str:
    return json.dumps(self.to_dict(encode_json=False),
                      cls=_ExtendedEncoder,
                      skipkeys=skipkeys,
                      ensure_ascii=ensure_ascii,
                      check_circular=check_circular,
                      allow_nan=allow_nan,
                      indent=indent,
                      separators=separators,
                      default=default,
                      sort_keys=sort_keys,
                      **kw)
class AuthResp (status: int, auth_token: Optional[str], claims: Optional[ForwardRef('ValidateTokenResp')])

An authentication response.

Expand source code
@dataclass_json
@dataclass
class AuthResp:
    """
    An authentication response.
    """

    status: int
    auth_token: Optional[str]
    claims: Optional["ValidateTokenResp"]

    def is_success(self) -> bool:
        """
        :return: Returns true if the auth response was a success, false otherwise.
        """
        return (
            self.status == 200
            and self.auth_token is not None
            and len(self.auth_token) > 0
        )

Class variables

var auth_token : Optional[str]
var claims : Optional[ValidateTokenResp]
var status : int

Static methods

def from_dict(kvs: Union[dict, list, str, int, float, bool, ForwardRef(None)], *, infer_missing=False) ‑> ~A
Expand source code
@classmethod
def from_dict(cls: Type[A],
              kvs: Json,
              *,
              infer_missing=False) -> A:
    return _decode_dataclass(cls, kvs, infer_missing)
def from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) ‑> ~A
Expand source code
@classmethod
def from_json(cls: Type[A],
              s: JsonData,
              *,
              parse_float=None,
              parse_int=None,
              parse_constant=None,
              infer_missing=False,
              **kw) -> A:
    kvs = json.loads(s,
                     parse_float=parse_float,
                     parse_int=parse_int,
                     parse_constant=parse_constant,
                     **kw)
    return cls.from_dict(kvs, infer_missing=infer_missing)
def schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) ‑> dataclasses_json.mm.SchemaF[~A]
Expand source code
@classmethod
def schema(cls: Type[A],
           *,
           infer_missing: bool = False,
           only=None,
           exclude=(),
           many: bool = False,
           context=None,
           load_only=(),
           dump_only=(),
           partial: bool = False,
           unknown=None) -> SchemaType:
    Schema = build_schema(cls, DataClassJsonMixin, infer_missing, partial)

    if unknown is None:
        undefined_parameter_action = _undefined_parameter_action_safe(cls)
        if undefined_parameter_action is not None:
            # We can just make use of the same-named mm keywords
            unknown = undefined_parameter_action.name.lower()

    return Schema(only=only,
                  exclude=exclude,
                  many=many,
                  context=context,
                  load_only=load_only,
                  dump_only=dump_only,
                  partial=partial,
                  unknown=unknown)

Methods

def is_success(self) ‑> bool

:return: Returns true if the auth response was a success, false otherwise.

Expand source code
def is_success(self) -> bool:
    """
    :return: Returns true if the auth response was a success, false otherwise.
    """
    return (
        self.status == 200
        and self.auth_token is not None
        and len(self.auth_token) > 0
    )
def to_dict(self, encode_json=False) ‑> Dict[str, Union[dict, list, str, int, float, bool, ForwardRef(None)]]
Expand source code
def to_dict(self, encode_json=False) -> Dict[str, Json]:
    return _asdict(self, encode_json=encode_json)
def to_json(self, *, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Union[int, str, ForwardRef(None)] = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) ‑> str
Expand source code
def to_json(self,
            *,
            skipkeys: bool = False,
            ensure_ascii: bool = True,
            check_circular: bool = True,
            allow_nan: bool = True,
            indent: Optional[Union[int, str]] = None,
            separators: Tuple[str, str] = None,
            default: Callable = None,
            sort_keys: bool = False,
            **kw) -> str:
    return json.dumps(self.to_dict(encode_json=False),
                      cls=_ExtendedEncoder,
                      skipkeys=skipkeys,
                      ensure_ascii=ensure_ascii,
                      check_circular=check_circular,
                      allow_nan=allow_nan,
                      indent=indent,
                      separators=separators,
                      default=default,
                      sort_keys=sort_keys,
                      **kw)
class RefreshTokenReq (auth_token: str)

A token validation request.

Expand source code
@dataclass_json
@dataclass
class RefreshTokenReq:
    """
    A token validation request.
    """

    auth_token: str

Class variables

var auth_token : str

Static methods

def from_dict(kvs: Union[dict, list, str, int, float, bool, ForwardRef(None)], *, infer_missing=False) ‑> ~A
Expand source code
@classmethod
def from_dict(cls: Type[A],
              kvs: Json,
              *,
              infer_missing=False) -> A:
    return _decode_dataclass(cls, kvs, infer_missing)
def from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) ‑> ~A
Expand source code
@classmethod
def from_json(cls: Type[A],
              s: JsonData,
              *,
              parse_float=None,
              parse_int=None,
              parse_constant=None,
              infer_missing=False,
              **kw) -> A:
    kvs = json.loads(s,
                     parse_float=parse_float,
                     parse_int=parse_int,
                     parse_constant=parse_constant,
                     **kw)
    return cls.from_dict(kvs, infer_missing=infer_missing)
def schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) ‑> dataclasses_json.mm.SchemaF[~A]
Expand source code
@classmethod
def schema(cls: Type[A],
           *,
           infer_missing: bool = False,
           only=None,
           exclude=(),
           many: bool = False,
           context=None,
           load_only=(),
           dump_only=(),
           partial: bool = False,
           unknown=None) -> SchemaType:
    Schema = build_schema(cls, DataClassJsonMixin, infer_missing, partial)

    if unknown is None:
        undefined_parameter_action = _undefined_parameter_action_safe(cls)
        if undefined_parameter_action is not None:
            # We can just make use of the same-named mm keywords
            unknown = undefined_parameter_action.name.lower()

    return Schema(only=only,
                  exclude=exclude,
                  many=many,
                  context=context,
                  load_only=load_only,
                  dump_only=dump_only,
                  partial=partial,
                  unknown=unknown)

Methods

def to_dict(self, encode_json=False) ‑> Dict[str, Union[dict, list, str, int, float, bool, ForwardRef(None)]]
Expand source code
def to_dict(self, encode_json=False) -> Dict[str, Json]:
    return _asdict(self, encode_json=encode_json)
def to_json(self, *, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Union[int, str, ForwardRef(None)] = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) ‑> str
Expand source code
def to_json(self,
            *,
            skipkeys: bool = False,
            ensure_ascii: bool = True,
            check_circular: bool = True,
            allow_nan: bool = True,
            indent: Optional[Union[int, str]] = None,
            separators: Tuple[str, str] = None,
            default: Callable = None,
            sort_keys: bool = False,
            **kw) -> str:
    return json.dumps(self.to_dict(encode_json=False),
                      cls=_ExtendedEncoder,
                      skipkeys=skipkeys,
                      ensure_ascii=ensure_ascii,
                      check_circular=check_circular,
                      allow_nan=allow_nan,
                      indent=indent,
                      separators=separators,
                      default=default,
                      sort_keys=sort_keys,
                      **kw)
class RefreshTokenResp (auth_token: Optional[str], claims: Optional[ValidateTokenResp])

A token validation request.

Expand source code
@dataclass_json
@dataclass
class RefreshTokenResp:
    """
    A token validation request.
    """

    auth_token: Optional[str]
    claims: Optional[ValidateTokenResp]

Class variables

var auth_token : Optional[str]
var claims : Optional[ValidateTokenResp]

Static methods

def from_dict(kvs: Union[dict, list, str, int, float, bool, ForwardRef(None)], *, infer_missing=False) ‑> ~A
Expand source code
@classmethod
def from_dict(cls: Type[A],
              kvs: Json,
              *,
              infer_missing=False) -> A:
    return _decode_dataclass(cls, kvs, infer_missing)
def from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) ‑> ~A
Expand source code
@classmethod
def from_json(cls: Type[A],
              s: JsonData,
              *,
              parse_float=None,
              parse_int=None,
              parse_constant=None,
              infer_missing=False,
              **kw) -> A:
    kvs = json.loads(s,
                     parse_float=parse_float,
                     parse_int=parse_int,
                     parse_constant=parse_constant,
                     **kw)
    return cls.from_dict(kvs, infer_missing=infer_missing)
def schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) ‑> dataclasses_json.mm.SchemaF[~A]
Expand source code
@classmethod
def schema(cls: Type[A],
           *,
           infer_missing: bool = False,
           only=None,
           exclude=(),
           many: bool = False,
           context=None,
           load_only=(),
           dump_only=(),
           partial: bool = False,
           unknown=None) -> SchemaType:
    Schema = build_schema(cls, DataClassJsonMixin, infer_missing, partial)

    if unknown is None:
        undefined_parameter_action = _undefined_parameter_action_safe(cls)
        if undefined_parameter_action is not None:
            # We can just make use of the same-named mm keywords
            unknown = undefined_parameter_action.name.lower()

    return Schema(only=only,
                  exclude=exclude,
                  many=many,
                  context=context,
                  load_only=load_only,
                  dump_only=dump_only,
                  partial=partial,
                  unknown=unknown)

Methods

def to_dict(self, encode_json=False) ‑> Dict[str, Union[dict, list, str, int, float, bool, ForwardRef(None)]]
Expand source code
def to_dict(self, encode_json=False) -> Dict[str, Json]:
    return _asdict(self, encode_json=encode_json)
def to_json(self, *, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Union[int, str, ForwardRef(None)] = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) ‑> str
Expand source code
def to_json(self,
            *,
            skipkeys: bool = False,
            ensure_ascii: bool = True,
            check_circular: bool = True,
            allow_nan: bool = True,
            indent: Optional[Union[int, str]] = None,
            separators: Tuple[str, str] = None,
            default: Callable = None,
            sort_keys: bool = False,
            **kw) -> str:
    return json.dumps(self.to_dict(encode_json=False),
                      cls=_ExtendedEncoder,
                      skipkeys=skipkeys,
                      ensure_ascii=ensure_ascii,
                      check_circular=check_circular,
                      allow_nan=allow_nan,
                      indent=indent,
                      separators=separators,
                      default=default,
                      sort_keys=sort_keys,
                      **kw)
class ValidateTokenReq (auth_token: str)

A token validation request.

Expand source code
@dataclass_json
@dataclass
class ValidateTokenReq:
    """
    A token validation request.
    """

    auth_token: str

Class variables

var auth_token : str

Static methods

def from_dict(kvs: Union[dict, list, str, int, float, bool, ForwardRef(None)], *, infer_missing=False) ‑> ~A
Expand source code
@classmethod
def from_dict(cls: Type[A],
              kvs: Json,
              *,
              infer_missing=False) -> A:
    return _decode_dataclass(cls, kvs, infer_missing)
def from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) ‑> ~A
Expand source code
@classmethod
def from_json(cls: Type[A],
              s: JsonData,
              *,
              parse_float=None,
              parse_int=None,
              parse_constant=None,
              infer_missing=False,
              **kw) -> A:
    kvs = json.loads(s,
                     parse_float=parse_float,
                     parse_int=parse_int,
                     parse_constant=parse_constant,
                     **kw)
    return cls.from_dict(kvs, infer_missing=infer_missing)
def schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) ‑> dataclasses_json.mm.SchemaF[~A]
Expand source code
@classmethod
def schema(cls: Type[A],
           *,
           infer_missing: bool = False,
           only=None,
           exclude=(),
           many: bool = False,
           context=None,
           load_only=(),
           dump_only=(),
           partial: bool = False,
           unknown=None) -> SchemaType:
    Schema = build_schema(cls, DataClassJsonMixin, infer_missing, partial)

    if unknown is None:
        undefined_parameter_action = _undefined_parameter_action_safe(cls)
        if undefined_parameter_action is not None:
            # We can just make use of the same-named mm keywords
            unknown = undefined_parameter_action.name.lower()

    return Schema(only=only,
                  exclude=exclude,
                  many=many,
                  context=context,
                  load_only=load_only,
                  dump_only=dump_only,
                  partial=partial,
                  unknown=unknown)

Methods

def to_dict(self, encode_json=False) ‑> Dict[str, Union[dict, list, str, int, float, bool, ForwardRef(None)]]
Expand source code
def to_dict(self, encode_json=False) -> Dict[str, Json]:
    return _asdict(self, encode_json=encode_json)
def to_json(self, *, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Union[int, str, ForwardRef(None)] = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) ‑> str
Expand source code
def to_json(self,
            *,
            skipkeys: bool = False,
            ensure_ascii: bool = True,
            check_circular: bool = True,
            allow_nan: bool = True,
            indent: Optional[Union[int, str]] = None,
            separators: Tuple[str, str] = None,
            default: Callable = None,
            sort_keys: bool = False,
            **kw) -> str:
    return json.dumps(self.to_dict(encode_json=False),
                      cls=_ExtendedEncoder,
                      skipkeys=skipkeys,
                      ensure_ascii=ensure_ascii,
                      check_circular=check_circular,
                      allow_nan=allow_nan,
                      indent=indent,
                      separators=separators,
                      default=default,
                      sort_keys=sort_keys,
                      **kw)
class ValidateTokenResp (aud: str, exp: str, iat: str, iss: str, nbf: str, sub: str, tier: str)

A verified token response.

Expand source code
@dataclass_json
@dataclass
class ValidateTokenResp:
    """
    A verified token response.
    """

    aud: str
    exp: str
    iat: str
    iss: str
    nbf: str
    sub: str
    tier: str

Class variables

var aud : str
var exp : str
var iat : str
var iss : str
var nbf : str
var sub : str
var tier : str

Static methods

def from_dict(kvs: Union[dict, list, str, int, float, bool, ForwardRef(None)], *, infer_missing=False) ‑> ~A
Expand source code
@classmethod
def from_dict(cls: Type[A],
              kvs: Json,
              *,
              infer_missing=False) -> A:
    return _decode_dataclass(cls, kvs, infer_missing)
def from_json(s: Union[str, bytes, bytearray], *, parse_float=None, parse_int=None, parse_constant=None, infer_missing=False, **kw) ‑> ~A
Expand source code
@classmethod
def from_json(cls: Type[A],
              s: JsonData,
              *,
              parse_float=None,
              parse_int=None,
              parse_constant=None,
              infer_missing=False,
              **kw) -> A:
    kvs = json.loads(s,
                     parse_float=parse_float,
                     parse_int=parse_int,
                     parse_constant=parse_constant,
                     **kw)
    return cls.from_dict(kvs, infer_missing=infer_missing)
def schema(*, infer_missing: bool = False, only=None, exclude=(), many: bool = False, context=None, load_only=(), dump_only=(), partial: bool = False, unknown=None) ‑> dataclasses_json.mm.SchemaF[~A]
Expand source code
@classmethod
def schema(cls: Type[A],
           *,
           infer_missing: bool = False,
           only=None,
           exclude=(),
           many: bool = False,
           context=None,
           load_only=(),
           dump_only=(),
           partial: bool = False,
           unknown=None) -> SchemaType:
    Schema = build_schema(cls, DataClassJsonMixin, infer_missing, partial)

    if unknown is None:
        undefined_parameter_action = _undefined_parameter_action_safe(cls)
        if undefined_parameter_action is not None:
            # We can just make use of the same-named mm keywords
            unknown = undefined_parameter_action.name.lower()

    return Schema(only=only,
                  exclude=exclude,
                  many=many,
                  context=context,
                  load_only=load_only,
                  dump_only=dump_only,
                  partial=partial,
                  unknown=unknown)

Methods

def to_dict(self, encode_json=False) ‑> Dict[str, Union[dict, list, str, int, float, bool, ForwardRef(None)]]
Expand source code
def to_dict(self, encode_json=False) -> Dict[str, Json]:
    return _asdict(self, encode_json=encode_json)
def to_json(self, *, skipkeys: bool = False, ensure_ascii: bool = True, check_circular: bool = True, allow_nan: bool = True, indent: Union[int, str, ForwardRef(None)] = None, separators: Tuple[str, str] = None, default: Callable = None, sort_keys: bool = False, **kw) ‑> str
Expand source code
def to_json(self,
            *,
            skipkeys: bool = False,
            ensure_ascii: bool = True,
            check_circular: bool = True,
            allow_nan: bool = True,
            indent: Optional[Union[int, str]] = None,
            separators: Tuple[str, str] = None,
            default: Callable = None,
            sort_keys: bool = False,
            **kw) -> str:
    return json.dumps(self.to_dict(encode_json=False),
                      cls=_ExtendedEncoder,
                      skipkeys=skipkeys,
                      ensure_ascii=ensure_ascii,
                      check_circular=check_circular,
                      allow_nan=allow_nan,
                      indent=indent,
                      separators=separators,
                      default=default,
                      sort_keys=sort_keys,
                      **kw)