Module piate.api.authentication.v1
Expand source code
from dataclasses import dataclass
from typing import List, Dict, NewType
from dataclasses_json import dataclass_json, Undefined
from piate.api.authentication import (
AuthenticationBase,
RefreshToken,
ExpirationBase,
)
from piate.api.version import APIVersion
AuthToken = NewType("AuthToken", str)
@dataclass_json(undefined=Undefined.RAISE)
@dataclass
class TokenResponse:
"""Response from the Authentication API"""
token_type: str
tokens: List[AuthToken]
refresh_token: RefreshToken
permission_name_by_id: Dict[str, str]
role_group_name_by_id: Dict[str, str]
expiration: ExpirationBase
class Authentication(AuthenticationBase):
API_VERSION = APIVersion.V1
def token(self, base_url: str, username: str, password: str) -> TokenResponse:
return TokenResponse.from_dict(
super().token(base_url=base_url, username=username, password=password)
)
def extends(self, base_url: str, refresh_token: str) -> TokenResponse:
return TokenResponse.from_dict(
super().extends(base_url=base_url, refresh_token=refresh_token)
)
Classes
class Authentication-
Expand source code
class Authentication(AuthenticationBase): API_VERSION = APIVersion.V1 def token(self, base_url: str, username: str, password: str) -> TokenResponse: return TokenResponse.from_dict( super().token(base_url=base_url, username=username, password=password) ) def extends(self, base_url: str, refresh_token: str) -> TokenResponse: return TokenResponse.from_dict( super().extends(base_url=base_url, refresh_token=refresh_token) )Ancestors
Class variables
var API_VERSION : APIVersion
Methods
def extends(self, base_url: str, refresh_token: str) ‑> TokenResponse-
Expand source code
def extends(self, base_url: str, refresh_token: str) -> TokenResponse: return TokenResponse.from_dict( super().extends(base_url=base_url, refresh_token=refresh_token) ) def token(self, base_url: str, username: str, password: str) ‑> TokenResponse-
Expand source code
def token(self, base_url: str, username: str, password: str) -> TokenResponse: return TokenResponse.from_dict( super().token(base_url=base_url, username=username, password=password) )
class TokenResponse (token_type: str, tokens: List[AuthToken], refresh_token: RefreshToken, permission_name_by_id: Dict[str, str], role_group_name_by_id: Dict[str, str], expiration: ExpirationBase)-
Response from the Authentication API
Expand source code
@dataclass_json(undefined=Undefined.RAISE) @dataclass class TokenResponse: """Response from the Authentication API""" token_type: str tokens: List[AuthToken] refresh_token: RefreshToken permission_name_by_id: Dict[str, str] role_group_name_by_id: Dict[str, str] expiration: ExpirationBaseClass variables
var dataclass_json_configvar expiration : ExpirationBasevar permission_name_by_id : Dict[str, str]var refresh_token : RefreshTokenvar role_group_name_by_id : Dict[str, str]var token_type : strvar tokens : List[AuthToken]
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)