Adds webfinger

This commit is contained in:
Mouse Reeve 2020-01-25 16:24:22 -08:00
parent a312791259
commit e357f4a7a6
3 changed files with 27 additions and 2 deletions

View file

@ -1,4 +1,28 @@
''' activitystream api '''
from django.http import HttpResponseBadRequest, HttpResponseNotFound, JsonResponse
from fedireads.settings import DOMAIN
from fedireads.models import User
def webfinger(request):
return 'hi'
''' allow other servers to ask about a user '''
resource = request.GET.get('resource')
if not resource and not resource.startswith('acct:'):
return HttpResponseBadRequest()
account = resource.replace('acct:', '')
account = account.replace('@' + DOMAIN, '')
user = User.objects.filter(username=account).first()
if not user:
return HttpResponseNotFound('No account found')
return JsonResponse(format_webfinger(user))
def format_webfinger(user):
return {
'subject': 'acct:%s@%s' % (user.username, DOMAIN),
'links': [
{
'rel': 'self',
'type': 'application/activity+json',
'href': 'https://%s/user/%s' % (DOMAIN, user.username),
}
]
}

View file

@ -27,6 +27,7 @@ DEBUG = True
ALLOWED_HOSTS = []
DOMAIN = 'localhost'
# Application definition

View file

@ -23,5 +23,5 @@ urlpatterns = [
path('login/', views.user_login),
path('logout/', views.user_logout),
path('api/book/<str:olkey>', openlibrary.get_book),
path('webfinger/', activitystream.webfinger),
path('.well-known/webfinger', activitystream.webfinger),
]