mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 09:31:08 +00:00
Adds webfinger
This commit is contained in:
parent
a312791259
commit
e357f4a7a6
3 changed files with 27 additions and 2 deletions
|
@ -1,4 +1,28 @@
|
||||||
''' activitystream api '''
|
''' activitystream api '''
|
||||||
|
from django.http import HttpResponseBadRequest, HttpResponseNotFound, JsonResponse
|
||||||
|
from fedireads.settings import DOMAIN
|
||||||
|
from fedireads.models import User
|
||||||
|
|
||||||
def webfinger(request):
|
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),
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ DEBUG = True
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = []
|
||||||
|
|
||||||
|
DOMAIN = 'localhost'
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
|
|
|
@ -23,5 +23,5 @@ urlpatterns = [
|
||||||
path('login/', views.user_login),
|
path('login/', views.user_login),
|
||||||
path('logout/', views.user_logout),
|
path('logout/', views.user_logout),
|
||||||
path('api/book/<str:olkey>', openlibrary.get_book),
|
path('api/book/<str:olkey>', openlibrary.get_book),
|
||||||
path('webfinger/', activitystream.webfinger),
|
path('.well-known/webfinger', activitystream.webfinger),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue