diff options
author | Munyoki Kilyungi | 2024-04-30 10:54:48 +0300 |
---|---|---|
committer | BonfaceKilz | 2024-04-30 13:09:46 +0300 |
commit | 9856a8f2f9addce60c231ffa1f28366a5e6dba9a (patch) | |
tree | fae2162a279de792e5e5c0a31e64d83dcd49293a /gn2/wqflask/oauth2 | |
parent | 5e54afe8fc7fbe0da42a0d8b477c60599f9b967b (diff) | |
download | genenetwork2-9856a8f2f9addce60c231ffa1f28366a5e6dba9a.tar.gz |
Revert "Create constructors for encoding and decoding a token."
This reverts commit e7a3bf22da1b63a01343f2cd30cd13c234fe508c.
Diffstat (limited to 'gn2/wqflask/oauth2')
-rw-r--r-- | gn2/wqflask/oauth2/tokens.py | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/gn2/wqflask/oauth2/tokens.py b/gn2/wqflask/oauth2/tokens.py deleted file mode 100644 index e0ee814b..00000000 --- a/gn2/wqflask/oauth2/tokens.py +++ /dev/null @@ -1,59 +0,0 @@ -"""This file contains functions/classes related to dealing with JWTs""" -from dataclasses import dataclass -from dataclasses import field -from authlib.jose import jwt - - -@dataclass -class JWTToken: - """Class for constructing a JWT according to RFC7519 - -https://datatracker.ietf.org/doc/html/rfc7519 - - """ - key: str - private_claims: dict = field(default_factory=lambda: {}) - public_claims: dict = field(default_factory=lambda: {}) - jose_header: dict = field( - default_factory=lambda: { - "alg": "HS256", - "typ": "jwt", - "cty": "json", - }) - registered_claims: dict = field( - default_factory={ - "iss": "", # Issuer Claim - "iat": "", # Issued At - "sub": "", # Subject Claim - "aud": "", # Audience Claim - "exp": "", # Expiration Time Claim - "jti": "", # Unique Identifier for this token - }) - - def __post__init__(self): - match self.jose_header.get("alg"): - case "HS256": - self.key = self.key - case _: - with open(self.key, "rb")as f_: - self.key = f_.read() - - def encode(self): - """Encode the JWT""" - payload = self.registered_claims \ - | self.private_claims \ - | self.public_claims \ - | self.registered_claims - return jwt.encode(self.jose_header, payload, self.key) - - @property - def bearer_token(self) -> dict: - """Return a header that contains this tokens Bearer Token""" - return { - "Authorization": f"Bearer {self.encode()}" - } - - @staticmethod - def decode(token, key) -> str: - """Decode the JWT""" - return jwt.decode(token, key) |