Module piate.api.authentication.v2
Expand source code
from dataclasses import dataclass
from datetime import datetime
from typing import NewType, List
from dataclasses_json import dataclass_json, Undefined
from piate.api.authentication import (
AuthenticationBase,
RefreshToken,
ExpirationBase,
)
from piate.api.version import APIVersion
IDToken = NewType("IDToken", str)
AccessToken = NewType("AccessToken", str)
@dataclass_json(undefined=Undefined.RAISE)
@dataclass
class Expiration(ExpirationBase):
id: datetime
def id_expired(self) -> bool:
return self.id >= datetime.now()
@dataclass_json(undefined=Undefined.RAISE)
@dataclass
class TokenResponseToken:
id_token: IDToken
access_token: AccessToken
@dataclass_json(undefined=Undefined.RAISE)
@dataclass
class TokenResponse:
token_type: str
refresh_token: RefreshToken
tokens: List[TokenResponseToken]
expiration: Expiration
class Authentication(AuthenticationBase):
API_VERSION = APIVersion.V2
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: RefreshToken) -> 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.V2 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: RefreshToken) -> 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: RefreshToken) ‑> TokenResponse-
Expand source code
def extends(self, base_url: str, refresh_token: RefreshToken) -> 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 Expiration (access: datetime.datetime, refresh: datetime.datetime, id: datetime.datetime)-
Expiration(access: datetime.datetime, refresh: datetime.datetime, id: datetime.datetime)
Expand source code
@dataclass_json(undefined=Undefined.RAISE) @dataclass class Expiration(ExpirationBase): id: datetime def id_expired(self) -> bool: return self.id >= datetime.now()Ancestors
Class variables
var dataclass_json_configvar id : datetime.datetime
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 id_expired(self) ‑> bool-
Expand source code
def id_expired(self) -> bool: return self.id >= datetime.now() 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 TokenResponse (token_type: str, refresh_token: RefreshToken, tokens: List[TokenResponseToken], expiration: Expiration)-
TokenResponse(token_type: str, refresh_token:
.new_type at 0x10a9454c0>, tokens: List[piate.api.authentication.v2.TokenResponseToken], expiration: piate.api.authentication.v2.Expiration) Expand source code
@dataclass_json(undefined=Undefined.RAISE) @dataclass class TokenResponse: token_type: str refresh_token: RefreshToken tokens: List[TokenResponseToken] expiration: ExpirationClass variables
var dataclass_json_configvar expiration : Expirationvar refresh_token : RefreshTokenvar token_type : strvar tokens : List[TokenResponseToken]
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 TokenResponseToken (id_token: IDToken, access_token: AccessToken)-
TokenResponseToken(id_token:
.new_type at 0x10ac10430>, access_token: .new_type at 0x10adae280>) Expand source code
@dataclass_json(undefined=Undefined.RAISE) @dataclass class TokenResponseToken: id_token: IDToken access_token: AccessTokenClass variables
var access_token : AccessTokenvar dataclass_json_configvar id_token : IDToken
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)