add publish verify
This commit is contained in:
parent
1939180939
commit
1c46089ae8
|
@ -6,10 +6,10 @@ long_description = file: README.md
|
||||||
long_description_content_type = text/markdown
|
long_description_content_type = text/markdown
|
||||||
author = Gabriel Carneiro
|
author = Gabriel Carneiro
|
||||||
author_email = therealcarneiro@gmail.com
|
author_email = therealcarneiro@gmail.com
|
||||||
license = MIT
|
#license = MIT
|
||||||
license_files = LICENSE
|
#license_files = LICENSE
|
||||||
#url = https://github.com/theRealCarneiro/pulsemeeter
|
#url = https://github.com/theRealCarneiro/pulsemeeter
|
||||||
keywords = audio, mixing, mixer
|
#keywords = audio, mixing, mixer
|
||||||
classifiers =
|
classifiers =
|
||||||
Programming Language :: Python :: 3
|
Programming Language :: Python :: 3
|
||||||
Environment :: X11 Applications
|
Environment :: X11 Applications
|
||||||
|
@ -26,7 +26,7 @@ package_dir =
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
meexer = meexer.main:main
|
stream_auth = stream_auth.main:main
|
||||||
|
|
||||||
[options.packages.find]
|
[options.packages.find]
|
||||||
where=src
|
where=src
|
||||||
|
|
|
@ -6,6 +6,7 @@ import logging
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from stream_auth import settings
|
from stream_auth import settings
|
||||||
from stream_auth.routes.user import user as user_routes
|
from stream_auth.routes.user import user as user_routes
|
||||||
|
from stream_auth.routes.stream import user as stream_routes
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
@ -14,6 +15,8 @@ logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app.register_blueprint(user_routes)
|
app.register_blueprint(user_routes)
|
||||||
|
app.register_blueprint(stream_routes)
|
||||||
|
|
||||||
app.run(host=settings.HOST, port=settings.PORT)
|
app.run(host=settings.HOST, port=settings.PORT)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,8 @@ JWT_PRIV_KEY = read_key(settings.JWT_PRIV_PATH)
|
||||||
JWT_PUB_KEY = read_key(settings.JWT_PUB_PATH)
|
JWT_PUB_KEY = read_key(settings.JWT_PUB_PATH)
|
||||||
|
|
||||||
|
|
||||||
def create_token(username: str, stream_key: str):
|
def create_token(username: str, stream_key: str, exp: int = settings.JWT_EXP_TIME):
|
||||||
exp = time.time() + settings.JWT_EXP_TIME
|
exp = time.time() + exp
|
||||||
payload = {'username': username, 'stream_key': stream_key, 'exp': exp}
|
payload = {'username': username, 'stream_key': stream_key, 'exp': exp}
|
||||||
return jwt.encode(payload, JWT_PRIV_KEY, algorithm="RS256")
|
return jwt.encode(payload, JWT_PRIV_KEY, algorithm="RS256")
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,11 @@ For controlling streams
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# import logging
|
# import logging
|
||||||
from flask import Blueprint, Response, request
|
from flask import Blueprint, Response, request, redirect
|
||||||
from stream_auth.middlewares.auth import auth
|
from stream_auth.middlewares.auth import auth
|
||||||
|
from stream_auth.middlewares import jwt
|
||||||
from stream_auth.models.stream import Stream as StreamModel
|
from stream_auth.models.stream import Stream as StreamModel
|
||||||
|
from stream_auth.database import user
|
||||||
|
|
||||||
stream = Blueprint('user', __name__)
|
stream = Blueprint('user', __name__)
|
||||||
|
|
||||||
|
@ -17,5 +19,27 @@ def create_stream():
|
||||||
username = json['username']
|
username = json['username']
|
||||||
title = json['name']
|
title = json['name']
|
||||||
description = json['description']
|
description = json['description']
|
||||||
# stream_key = json['stream_key']
|
StreamModel(username, title, description)
|
||||||
StreamModel(title, description, username)
|
|
||||||
|
|
||||||
|
@stream.route('/publish_check')
|
||||||
|
def publish_check():
|
||||||
|
|
||||||
|
# TODO: check if user created stream
|
||||||
|
|
||||||
|
# check if already redirected
|
||||||
|
token = request.form.get('token')
|
||||||
|
if jwt.verify(token):
|
||||||
|
return Response('OK', 200)
|
||||||
|
|
||||||
|
# get user
|
||||||
|
try:
|
||||||
|
stream_key = request.form.get('name')
|
||||||
|
stream_user = user.search_stream_key(stream_key)[0]['username']
|
||||||
|
username = stream_user['username']
|
||||||
|
|
||||||
|
except IndexError:
|
||||||
|
return Response('Invalid Stream Key', 401)
|
||||||
|
|
||||||
|
token = jwt.create_token(username, stream_key, 10)
|
||||||
|
return redirect(f'rtmp://127.0.0.1:33000/live/{username}?{token}', code=302)
|
||||||
|
|
|
@ -39,7 +39,10 @@ def login():
|
||||||
username = json['username']
|
username = json['username']
|
||||||
password = json['password']
|
password = json['password']
|
||||||
|
|
||||||
|
try:
|
||||||
log_user = userdb.search_user(username)[0]
|
log_user = userdb.search_user(username)[0]
|
||||||
|
except IndexError:
|
||||||
|
return Response('User or password incorrect', 401)
|
||||||
|
|
||||||
if not log_user.check_password(password):
|
if not log_user.check_password(password):
|
||||||
return Response('User or password incorrect', 401)
|
return Response('User or password incorrect', 401)
|
||||||
|
|
Loading…
Reference in New Issue