Remove legacy login
parent
45e4f94741
commit
228535e042
|
@ -33,8 +33,6 @@ class Extension(mopidy.ext.Extension):
|
||||||
schema["client_secret"] = mopidy.config.String(optional=True)
|
schema["client_secret"] = mopidy.config.String(optional=True)
|
||||||
schema["client_id"] = mopidy.config.String(optional=True)
|
schema["client_id"] = mopidy.config.String(optional=True)
|
||||||
|
|
||||||
schema["username"] = mopidy.config.String(optional=True)
|
|
||||||
schema["password"] = mopidy.config.Secret(optional=True)
|
|
||||||
schema["cache_duration"] = mopidy.config.Integer(optional=True)
|
schema["cache_duration"] = mopidy.config.Integer(optional=True)
|
||||||
schema["verify_cert"] = mopidy.config.Boolean(optional=True)
|
schema["verify_cert"] = mopidy.config.Boolean(optional=True)
|
||||||
|
|
||||||
|
@ -42,16 +40,6 @@ class Extension(mopidy.ext.Extension):
|
||||||
|
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
def validate_config(self, config):
|
|
||||||
if not config.getboolean("funkwhale", "enabled"):
|
|
||||||
return
|
|
||||||
username = config.getstring("funkwhale", "username")
|
|
||||||
password = config.getstring("funkwhale", "password")
|
|
||||||
if any([username, password]) and not all([username, password]):
|
|
||||||
raise mopidy.ext.ExtensionError(
|
|
||||||
"You need to provide username and password to authenticate with the funkwhale backend"
|
|
||||||
)
|
|
||||||
|
|
||||||
def setup(self, registry):
|
def setup(self, registry):
|
||||||
from . import actor
|
from . import actor
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,6 @@ class FunkwhaleBackend(pykka.ThreadingActor, backend.Backend):
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
if self.config["funkwhale"]["client_id"]:
|
if self.config["funkwhale"]["client_id"]:
|
||||||
logger.info('Using OAuth2 connection"')
|
logger.info('Using OAuth2 connection"')
|
||||||
elif self.client.username is not None:
|
|
||||||
self.client.login()
|
|
||||||
logger.info(
|
|
||||||
'Logged in to Funkwhale as "%s" on "%s"',
|
|
||||||
self.client.username,
|
|
||||||
self.config["funkwhale"]["url"],
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
logger.info('Using "%s" anonymously', self.config["funkwhale"]["url"])
|
logger.info('Using "%s" anonymously', self.config["funkwhale"]["url"])
|
||||||
|
|
||||||
|
|
|
@ -52,25 +52,11 @@ def get_requests_session(url, proxy_config, user_agent, base_cls, **kwargs):
|
||||||
return session
|
return session
|
||||||
|
|
||||||
|
|
||||||
def login_legacy(session, username, password):
|
|
||||||
if not username:
|
|
||||||
return
|
|
||||||
response = session.post("token/", {"username": username, "password": password})
|
|
||||||
try:
|
|
||||||
response.raise_for_status()
|
|
||||||
except requests.exceptions.HTTPError:
|
|
||||||
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):
|
class APIClient(object):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.jwt_token = None
|
|
||||||
self.oauth_token = get_token(config)
|
self.oauth_token = get_token(config)
|
||||||
if self.use_oauth:
|
|
||||||
self.session = get_requests_session(
|
self.session = get_requests_session(
|
||||||
config["funkwhale"]["url"],
|
config["funkwhale"]["url"],
|
||||||
proxy_config=config["proxy"],
|
proxy_config=config["proxy"],
|
||||||
|
@ -87,14 +73,6 @@ class APIClient(object):
|
||||||
},
|
},
|
||||||
token_updater=self.refresh_token,
|
token_updater=self.refresh_token,
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
self.session = get_requests_session(
|
|
||||||
config["funkwhale"]["url"],
|
|
||||||
proxy_config=config["proxy"],
|
|
||||||
user_agent="%s/%s" % (Extension.dist_name, __version__),
|
|
||||||
base_cls=SessionWithUrlBase,
|
|
||||||
)
|
|
||||||
self.username = self.config["funkwhale"]["username"]
|
|
||||||
self.session.verify = config["funkwhale"].get("verify_cert", True)
|
self.session.verify = config["funkwhale"].get("verify_cert", True)
|
||||||
|
|
||||||
self.exclude_compilation_artists = self.config["funkwhale"].get("exclude_compilation_artists", True)
|
self.exclude_compilation_artists = self.config["funkwhale"].get("exclude_compilation_artists", True)
|
||||||
|
@ -107,17 +85,6 @@ class APIClient(object):
|
||||||
self.oauth_token = token
|
self.oauth_token = token
|
||||||
set_token(token, self.config)
|
set_token(token, self.config)
|
||||||
|
|
||||||
def login(self):
|
|
||||||
self.username = self.config["funkwhale"]["username"]
|
|
||||||
if self.username:
|
|
||||||
self.jwt_token = login_legacy(
|
|
||||||
self.session,
|
|
||||||
self.config["funkwhale"]["username"],
|
|
||||||
self.config["funkwhale"]["password"],
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.jwt_token = None
|
|
||||||
|
|
||||||
def search(self, query):
|
def search(self, query):
|
||||||
response = self.session.get("search", params={"query": query})
|
response = self.session.get("search", params={"query": query})
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
|
@ -186,6 +153,9 @@ def get_token(config):
|
||||||
|
|
||||||
|
|
||||||
def set_token(token_data, config):
|
def set_token(token_data, config):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import mopidy_funkwhale
|
import mopidy_funkwhale
|
||||||
|
|
||||||
data_dir = mopidy_funkwhale.Extension.get_data_dir(config)
|
data_dir = mopidy_funkwhale.Extension.get_data_dir(config)
|
||||||
|
|
|
@ -14,13 +14,6 @@ client_secret =
|
||||||
authorization_endpoint = /authorize
|
authorization_endpoint = /authorize
|
||||||
token_endpoint = /api/v1/oauth/token/
|
token_endpoint = /api/v1/oauth/token/
|
||||||
|
|
||||||
## Settings below are for legacy password-based auth, you should use OAuth instead
|
|
||||||
|
|
||||||
# Username to use when authenticating (leave empty fo anonymous access)
|
|
||||||
username =
|
|
||||||
# Password to use when authenticating (leave empty fo anonymous access)
|
|
||||||
password =
|
|
||||||
|
|
||||||
# duration of cache entries before they are removed, in seconds
|
# duration of cache entries before they are removed, in seconds
|
||||||
# 0 to cache forever, empty to disable cache
|
# 0 to cache forever, empty to disable cache
|
||||||
cache_duration = 600
|
cache_duration = 600
|
||||||
|
|
Loading…
Reference in New Issue