Commit a77ea62c authored by Fence's avatar Fence 🌈

rename model to TrustedRsaKey & remove CryptoChecker

parent ec7567dc
import jwt
from minor.model import TrustedRsaKey
def get_asymetric_jwt_payload(self, token):
payload = jwt.decode(token, "", verify=False)
try:
issuer = TrustedRsaKey.objects.get(issuer=payload["iss"])
except TrustedRsaKey.DoesNotExist:
return None
if issuer is not None:
try:
key = issuer.key
checked_payload = jwt.decode(token, key)
return checked_payload
except Exception:
return None
return None
import jwt
from minor.model import MajorInstance
class CryptoChecker(object):
def __init__(self, db):
self._db = db
def check(self, token):
payload = jwt.decode(token, "", verify=False)
try:
issuer = MajorInstance.objects.get(issuer=payload["iss"])
except MajorInstance.DoesNotExist:
return None
if issuer is not None:
try:
key = issuer.key
checked_payload = jwt.decode(token, key)
return checked_payload
except Exception:
return None
return None
from functools import wraps
from flask import json_available, jsonify, request
from .crypto_checker import CryptoChecker
import crypto
def auth_required(f):
......@@ -11,7 +11,7 @@ def auth_required(f):
auth = auth.split(" ")
if auth[0] == "Bearer":
# print(auth[1])
payload = CryptoChecker("minor").check(auth[1])
payload = crypto.get_asymetric_jwt_payload(auth[1])
if payload is not None:
kwargs["payload"] = payload
return f(self, *args, **kwargs)
......
......@@ -21,6 +21,6 @@ class Cover(Document):
songs = ListField(ReferenceField(Song, reverse_delete_rule=CASCADE))
class MajorInstance(Document):
class TrustedRsaKey(Document):
issuer = StringField(required=True)
key = StringField(required=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment