configurable MASTODON_CLIENT_SCOPE

This commit is contained in:
Your Name 2021-09-18 10:48:11 -04:00
parent eaa17e030e
commit b4e3dda09e
6 changed files with 14 additions and 10 deletions

5
.gitignore vendored
View file

@ -24,4 +24,7 @@ migrations/
# debug log file # debug log file
/log /log
log log
# conf folder for neodb
/neodb

View file

@ -219,6 +219,10 @@ MASTODON_ALLOW_ANY_SITE = False
# Timeout of requests to Mastodon, in seconds # Timeout of requests to Mastodon, in seconds
MASTODON_TIMEOUT = 30 MASTODON_TIMEOUT = 30
MASTODON_CLIENT_SCOPE = 'read write follow'
#use the following if it's a new site
#MASTODON_CLIENT_SCOPE = 'read:accounts read:follows read:search read:blocks read:mutes write:statuses write:media'
# Tags for toots posted from this site # Tags for toots posted from this site
MASTODON_TAGS = '#NiceDB #NiceDB%(category)s #NiceDB%(category)s%(type)s' MASTODON_TAGS = '#NiceDB #NiceDB%(category)s #NiceDB%(category)s%(type)s'

View file

@ -96,7 +96,7 @@ def create_app(domain_name):
payload = { payload = {
'client_name': settings.CLIENT_NAME, 'client_name': settings.CLIENT_NAME,
'scopes': 'read write follow', 'scopes': settings.MASTODON_CLIENT_SCOPE,
'redirect_uris': settings.REDIRECT_URIS, 'redirect_uris': settings.REDIRECT_URIS,
'website': settings.APP_WEBSITE 'website': settings.APP_WEBSITE
} }

View file

@ -233,6 +233,7 @@ class DoufenParser:
return self.items return self.items
except Exception as e: except Exception as e:
print('ERROR ' + self.__file_path)
logger.error(e) logger.error(e)
raise e raise e

View file

@ -68,15 +68,9 @@
let domain = selected.val(); let domain = selected.val();
Cookies.set('mastodon_domain', domain); Cookies.set('mastodon_domain', domain);
{% if debug %}
location.href = "https://" + domain + "/oauth/authorize?client_id=" + client_id + location.href = "https://" + domain + "/oauth/authorize?client_id=" + client_id +
"&scope=read+write&redirect_uri=http://{{ request.get_host }}{% url 'users:OAuth2_login' %}" + "&scope={{ scope }}&redirect_uri={{ request.scheme }}://{{ request.get_host }}{% url 'users:OAuth2_login' %}" +
"&response_type=code"; "&response_type=code";
{% else %}
location.href = "https://" + domain + "/oauth/authorize?client_id=" + client_id +
"&scope=read+write&redirect_uri=https://{{ request.get_host }}{% url 'users:OAuth2_login' %}" +
"&response_type=code";
{% endif %}
}); });
</script> </script>
{% endif %} {% endif %}

View file

@ -26,6 +26,7 @@ from music.forms import MusicMarkStatusTranslator
from games.forms import GameMarkStatusTranslator from games.forms import GameMarkStatusTranslator
from mastodon.models import MastodonApplication from mastodon.models import MastodonApplication
from django.conf import settings from django.conf import settings
from urllib.parse import quote
# Views # Views
######################################## ########################################
@ -88,6 +89,7 @@ def login(request):
'users/login.html', 'users/login.html',
{ {
'sites': sites, 'sites': sites,
'scope': quote(settings.MASTODON_CLIENT_SCOPE),
'selected_site': selected_site, 'selected_site': selected_site,
'allow_any_site': settings.MASTODON_ALLOW_ANY_SITE, 'allow_any_site': settings.MASTODON_ALLOW_ANY_SITE,
} }
@ -122,7 +124,7 @@ def connect(request):
} }
) )
else: else:
login_url = "https://" + domain + "/oauth/authorize?client_id=" + app.client_id + "&scope=read+write&redirect_uri=" + request.scheme + "://" + request.get_host() + reverse('users:OAuth2_login') + "&response_type=code" login_url = "https://" + domain + "/oauth/authorize?client_id=" + app.client_id + "&scope=" + quote(settings.MASTODON_CLIENT_SCOPE) + "&redirect_uri=" + request.scheme + "://" + request.get_host() + reverse('users:OAuth2_login') + "&response_type=code"
resp = redirect(login_url) resp = redirect(login_url)
resp.set_cookie("mastodon_domain", domain) resp.set_cookie("mastodon_domain", domain)
return resp return resp