1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import time
17 import urllib
18
19 from django.conf import settings
20 from django.http import str_to_unicode, get_host
21 from django.utils.html import escape
22
23 from openid.consumer.discover import discover
24 from openid.extensions import sreg, ax
25 try:
26 from openid.yadis import xri
27 except ImportError:
28 from yadis import xri
29
30
32 - def __init__(self, openid_, issued, attrs=None, sreg_=None, ax_=None):
33 self.openid = openid_
34 self.issued = issued
35 self.attrs = attrs or {}
36 self.sreg = sreg_ or {}
37 self.ax = ax_ or {}
38 self.is_iname = (xri.identifierScheme(openid_) == 'XRI')
39
41 return '<OpenID: %s>' % self.openid
42
45
47 service = discover(openid_url)
48 use_ax = False
49 use_sreg = False
50 for endpoint in service[1]:
51 if not use_sreg:
52 use_sreg = sreg.supportsSReg(endpoint)
53 if not use_ax:
54 use_ax = endpoint.usesExtension("http://openid.net/srv/ax/1.0")
55 if use_ax and use_sreg:
56 break
57 if not use_sreg and not use_ax:
58 use_sreg = True
59 return use_ax, use_sreg
60
61
62 DEFAULT_NEXT = getattr(settings, 'OPENID_REDIRECT_NEXT', '/')
64 if next is None:
65 return DEFAULT_NEXT
66 next = str_to_unicode(urllib.unquote(next), 'utf-8')
67 next = next.strip()
68 if next.startswith('/'):
69 return next
70 return DEFAULT_NEXT
71
72
74 """ return openid object from response """
75 issued = int(time.time())
76 sreg_resp = sreg.SRegResponse.fromSuccessResponse(openid_response) \
77 or []
78 ax_resp = ax.FetchResponse.fromSuccessResponse(openid_response)
79 ax_args = {}
80 if ax_resp is not None:
81 ax_args = ax_resp.getExtensionArgs()
82 ax_resp.parseExtensionArgs(ax_args)
83 ax_args = ax_resp.data
84
85 return OpenID(
86 openid_response.identity_url, issued, openid_response.signed_fields,
87 dict(sreg_resp), ax_args
88 )
89
91 if request.is_secure():
92 protocol = 'https'
93 else:
94 protocol = 'http'
95 host = escape(get_host(request))
96 return '%s://%s' % (protocol, host)
97
100