Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added various settings to customize the login dialog. (fixes #1)

  • Loading branch information...
commit 656d399a9ad8086011d4d3c6aaa2856afa23cc42 1 parent 573365c
@madjar authored
View
1  CHANGES.rst
@@ -6,6 +6,7 @@ DEV
- Use a pre-built verifier object for lower per-request overhead (thanks @rfk).
- Renamed the setting persona.audience to persona.audiences to match the PyBrowserID API.
- Added the "persona.verifier" setting to change the verifier.
+- Added various settings to customize the login dialog.
1.0
---
View
30 README.rst
@@ -88,6 +88,34 @@ persona.audiences
persona.verifier
The doted python name of the BrowserID assertion verifier. Optional. Default is 'browserid.RemoteVerifier'. Another possible value could be 'browserid.LocalVerifier' (not recommended for now).
+.. _`persona documentation`: https://developer.mozilla.org/en-US/docs/Persona/Remote_Verification_API
+
+Login dialog customization
+++++++++++++++++++++++++++
+
+Persona provides a few ways to customize the login dialog. To be precise, they
+are arguments to the `navigator.id.request` API call. For the full description of these parameters,
+see `the documentation of navigator.id.request`_.
+
+.. _the documentation of navigator.id.request: https://developer.mozilla.org/en-US/docs/DOM/navigator.id.request
+
+persona.siteName
+ Plain text name of your site to show in the login dialog. Optional.
+
+persona.siteLogo
+ Absolute path to an image to show in the login dialog. Optional.
+
+persona.privacyPolicy
+ Absolute path or URL to the web site's privacy policy. Optional.
+
+persona.termsOfService
+ Absolute path or URL to the web site's terms of service. Optional.
+
+Routes
+++++++
+
+If the default route names or paths conflicts with your application, you can change them :
+
persona.login_route
The login route name. Optional, default is 'login'.
@@ -100,8 +128,6 @@ persona.logout_route
persona.logout_path
The logout route path. Optional, default is '/logout'.
-.. _`persona documentation`: https://developer.mozilla.org/en-US/docs/Persona/Remote_Verification_API
-
Python 3 compatibility
----------------------
View
3  demo/demo.py
@@ -29,6 +29,9 @@ def template(request):
'persona.secret': 'some secret',
'persona.audiences': 'http://localhost:8080',
'mako.directories': '.',
+ 'persona.siteName': 'Super demo app',
+ 'persona.privacyPolicy': '/nonExistentPrivacy.html',
+ 'persona.termsOfService': '/nonExistentTos.html',
}
config = Configurator(settings=settings)
config.include('pyramid_persona')
View
9 pyramid_persona/__init__.py
@@ -1,3 +1,4 @@
+import json
import warnings
from pyramid.authentication import SessionAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
@@ -60,6 +61,14 @@ def check():
audiences = aslist(settings['persona.audiences'])
config.registry['persona.verifier'] = verifier_factory(audiences)
+ # Parameters for the request API call
+ request_params = {}
+ for option in ('privacyPolicy', 'siteLogo', 'siteName', 'termsOfService'):
+ setting_name = 'persona.%s'%option
+ if setting_name in settings:
+ request_params[option] = settings[setting_name]
+ config.registry['persona.request_params'] = json.dumps(request_params)
+
# Login and logout views.
login_route = settings.get('persona.login_route', 'login')
login_path = settings.get('persona.login_path', '/login')
View
4 pyramid_persona/templates/persona.js
@@ -1,5 +1,5 @@
$(function() {
- $('#signin').click(function() { navigator.id.request(); return false;});
+ $('#signin').click(function() { navigator.id.request(%(request_params)s); return false;});
$('#signout').click(function() { navigator.id.logout(); return false;});
@@ -26,4 +26,4 @@ $(function() {
});
}
});
-});
+});
View
3  pyramid_persona/utils.py
@@ -23,7 +23,8 @@ def js(request):
'user': user,
'login': '/login',
'logout': '/logout',
- 'csrf_token': request.session.get_csrf_token()
+ 'csrf_token': request.session.get_csrf_token(),
+ 'request_params': markupsafe.Markup(request.registry['persona.request_params']),
}
template = markupsafe.Markup(pkg_resources.resource_string('pyramid_persona', 'templates/persona.js').decode())
return template % data
Please sign in to comment.
Something went wrong with that request. Please try again.