change stream key to jwt
This commit is contained in:
parent
de7f452a91
commit
7b56e8a892
|
@ -13,6 +13,11 @@ JWT_PRIV_KEY = read_key(settings.JWT_PRIV_PATH)
|
|||
JWT_PUB_KEY = read_key(settings.JWT_PUB_PATH)
|
||||
|
||||
|
||||
def create_stream_key(username: str):
|
||||
payload = {'username': username}
|
||||
return jwt.encode(payload, JWT_PRIV_KEY, algorithm="RS256")
|
||||
|
||||
|
||||
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}
|
||||
|
|
|
@ -5,6 +5,7 @@ import random
|
|||
import string
|
||||
import logging
|
||||
import bcrypt
|
||||
from stream_auth.middlewares import jwt
|
||||
|
||||
STREAM_KEY_LENGTH = 64
|
||||
|
||||
|
@ -26,7 +27,8 @@ class User:
|
|||
salt = bcrypt.gensalt()
|
||||
self.username = username
|
||||
self.password = str(bcrypt.hashpw(password.encode('utf-8'), salt), 'utf-8')
|
||||
self.stream_key = generate_stream_key(STREAM_KEY_LENGTH)
|
||||
# self.stream_key = generate_stream_key(STREAM_KEY_LENGTH)
|
||||
self.stream_key = jwt.create_stream_key(username)
|
||||
self.live = False
|
||||
|
||||
def check_passwrod(self, password: str):
|
||||
|
@ -51,4 +53,4 @@ class User:
|
|||
'''
|
||||
Recreate stream_key
|
||||
'''
|
||||
self.stream_key = generate_stream_key(STREAM_KEY_LENGTH)
|
||||
self.stream_key = jwt.create_stream_key(self.username)
|
||||
|
|
|
@ -26,7 +26,8 @@ def create():
|
|||
logging.info('User %s created with stream key %s',
|
||||
new_user.username, new_user.stream_key)
|
||||
|
||||
return Response('OK', 200)
|
||||
res = {'username': new_user.username, 'stream_key': new_user.stream_key}
|
||||
return Response(jsonify(res), 200)
|
||||
|
||||
|
||||
@user.route('/login', methods=['POST'])
|
||||
|
|
Loading…
Reference in New Issue