templates: add template autologin.html to provider autologin capability in any page
It use the new JSONP logged-in web service from authentic. You must declare you website in the VALID_REFERERS settings of your authentic server.
This commit is contained in:
parent
ef4cb6dbff
commit
94f3d5ca6a
|
@ -141,13 +141,17 @@ AUTHENTICATION_BACKENDS = (
|
|||
# auth and allauth settings
|
||||
LOGIN_REDIRECT_URL = os.environ.get('LOGIN_REDIRECT_URL', '/')
|
||||
LOGOUT_URL = os.environ.get('LOGOUT_URL', '/accounts/logout/')
|
||||
PORTAIL_CITOYEN_TEMPLATE_VARS = {}
|
||||
if 'AUTHENTIC2_URL' in os.environ:
|
||||
AUTHENTIC2_URL = os.environ.get('AUTHENTIC2_URL', '')
|
||||
PORTAIL_CITOYEN_TEMPLATE_VARS['AUTHENTIC2_URL'] = AUTHENTIC2_URL
|
||||
INSTALLED_APPS += ('portail_citoyen2.allauth_authentic2',)
|
||||
LOGIN_URL = os.environ.get('LOGIN_URL', '/accounts/authentic2/login/?process=login')
|
||||
PORTAIL_CITOYEN_TEMPLATE_VARS['LOGIN_URL'] = LOGIN_URL
|
||||
SOCIALACCOUNT_QUERY_EMAIL = True
|
||||
SOCIALACCOUNT_PROVIDERS = {
|
||||
'authentic2': {
|
||||
'URL': os.environ.get('AUTHENTIC2_URL', '') + '/idp/oauth2/',
|
||||
'URL': AUTHENTIC2_URL + '/idp/oauth2/',
|
||||
'SCOPE': ['read', 'write'],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
function autologin(authentic_url, login_url, next_url) {
|
||||
var document = window.document;
|
||||
var callback_name = 'callback'+Math.floor(Math.random()*100000+1);
|
||||
window[callback_name] = function(is_logged) {
|
||||
var s;
|
||||
if (is_logged) {
|
||||
if (login_url.indexOf('?') == -1) {
|
||||
s = '?';
|
||||
} else {
|
||||
s = '&';
|
||||
}
|
||||
window.location.href = login_url + s + 'next=' + encodeURI(next_url);
|
||||
}
|
||||
}
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.async = true;
|
||||
script.src = authentic_url + '/accounts/logged-in/?callback=' + callback_name;
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
{% endblock %}
|
||||
</head>
|
||||
<body {% block bodyargs %}{% endblock %}>
|
||||
{% include 'portail_citoyen/autologin.html' %}
|
||||
{% cms_toolbar %}
|
||||
<div id="page">
|
||||
<div id="header">
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{% load staticfiles %}
|
||||
{% if not user.is_authenticated and AUTHENTIC2_URL %}
|
||||
<script src="{% static 'portail_citoyen/js/autologin.js' %}"></script>
|
||||
<script>
|
||||
autologin('{{ AUTHENTIC2_URL }}', '{{ LOGIN_URL }}', '{{ request.build_absolute_uri }}');
|
||||
</script>
|
||||
{% endif %}
|
Reference in New Issue