File: auth_mgr.py

package info (click to toggle)
python-yolink-api 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 184 kB
  • sloc: python: 1,147; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 729 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""YoLink authorization manager."""

import abc
from aiohttp import ClientSession


class YoLinkAuthMgr(metaclass=abc.ABCMeta):
    """YoLink API Authentication Manager."""

    def __init__(self, session: ClientSession) -> None:
        """YoLink Auth Manager"""
        self._session = session

    def client_session(self) -> ClientSession:
        """Get client session."""
        return self._session

    @abc.abstractmethod
    def access_token(self) -> str:
        """Get auth token."""

    def http_auth_header(self) -> str:
        """Get auth header."""
        return f"Bearer {self.access_token()}"

    @abc.abstractmethod
    async def check_and_refresh_token(self) -> str:
        """Check and fresh token."""