Added authentication token in playback url

main
Eliot Berriot 2018-10-03 22:09:02 +02:00
parent 3f0ad7742f
commit 0d93ebea73
No known key found for this signature in database
GPG Key ID: DD6965E2476E5C27
3 changed files with 8 additions and 4 deletions

View File

@ -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

View File

@ -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'])

View File

@ -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)),