Allow authentication on custom MusicBrainz servers using Basic HTTP Authentication.

This commit is contained in:
Tim
2015-02-19 00:54:10 +02:00
parent 03ea67b20b
commit 24a52a294c
5 changed files with 57 additions and 6 deletions
+10 -2
View File
@@ -271,6 +271,7 @@ user = password = ""
hostname = "musicbrainz.org"
_client = ""
_useragent = ""
mb_auth = False
def auth(u, p):
"""Set the username and password to be used in subsequent queries to
@@ -284,9 +285,16 @@ def hpauth(u, p):
"""Set the username and password to be used in subsequent queries to
the MusicBrainz XML API that require authentication.
"""
global hpuser, hppassword
global hpuser, hppassword, mb_auth
hpuser = u
hppassword = p
mb_auth = True
def disable_hpauth():
"""Disable the authentication for MusicBrainz XML API
"""
global mb_auth
mb_auth = False
def set_useragent(app, version, contact=None):
"""Set the User-Agent to be used for requests to the MusicBrainz webservice.
@@ -635,7 +643,7 @@ def _mb_request(path, method='GET', auth_required=False, client_required=False,
req.add_header('User-Agent', _useragent)
# Add headphones credentials
if hostname == '144.76.94.239:8181':
if mb_auth:
base64string = base64.encodestring('%s:%s' % (hpuser, hppassword)).replace('\n', '')
req.add_header("Authorization", "Basic %s" % base64string)