Verified Commit 0d93ebea authored by Agate's avatar Agate 💬
Browse files

Added authentication token in playback url

parent 3f0ad774
Pipeline #2182 failed with stages
in 38 seconds
......@@ -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)),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment