add publish verify

This commit is contained in:
Carneiro 2023-10-04 20:43:38 -03:00
parent 1939180939
commit 1c46089ae8
5 changed files with 40 additions and 10 deletions

View File

@ -6,10 +6,10 @@ long_description = file: README.md
long_description_content_type = text/markdown
author = Gabriel Carneiro
author_email = therealcarneiro@gmail.com
license = MIT
license_files = LICENSE
#license = MIT
#license_files = LICENSE
#url = https://github.com/theRealCarneiro/pulsemeeter
keywords = audio, mixing, mixer
#keywords = audio, mixing, mixer
classifiers =
Programming Language :: Python :: 3
Environment :: X11 Applications
@ -26,7 +26,7 @@ package_dir =
[options.entry_points]
console_scripts =
meexer = meexer.main:main
stream_auth = stream_auth.main:main
[options.packages.find]
where=src

View File

@ -6,6 +6,7 @@ import logging
from flask import Flask
from stream_auth import settings
from stream_auth.routes.user import user as user_routes
from stream_auth.routes.stream import user as stream_routes
app = Flask(__name__)
@ -14,6 +15,8 @@ logging.basicConfig(level=logging.INFO)
def main():
app.register_blueprint(user_routes)
app.register_blueprint(stream_routes)
app.run(host=settings.HOST, port=settings.PORT)

View File

@ -13,8 +13,8 @@ JWT_PRIV_KEY = read_key(settings.JWT_PRIV_PATH)
JWT_PUB_KEY = read_key(settings.JWT_PUB_PATH)
def create_token(username: str, stream_key: str):
exp = time.time() + settings.JWT_EXP_TIME
def create_token(username: str, stream_key: str, exp: int = settings.JWT_EXP_TIME):
exp = time.time() + exp
payload = {'username': username, 'stream_key': stream_key, 'exp': exp}
return jwt.encode(payload, JWT_PRIV_KEY, algorithm="RS256")

View File

@ -3,9 +3,11 @@ For controlling streams
'''
# 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 import jwt
from stream_auth.models.stream import Stream as StreamModel
from stream_auth.database import user
stream = Blueprint('user', __name__)
@ -17,5 +19,27 @@ def create_stream():
username = json['username']
title = json['name']
description = json['description']
# stream_key = json['stream_key']
StreamModel(title, description, username)
StreamModel(username, title, description)
@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)

View File

@ -39,7 +39,10 @@ def login():
username = json['username']
password = json['password']
try:
log_user = userdb.search_user(username)[0]
except IndexError:
return Response('User or password incorrect', 401)
if not log_user.check_password(password):
return Response('User or password incorrect', 401)