Commit a836433d authored by Fence's avatar Fence 🌈

what were they thinking - AVGN, circa 2006 AD

parent 5dc776ec
This diff is collapsed.
import sys
from mongoengine import connect
from minor.model import MajorInstance
key = None
with open(sys.argv[2], "r") as file:
key = file.read()
if key == None:
print("oh no!")
exit()
connect("minor")
MajorInstance(issuer=sys.argv[1], key=key).save()
print("everything worked~")
import sys
import jwt
from datetime import datetime, timedelta
expires = 15
payload = {"song": "5b9ae72fc0368e3b9c8a6027" }
key = None
with open(sys.argv[2], "r") as file:
key = file.read()
payload["iss"] = sys.argv[1]
payload["iat"] = datetime.utcnow()
payload["exp"] = datetime.utcnow() + timedelta(expires)
print(jwt.encode(payload, key, algorithm='RS256'))
{
"info": {
"_postman_id": "47133917-aa5d-440f-ba7b-279ab5787a57",
"name": "minor",
"_postman_id": "b1cdfd5a-5601-4082-897a-1971d38f1315",
"name": "minor copy",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
......@@ -30,7 +30,10 @@
"request": {
"method": "GET",
"header": [],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{url}}/api",
"host": [
......@@ -112,7 +115,10 @@
"request": {
"method": "GET",
"header": [],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{url}}/api/music/song/{{song_id}}/hasfile",
"host": [
......@@ -153,8 +159,8 @@
"formdata": [
{
"key": "file",
"description": "",
"type": "file"
"type": "file",
"value": ""
}
]
},
......@@ -194,7 +200,10 @@
"request": {
"method": "GET",
"header": [],
"body": {},
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{url}}/api/music/song/{{song_id}}/hasfile",
"host": [
......@@ -210,8 +219,30 @@
}
},
"response": []
},
{
"name": "listen",
"request": {
"method": "GET",
"header": [],
"body": {},
"url": {
"raw": ""
}
},
"response": []
}
],
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJtaW5pd2EiLCJpYXQiOjE1MzY4NzgyNjIsImV4cCI6MTUzODE3NDI2Mn0.nw52vrtybuoiDa6fPUoMIaqAEUiqwVZcK6CR0U9dP9Q4P1-F6jADld3tLyQxIlX1P5J1oTh18pXywXcn3uikBNSjQNSzKhBW_0-HM2saBALuiP_gG_8hmCkfgPjItLTdJHe-bvCmerqc3lakMuPqKpZAxJmmi0PkbmsWNDmGEpnMkV5mWLXvaOF05yi1ayOdn2IzVDsgvy4TeV_2U2viaZ9D21MDBBEFqNiPMbLTpBBs68CgSn2eQa2w-wxuwDGyAh-UGUTPcjCv2DHmL0twxPEP3sOPMU0Lr9CYK0BSPL3igs1-GZ6dR5QAZTolgOgUw8CUbXNdIb89sP5lxgSdzA",
"type": "string"
}
]
},
"event": [
{
"listen": "prerequest",
......@@ -236,11 +267,18 @@
],
"variable": [
{
"id": "c547da47-7193-43fd-ab64-435731330129",
"id": "4d510edb-b692-4c37-b344-1999f25eaaaa",
"key": "url",
"value": "http://127.0.0.1:5000/",
"type": "string",
"description": ""
},
{
"id": "1fc5d0c9-7320-4f4f-a2f4-2a0f4f7492a7",
"key": "song_id",
"value": "5b9ae72fc0368e3b9c8a6027",
"type": "string",
"description": ""
}
]
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ from minor.controller import ApiController, MusicController
class App(object):
def __init__(self):
self._flask = Flask(__name__)
self._flask.config['MONGODB_SETTINGS'] = {'DB': 'testing'}
self._flask.config['MONGODB_SETTINGS'] = {'db': 'minor'}
from minor.model import db
db.init_app(self._flask)
......
......@@ -13,13 +13,14 @@ from minor.util import get_ext
@route("/api/music")
class MusicController(FlaskController):
# @auth_required
@auth_required
@route("/listen")
def listen(self, payload=None):
if "song" in payload:
song = Song.objects.get(id=payload["song"])
if song is not None:
filename = "./uploads/" + str(song["_id"]) + ".mp3"
print(dir(song))
filename = "./uploads/" + str(song.id) + ".mp3"
print(filename)
if os.path.isfile(filename):
def generate():
......@@ -32,7 +33,7 @@ class MusicController(FlaskController):
else:
return jsonify({"code": 400, "message": "bad_request"}), 400
# auth_required
#@auth_required
@route("/song/<id>")
def song(self, id, payload=None):
song = Song.objects.get(id=id)
......@@ -41,7 +42,7 @@ class MusicController(FlaskController):
else:
return jsonify({"code": 400, "message": "bad_request"}), 400
# @auth_required
@auth_required
@route("/song/<id>/hasfile")
def song_has_file(self, id, payload=None):
song = Song.objects.get(id=id)
......@@ -54,7 +55,7 @@ class MusicController(FlaskController):
else:
return jsonify({"code": 400, "message": "bad_request"}), 400
# @auth_required
@auth_required
@json_required
@route("/song", methods=["POST"])
def song_post(self, payload=None):
......
import os
import os.path
import json
import jwt
from datetime import datetime, timedelta
import requests
from minor.model import MajorInstance
class CryptoChecker(object):
......@@ -16,9 +11,9 @@ class CryptoChecker(object):
issuer = MajorInstance.objects.get(issuer=payload["iss"])
if issuer is not None:
try:
key = requests.get(issuer["url"] + "/auth/key").text
key = issuer.key
checked_payload = jwt.decode(token, key)
return checked_payload
except Exception as e:
print(e)
return None
\ No newline at end of file
return None
......@@ -11,7 +11,7 @@ def auth_required(f):
auth = auth.split(" ")
if auth[0] == "Bearer":
print(auth[1])
payload = CryptoChecker(self._db).check(auth[1])
payload = CryptoChecker("minor").check(auth[1])
if payload is not None:
kwargs["payload"] = payload
return f(self, *args, **kwargs)
......@@ -25,4 +25,4 @@ def json_required(f):
if not json_available:
return jsonify({"code": 400, "message": "bad_request"}), 400
return f(*args, **kwargs)
return decorated_function
\ No newline at end of file
return decorated_function
......@@ -15,4 +15,4 @@ class Song(Document):
class MajorInstance(Document):
issuer = StringField(required=True)
url = URLField(required=True)
\ No newline at end of file
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