simplify OAuth as_dict and is_oauth
This commit is contained in:
parent
fb48dcc103
commit
102a732f9b
1 changed files with 6 additions and 16 deletions
|
|
@ -23,20 +23,17 @@ class Token:
|
||||||
expires_at: int
|
expires_at: int
|
||||||
expires_in: int = 0
|
expires_in: int = 0
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def members():
|
||||||
|
return Token.__annotations__.keys()
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
"""Readable version."""
|
"""Readable version."""
|
||||||
return f"{self.__class__.__name__}: {self.as_dict()}"
|
return f"{self.__class__.__name__}: {self.as_dict()}"
|
||||||
|
|
||||||
def as_dict(self) -> RefreshableTokenDict:
|
def as_dict(self) -> RefreshableTokenDict:
|
||||||
"""Returns dictionary containing underlying token values."""
|
"""Returns dictionary containing underlying token values."""
|
||||||
return {
|
return {key: self.__dict__[key] for key in Token.members()} # type: ignore
|
||||||
"access_token": self.access_token,
|
|
||||||
"refresh_token": self.refresh_token,
|
|
||||||
"scope": self.scope,
|
|
||||||
"expires_at": self.expires_at,
|
|
||||||
"expires_in": self.expires_in,
|
|
||||||
"token_type": self.token_type,
|
|
||||||
}
|
|
||||||
|
|
||||||
def as_json(self) -> str:
|
def as_json(self) -> str:
|
||||||
return json.dumps(self.as_dict())
|
return json.dumps(self.as_dict())
|
||||||
|
|
@ -55,14 +52,7 @@ class OAuthToken(Token):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_oauth(headers: CaseInsensitiveDict) -> bool:
|
def is_oauth(headers: CaseInsensitiveDict) -> bool:
|
||||||
oauth_structure = {
|
return all(key in headers for key in Token.members())
|
||||||
"access_token",
|
|
||||||
"expires_at",
|
|
||||||
"expires_in",
|
|
||||||
"token_type",
|
|
||||||
"refresh_token",
|
|
||||||
}
|
|
||||||
return all(key in headers for key in oauth_structure)
|
|
||||||
|
|
||||||
def update(self, fresh_access: BaseTokenDict):
|
def update(self, fresh_access: BaseTokenDict):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue