Added authentication token in playback url
parent
3f0ad7742f
commit
0d93ebea73
|
@ -42,4 +42,6 @@ class FunkwhalePlaybackProvider(backend.PlaybackProvider):
|
|||
url = track['listen_url']
|
||||
if url.startswith('/'):
|
||||
url = self.backend.config['funkwhale']['url'] + url
|
||||
if self.backend.remote.token:
|
||||
url += '?jwt=' + self.backend.remote.token
|
||||
return url
|
||||
|
|
|
@ -2,7 +2,7 @@ from __future__ import unicode_literals
|
|||
|
||||
import requests
|
||||
|
||||
from mopidy import httpclient
|
||||
from mopidy import httpclient, exceptions
|
||||
|
||||
from . import Extension, __version__
|
||||
|
||||
|
@ -42,10 +42,10 @@ def login(session, username, password):
|
|||
try:
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.HTTPError:
|
||||
raise BackendError('Authentication failed for user %s' % (username,))
|
||||
raise exceptions.BackendError('Authentication failed for user %s' % (username,))
|
||||
token = response.json()['token']
|
||||
session.headers.update({'Authorization': 'JWT %s' % (token,)})
|
||||
|
||||
return token
|
||||
|
||||
class APIClient(object):
|
||||
def __init__(self, session):
|
||||
|
@ -82,8 +82,9 @@ class FunkwhaleClient(object):
|
|||
)
|
||||
)
|
||||
self.username = config['funkwhale']['username']
|
||||
self.token = None
|
||||
if config['funkwhale']['username']:
|
||||
login(
|
||||
self.token = login(
|
||||
self.http_client.session,
|
||||
config['funkwhale']['username'],
|
||||
config['funkwhale']['password'])
|
||||
|
|
|
@ -94,6 +94,7 @@ def test_convert_album_to_model():
|
|||
assert result.album == mopidy_funkwhale.library.convert_to_album(payload['album'])
|
||||
assert result.artists == frozenset([mopidy_funkwhale.library.convert_to_artist(payload['artist'])])
|
||||
|
||||
|
||||
@pytest.mark.parametrize('uri, expected', [
|
||||
('funkwhale:albums:42', ('album', 42)),
|
||||
('funkwhale:tracks:42', ('track', 42)),
|
||||
|
|
Loading…
Reference in New Issue