Update to Poetry (resolves #27 and #29)

This commit is contained in:
2024-08-16 09:33:47 +01:00
parent 9f2b553121
commit 029c88c44f
7 changed files with 347 additions and 15 deletions

67
simple_webfinger/app.py Normal file
View File

@@ -0,0 +1,67 @@
from urllib.parse import urlparse
from flask import Flask, request, abort
import yaml
app = Flask(__name__)
with open('config.yaml', 'rb') as fobj:
data = yaml.load(fobj, yaml.SafeLoader)
def get_account_links(user):
links = []
account_data = data['accounts'][user]
# Append custom links
if 'links' in account_data:
links.extend(account_data['links'])
if 'mastodon' in account_data:
account, domain = account_data['mastodon'].split('@')
links.extend([
{'rel': 'http://webfinger.net/rel/profile-page', 'type': 'text/html', 'href': 'https://{0}/@{1}'.format(domain, account)},
{'rel': 'self', 'type': 'application/activity+json', 'href': 'https://{0}/users/{1}'.format(domain, account)},
{'rel': 'http://ostatus.org/schema/1.0/subscribe', 'template': "https://{0}/authorize_interaction?uri={{uri}}".format(domain)}
])
# Append the OIDC link
if 'oidc_href' in data:
links.append({
'rel': 'http://openid.net/specs/connect/1.0/issuer',
'href': data['oidc_href'],
})
return links
def filter_links(links, rel):
new_links = []
for link in links:
if link['rel'] == rel:
new_links.append(link)
return new_links
@app.route("/.well-known/webfinger")
def webfinger():
resource = request.args.get('resource')
account, domain = urlparse(resource).path.split('@')
if domain != data['domain'] or account not in data['accounts']:
abort(404)
links = get_account_links(account)
rel = request.args.get('rel')
if rel:
links = filter_links(links, rel)
return {
'subject': resource,
'links': links
}
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)