kopia lustrzana https://github.com/snarfed/bridgy-fed
Use the acct: URI for this domain, if in h-card
This allows users to choose their own username for their webfinger ID. Closes #3pull/27/head
rodzic
6815807298
commit
38ff56e3cc
|
|
@ -188,3 +188,32 @@ class WebFingerTest(testutil.TestCase):
|
|||
self.assertEquals('application/json; charset=utf-8',
|
||||
got.headers['Content-Type'])
|
||||
self.assertEquals(self.expected_webfinger, json.loads(got.body))
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_webfinger_handler_custom_username(self, mock_get):
|
||||
self.html = """
|
||||
<body class="h-card">
|
||||
<a class="u-url" rel="me" href="/about-me">
|
||||
<img class="u-photo" src="/me.jpg" />
|
||||
Mrs. ☕ Foo
|
||||
</a>
|
||||
<a class="u-url" href="acct:notthisuser@boop.org"></a>
|
||||
<a class="u-url" href="acct:customuser@foo.com"></a>
|
||||
</body>
|
||||
"""
|
||||
self.expected_webfinger['subject'] = "acct:customuser@foo.com"
|
||||
self.expected_webfinger['aliases'] = [u'https://foo.com/about-me',
|
||||
u'acct:notthisuser@boop.org',
|
||||
u'acct:customuser@foo.com',
|
||||
u'https://foo.com/']
|
||||
mock_get.return_value = requests_response(self.html, url='https://foo.com/')
|
||||
|
||||
for resource in ('customuser@foo.com', 'acct:customuser@foo.com',
|
||||
'foo.com', 'http://foo.com/', 'https://foo.com/'):
|
||||
url = '/.well-known/webfinger?%s' % urllib.urlencode(
|
||||
{'resource': resource})
|
||||
got = app.get_response(url, headers={'Accept': 'application/json'})
|
||||
self.assertEquals(200, got.status_int, got.body)
|
||||
self.assertEquals('application/json; charset=utf-8',
|
||||
got.headers['Content-Type'])
|
||||
self.assertEquals(self.expected_webfinger, json.loads(got.body))
|
||||
|
|
|
|||
14
webfinger.py
14
webfinger.py
|
|
@ -58,13 +58,21 @@ class UserHandler(handlers.XrdOrJrdHandler):
|
|||
Couldn't find a <a href="http://microformats.org/wiki/representative-hcard-parsing">\
|
||||
representative h-card</a> on %s""" % resp.url)
|
||||
|
||||
acct = '%s@%s' % (domain, domain)
|
||||
logging.info('Generating WebFinger data for %s', acct)
|
||||
logging.info('Generating WebFinger data for %s', domain)
|
||||
key = models.MagicKey.get_or_create(domain)
|
||||
props = hcard.get('properties', {})
|
||||
urls = util.dedupe_urls(props.get('url', []) + [resp.url])
|
||||
canonical_url = urls[0]
|
||||
|
||||
acct = '%s@%s' % (domain, domain)
|
||||
for url in urls:
|
||||
if url.startswith('acct:'):
|
||||
urluser, urldomain = util.parse_acct_uri(url)
|
||||
if urldomain == domain:
|
||||
acct = '%s@%s' % (urluser, domain)
|
||||
logging.info('Found custom username: acct:%s', acct)
|
||||
break
|
||||
|
||||
# discover atom feed, if any
|
||||
atom = parsed.find('link', rel='alternate', type=common.CONTENT_TYPE_ATOM)
|
||||
if atom and atom['href']:
|
||||
|
|
@ -95,7 +103,7 @@ representative h-card</a> on %s""" % resp.url)
|
|||
'rel': 'http://webfinger.net/rel/profile-page',
|
||||
'type': 'text/html',
|
||||
'href': url,
|
||||
}] for url in urls), []) + [{
|
||||
}] for url in urls if url.startswith("http")), []) + [{
|
||||
'rel': 'http://webfinger.net/rel/avatar',
|
||||
'href': url,
|
||||
} for url in props.get('photo', [])] + [{
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue