Ejemplo n.º 1
0
	def gen_host_meta( cls, fmt='xml', href=None,
			template='{{ url_base }}{% url remotestorage:webfinger:webfinger fmt=q_fmt %}?uri={uri}',
			**attrs ):
		link = Link(dict( rel='lrdd',
			type='application/xrd+{}'.format(fmt), **attrs ), list(), list())
		if href: link.attributes['href'] = href
		else: link.attributes['template'] = template
		return cls.serialize(fmt, links=[link])
Ejemplo n.º 2
0
 def gen_host_meta(
         cls,
         fmt='xml',
         href=None,
         template='{{ url_base }}{% url remotestorage:webfinger:webfinger fmt=q_fmt %}?uri={uri}',
         **attrs):
     link = Link(
         dict(rel='lrdd', type='application/xrd+{}'.format(fmt), **attrs),
         list(), list())
     if href: link.attributes['href'] = href
     else: link.attributes['template'] = template
     return cls.serialize(fmt, links=[link])
Ejemplo n.º 3
0
	def gen_webfinger( cls, fmt='xml', href=None,
			auth_method='http://tools.ietf.org/html/draft-ietf-oauth-v2-26#section-4.2',
			auth=_abs_url_prefix + '{% url remotestorage:oauth2:authorize %}?user={{ q_acct }}',
			template=_abs_url_prefix + "{% url remotestorage:api:storage acct=q_acct path='' %}/{category}/",
			type='https://www.w3.org/community/rww/wiki/read-write-web-00#simple' ):
		link = Link(
			dict(auth=auth, api='simple', rel='remoteStorage', type=type),
			list(), [
				Property(auth, dict(type='auth_endpoint')),
				Property(auth_method, dict(type='auth_method')) ] )
		if href: link.attributes['href'] = href
		else: link.attributes['template'] = template
		return cls.serialize(fmt, links=[link])
Ejemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     link = Link(
         rel='lrdd',
         type_='application/xrd+xml',
         template='%s/webfinger?q={uri}' % kwargs["webfinger_host"]
     )
     self.xrd.links.append(link)
Ejemplo n.º 5
0
def handler(request, acct, xrd):
        # acct.userinfo is the username
        # acct.host is the host
    xrd.aliases.append('http://example.com/profile/%s/' % acct.userinfo)
    xrd.expires = datetime.datetime.utcnow() + datetime.timedelta(0, 10)
    xrd.links.append(Link(
        rel=AUTHOR,
        href='http://jeremy.carbauja.com',
        type_='text/html',
    ))
Ejemplo n.º 6
0
 def gen_webfinger(
         cls,
         fmt='xml',
         href=None,
         auth_method='http://tools.ietf.org/html/draft-ietf-oauth-v2-26#section-4.2',
         auth=_abs_url_prefix +
     '{% url remotestorage:oauth2:authorize %}?user={{ q_acct }}',
         template=_abs_url_prefix +
     "{% url remotestorage:api:storage acct=q_acct path='' %}/{category}/",
         type='https://www.w3.org/community/rww/wiki/read-write-web-00#simple'
 ):
     link = Link(
         dict(auth=auth, api='simple', rel='remoteStorage', type=type),
         list(), [
             Property(auth, dict(type='auth_endpoint')),
             Property(auth_method, dict(type='auth_method'))
         ])
     if href: link.attributes['href'] = href
     else: link.attributes['template'] = template
     return cls.serialize(fmt, links=[link])
Ejemplo n.º 7
0
 def __init__(self, handle, host, guid, public_key, *args, **kwargs):
     super().__init__(handle, *args, **kwargs)
     self.xrd.elements.append(
         Element("Alias", "%s/people/%s" % (host, guid)))
     username = handle.split("@")[0]
     self.xrd.links.append(
         Link(rel="http://microformats.org/profile/hcard",
              type_="text/html",
              href="%s/hcard/users/%s" % (host, guid)))
     self.xrd.links.append(
         Link(rel="http://joindiaspora.com/seed_location",
              type_="text/html",
              href=host))
     self.xrd.links.append(
         Link(rel="http://joindiaspora.com/guid",
              type_="text/html",
              href=guid))
     self.xrd.links.append(
         Link(rel="http://webfinger.net/rel/profile-page",
              type_="text/html",
              href="%s/u/%s" % (host, username)))
     self.xrd.links.append(
         Link(rel="http://schemas.google.com/g/2010#updates-from",
              type_="application/atom+xml",
              href="%s/public/%s.atom" % (host, username)))
     # Base64 the key
     # See https://wiki.diasporafoundation.org/Federation_Protocol_Overview#Diaspora_Public_Key
     try:
         base64_key = b64encode(bytes(public_key,
                                      encoding="UTF-8")).decode("ascii")
     except TypeError:
         # Python 2
         base64_key = b64encode(public_key).decode("ascii")
     self.xrd.links.append(
         Link(rel="diaspora-public-key", type_="RSA", href=base64_key))
Ejemplo n.º 8
0
def get_host_meta():
    """
    This function services the well-known host-meta XRD data for RESTCONF
    API root discovery.
    """
    if args.verbose > 0:
        print 'get_host_meta: entry'

    xrd_obj = XRD()

    # Add a few extra elements and links before RESTCONF to help make sure
    # the parsing/XPATH is correct

    xrd_obj.elements.append(Element('hm:Host', 'testDevice'))
    xrd_obj.links.append(
        Link(rel='license', href='http://www.apache.org/licenses/LICENSE-2.0'))
    xrd_obj.links.append(Link(rel='author', href='http://bcsw.net'))

    # Add the link for RESTCONF

    xrd_obj.links.append(Link(rel='restconf', href=args.root_resource))

    # Add some extra links here as well

    xrd_obj.links.append(Link(rel='testPath', href='this/does/not/exist'))
    xrd_obj.links.append(
        Link(rel='http://oexchange.org/spec/0.8/rel/resident-target',
             type_='application/xrd+xml',
             href='http://twitter.com/oexchange.xrd'))

    # Convert to XML, pretty-print it to aid in debugging

    xrd_doc = xrd_obj.to_xml()

    return Response(xrd_doc.toprettyxml(indent=' '),
                    mimetype='application/xrd+xml')
Ejemplo n.º 9
0
from django.conf import settings
from django.core.urlresolvers import reverse

from webfinger.rel import LRDD
from xrd import Link

import urllib
import wellknown

SECURE = getattr(settings, 'WEBFINGER_SECURE', False)
DOMAIN = getattr(settings, 'WEBFINGER_DOMAIN', 'example.com')

scheme = "https" if SECURE else "http"

endpoint = urllib.unquote(reverse('webfinger_endpoint', args=(r'{uri}', )))
uri_template = "%s://%s%s" % (scheme, DOMAIN, endpoint)

webfinger_link = Link(rel=LRDD, template=uri_template)
webfinger_link.titles.append('Resource Descriptor')

wellknown.get_hostmeta().links.append(webfinger_link)