feat: Add signature based login
This commit is contained in:
20
main.py
20
main.py
@@ -512,10 +512,12 @@ def auth_get():
|
|||||||
|
|
||||||
if 'username' not in request.args:
|
if 'username' not in request.args:
|
||||||
return redirect('/?error=Failed to login&reason=No username')
|
return redirect('/?error=Failed to login&reason=No username')
|
||||||
if 'token' not in request.args:
|
username = request.args['username']
|
||||||
|
|
||||||
|
if 'token' not in request.args and 'signature' not in request.args:
|
||||||
return redirect('/?error=Failed to login&reason=No token')
|
return redirect('/?error=Failed to login&reason=No token')
|
||||||
|
|
||||||
username = request.args['username']
|
if 'token' in request.args:
|
||||||
token = request.args['token']
|
token = request.args['token']
|
||||||
|
|
||||||
# Check if user is valid
|
# Check if user is valid
|
||||||
@@ -535,6 +537,20 @@ def auth_get():
|
|||||||
if r['username'] != username:
|
if r['username'] != username:
|
||||||
return redirect('/?error=Failed to login&reason=Username mismatch')
|
return redirect('/?error=Failed to login&reason=Username mismatch')
|
||||||
|
|
||||||
|
else: # Signature based login
|
||||||
|
signature = request.args['signature']
|
||||||
|
r = requests.post(f'http://x:{HSD_API}@{HSD_IP}:{HSD_PORT}', json={
|
||||||
|
'method': 'verifymessagewithname',
|
||||||
|
'params': [username, signature, "hns-links"]
|
||||||
|
})
|
||||||
|
if r.status_code != 200:
|
||||||
|
return jsonify({'error': 'Failed to connect to HSD',"success":False}), 500
|
||||||
|
r = r.json()
|
||||||
|
if 'result' not in r:
|
||||||
|
return jsonify({'error': 'Failed to verify signature',"success":False}), 400
|
||||||
|
if r['result'] != True:
|
||||||
|
return jsonify({'error': 'Failed to verify signature',"success":False}), 400
|
||||||
|
|
||||||
auth_cookie = secrets.token_hex(12 // 2)
|
auth_cookie = secrets.token_hex(12 // 2)
|
||||||
cookies.append({'name': username, 'cookie': auth_cookie})
|
cookies.append({'name': username, 'cookie': auth_cookie})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user