Skip to content

Commit d976107

Browse files
author
tailor
committed
[project @ Update django example consumer UI to let user select PAPE policy URIs to request]
1 parent d719a9d commit d976107

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎examples/djopenid/consumer/views.py‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212

1313
from djopenid import util
1414

15+
PAPE_POLICIES = [
16+
'AUTH_PHISHING_RESISTANT',
17+
'AUTH_MULTI_FACTOR',
18+
'AUTH_MULTI_FACTOR_PHYSICAL',
19+
]
20+
21+
# List of (name, uri) for use in generating the request form.
22+
POLICY_PAIRS = [(p, getattr(pape, p))
23+
for p in PAPE_POLICIES]
24+
1525
def getOpenIDStore():
1626
"""
1727
Return an OpenID store object fit for the currently-chosen
@@ -27,6 +37,8 @@ def getConsumer(request):
2737

2838
def renderIndexPage(request, **template_args):
2939
template_args['consumer_url'] = util.getViewURL(request, startOpenID)
40+
template_args['pape_policies'] = POLICY_PAIRS
41+
3042
response = direct_to_template(
3143
request, 'consumer/index.html', template_args)
3244
response[YADIS_HEADER_NAME] = util.getViewURL(request, rpXRDS)
@@ -75,8 +87,17 @@ def startOpenID(request):
7587
# Add PAPE request information. We'll ask for
7688
# phishing-resistant auth and display any policies we get in
7789
# the response.
78-
pape_request = pape.Request([pape.AUTH_PHISHING_RESISTANT])
79-
auth_request.addExtension(pape_request)
90+
requested_policies = []
91+
policy_prefix = 'policy_'
92+
for k, v in request.POST.iteritems():
93+
if k.startswith(policy_prefix):
94+
policy_attr = k[len(policy_prefix):]
95+
if policy_attr in PAPE_POLICIES:
96+
requested_policies.append(getattr(pape, policy_attr))
97+
98+
if requested_policies:
99+
pape_request = pape.Request(requested_policies)
100+
auth_request.addExtension(pape_request)
80101

81102
# Compute the trust root and return URL values to build the
82103
# redirect information.

‎examples/djopenid/templates/consumer/index.html‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@
9393

9494
<form method="post" action="{{ consumer_url }}">
9595
<input type="text" size="40" name="openid_identifier" />
96+
97+
<p>
98+
Request these authentication policies
99+
(<a href="http://openid.net/specs/openid-provider-authentication-policy-extension-1_0-01.html">PAPE</a>):
100+
101+
<table>
102+
{% for pair in pape_policies %}
103+
<tr>
104+
<td><input type="checkbox" name="policy_{{ pair.0 }}" id="id_policy_{{ pair.0 }}" /></td>
105+
<td>
106+
<label for="id_policy_{{ pair.0 }}"><tt>
107+
{{ pair.1 }}
108+
</tt></label>
109+
</td>
110+
</tr>
111+
{% endfor %}
112+
</table>
113+
</p>
114+
96115
<input type="submit" value="Begin" />
97116
</form>
98117

0 commit comments

Comments
 (0)