0001-misc-add-a-page-to-configure-FranceConnect.patch
MANIFEST.in | ||
---|---|---|
1 | 1 |
recursive-include hobo/static *.css *.png *.js |
2 | 2 |
recursive-include hobo/templates *.html *.txt |
3 |
recursive-include hobo/franceconnect/templates *.html *.txt |
|
3 | 4 |
recursive-include hobo/profile/templates *.html *.txt |
4 | 5 |
recursive-include hobo/theme/templates *.html *.txt |
5 | 6 |
recursive-include hobo/environment/templates *.html *.txt |
hobo/franceconnect/forms.py | ||
---|---|---|
1 |
# hobo - portal to configure and deploy applications |
|
2 |
# Copyright (C) 2015-2019 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from django import forms |
|
18 |
from django.utils.translation import ugettext_lazy as _ |
|
19 | ||
20 | ||
21 |
class SettingsForm(forms.Form): |
|
22 |
platform = forms.ChoiceField( |
|
23 |
label=_('Platform'), |
|
24 |
choices=[ |
|
25 |
('prod', _('Production')), |
|
26 |
('test', _('Integration')), |
|
27 |
]) |
|
28 |
client_id = forms.CharField( |
|
29 |
label=_('Client ID'), |
|
30 |
help_text=_('See <a href="https://franceconnect.gouv.fr/fournisseur-service">' |
|
31 |
'FranceConnect partners site</a> for getting client ID and secret.'), |
|
32 |
widget=forms.TextInput(attrs={'size': 64})) |
|
33 |
client_secret = forms.CharField( |
|
34 |
label=_('Client Secret'), |
|
35 |
widget=forms.TextInput(attrs={'size': 64})) |
|
36 | ||
37 | ||
38 |
class EnableForm(forms.Form): |
|
39 |
pass |
hobo/franceconnect/templates/hobo/franceconnect_disable.html | ||
---|---|---|
1 |
{% extends "hobo/franceconnect_home.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block appbar %} |
|
5 |
<h2>FranceConnect</h2> |
|
6 |
{% endblock %} |
|
7 | ||
8 |
{% block content %} |
|
9 |
<form method="post"> |
|
10 |
{% csrf_token %} |
|
11 |
<p> |
|
12 |
{% trans "Are you sure you want to disable FranceConnect support?" %} |
|
13 |
{{ form.as_p }} |
|
14 |
<div class="buttons"> |
|
15 |
<button class="submit-button">{% trans "Disable" %}</button> |
|
16 |
<a class="cancel" href="{% url 'franceconnect-home' %}">{% trans "Cancel" %}</a> |
|
17 |
</div> |
|
18 |
</form> |
|
19 | ||
20 |
{% endblock %} |
hobo/franceconnect/templates/hobo/franceconnect_enable.html | ||
---|---|---|
1 |
{% extends "hobo/franceconnect_home.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block appbar %} |
|
5 |
<h2>FranceConnect</h2> |
|
6 |
{% endblock %} |
|
7 | ||
8 |
{% block content %} |
|
9 |
<form method="post"> |
|
10 |
{% csrf_token %} |
|
11 |
<p> |
|
12 |
{% trans "Are you sure you want to enable FranceConnect support?" %} |
|
13 |
{{ form.as_p }} |
|
14 |
<div class="buttons"> |
|
15 |
<button class="submit-button">{% trans "Enable" %}</button> |
|
16 |
<a class="cancel" href="{% url 'franceconnect-home' %}">{% trans "Cancel" %}</a> |
|
17 |
</div> |
|
18 |
</form> |
|
19 | ||
20 |
{% endblock %} |
hobo/franceconnect/templates/hobo/franceconnect_home.html | ||
---|---|---|
1 |
{% extends "hobo/base.html" %} |
|
2 |
{% load i18n %} |
|
3 | ||
4 |
{% block breadcrumb %} |
|
5 |
{{ block.super }} |
|
6 |
<a href="{% url 'franceconnect-home' %}">FranceConnect</a> |
|
7 |
{% endblock %} |
|
8 | ||
9 |
{% block appbar %} |
|
10 |
<h2>{% trans 'FranceConnect' %}</h2> |
|
11 |
{% if enabled %} |
|
12 |
<span class="actions"> |
|
13 |
<a rel="popup" href="{% url 'franceconnect-disable' %}">{% trans 'Disable' %}</a> |
|
14 |
</span> |
|
15 |
{% endif %} |
|
16 |
{% endblock %} |
|
17 | ||
18 |
{% block content %} |
|
19 | ||
20 |
<div class="infonotice"> |
|
21 |
{% blocktrans %} |
|
22 |
FranceConnect is the solution proposed by the French state to streamline |
|
23 |
logging in online services. |
|
24 |
{% endblocktrans %} |
|
25 |
</div> |
|
26 | ||
27 |
{% if not enabled %} |
|
28 |
<p> |
|
29 |
{% trans "Support is currently disabled." %} |
|
30 |
</p> |
|
31 |
<p> |
|
32 |
<a class="button" rel="popup" href="{% url 'franceconnect-enable' %}">Enable</a> |
|
33 |
</p> |
|
34 |
{% else %} |
|
35 | ||
36 |
<form method="post"> |
|
37 |
{% csrf_token %} |
|
38 |
{{ form.as_p }} |
|
39 | ||
40 |
<div class="buttons"> |
|
41 |
<button class="submit-button">{% trans "Submit" %}</button> |
|
42 |
</div> |
|
43 |
</form> |
|
44 | ||
45 |
{% endif %} |
|
46 | ||
47 |
{% endblock %} |
hobo/franceconnect/urls.py | ||
---|---|---|
1 |
# hobo - portal to configure and deploy applications |
|
2 |
# Copyright (C) 2015-2019 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from django.conf.urls import url |
|
18 | ||
19 |
from . import views |
|
20 | ||
21 |
urlpatterns = [ |
|
22 |
url(r'^$', views.home, name='franceconnect-home'), |
|
23 |
url(r'^enable$', views.enable, name='franceconnect-enable'), |
|
24 |
url(r'^disable$', views.disable, name='franceconnect-disable'), |
|
25 |
] |
hobo/franceconnect/views.py | ||
---|---|---|
1 |
# hobo - portal to configure and deploy applications |
|
2 |
# Copyright (C) 2015-2019 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify it |
|
5 |
# under the terms of the GNU Affero General Public License as published |
|
6 |
# by the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU Affero General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU Affero General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from django.core.urlresolvers import reverse_lazy |
|
18 |
from django.views.generic import RedirectView, FormView |
|
19 | ||
20 |
from hobo.environment.models import Variable, Authentic |
|
21 |
from .forms import SettingsForm, EnableForm |
|
22 | ||
23 | ||
24 |
def get_variable(name): |
|
25 |
variable, created = Variable.objects.get_or_create( |
|
26 |
name='SETTING_' + name, |
|
27 |
defaults={ |
|
28 |
'auto': True, |
|
29 |
'service': Authentic.objects.get(secondary=False), |
|
30 |
}) |
|
31 |
return variable |
|
32 | ||
33 | ||
34 |
class HomeView(FormView): |
|
35 |
template_name = 'hobo/franceconnect_home.html' |
|
36 |
form_class = SettingsForm |
|
37 |
success_url = reverse_lazy('franceconnect-home') |
|
38 | ||
39 |
def get_initial(self): |
|
40 |
initial = super(HomeView, self).get_initial() |
|
41 |
authorize_url = get_variable('A2_FC_AUTHORIZE_URL').value |
|
42 |
if authorize_url == 'https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize': |
|
43 |
initial['platform'] = 'test' |
|
44 |
elif authorize_url == 'https://app.franceconnect.gouv.fr/api/v1/authorize': |
|
45 |
initial['platform'] = 'prod' |
|
46 | ||
47 |
initial['client_id'] = get_variable('A2_FC_CLIENT_ID').value |
|
48 |
initial['client_secret'] = get_variable('A2_FC_CLIENT_SECRET').value |
|
49 | ||
50 |
return initial |
|
51 | ||
52 |
def form_valid(self, form): |
|
53 |
platforms = { |
|
54 |
'test': { |
|
55 |
'A2_FC_AUTHORIZE_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/authorize', |
|
56 |
'A2_FC_TOKEN_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/token', |
|
57 |
'A2_FC_USERINFO_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/userinfo', |
|
58 |
'A2_FC_LOGOUT_URL': 'https://fcp.integ01.dev-franceconnect.fr/api/v1/logout', |
|
59 |
}, |
|
60 |
'prod': { |
|
61 |
'A2_FC_AUTHORIZE_URL': 'https://app.franceconnect.gouv.fr/api/v1/authorize', |
|
62 |
'A2_FC_TOKEN_URL': 'https://app.franceconnect.gouv.fr/api/v1/token', |
|
63 |
'A2_FC_USERINFO_URL': 'https://app.franceconnect.gouv.fr/api/v1/userinfo', |
|
64 |
'A2_FC_LOGOUT_URL': 'https://app.franceconnect.gouv.fr/api/v1/logout', |
|
65 |
} |
|
66 |
} |
|
67 | ||
68 |
for key, value in platforms[form.cleaned_data['platform']].items(): |
|
69 |
variable = get_variable(key) |
|
70 |
variable.value = value |
|
71 |
variable.save() |
|
72 | ||
73 |
variable = get_variable('A2_FC_CLIENT_ID') |
|
74 |
variable.value = form.cleaned_data['client_id'] |
|
75 |
variable.save() |
|
76 | ||
77 |
variable = get_variable('A2_FC_CLIENT_SECRET') |
|
78 |
variable.value = form.cleaned_data['client_secret'] |
|
79 |
variable.save() |
|
80 | ||
81 |
variable = get_variable('A2_FC_VERIFY_CERTIFICATE') |
|
82 |
variable.value = 'true' |
|
83 |
variable.save() |
|
84 | ||
85 |
return super(HomeView, self).form_valid(form) |
|
86 | ||
87 |
def get_context_data(self, **kwargs): |
|
88 |
context = super(HomeView, self).get_context_data(**kwargs) |
|
89 |
context['enabled'] = bool(get_variable('A2_FC_ENABLE').json) |
|
90 |
return context |
|
91 | ||
92 |
home = HomeView.as_view() |
|
93 | ||
94 | ||
95 |
class EnableView(FormView): |
|
96 |
form_class = EnableForm |
|
97 |
template_name = 'hobo/franceconnect_enable.html' |
|
98 |
success_url = reverse_lazy('franceconnect-home') |
|
99 | ||
100 |
def form_valid(self, form): |
|
101 |
variable = get_variable('A2_FC_ENABLE') |
|
102 |
variable.value = 'true' |
|
103 |
variable.save() |
|
104 |
return super(EnableView, self).form_valid(form) |
|
105 | ||
106 |
enable = EnableView.as_view() |
|
107 | ||
108 | ||
109 |
class DisableView(FormView): |
|
110 |
form_class = EnableForm |
|
111 |
template_name = 'hobo/franceconnect_disable.html' |
|
112 |
success_url = reverse_lazy('franceconnect-home') |
|
113 | ||
114 |
def form_valid(self, form): |
|
115 |
variable = get_variable('A2_FC_ENABLE') |
|
116 |
variable.value = 'false' |
|
117 |
variable.save() |
|
118 |
return super(DisableView, self).form_valid(form) |
|
119 | ||
120 |
disable = DisableView.as_view() |
hobo/settings.py | ||
---|---|---|
40 | 40 |
'mellon', |
41 | 41 |
'gadjo', |
42 | 42 |
'hobo.environment', |
43 |
'hobo.franceconnect', |
|
43 | 44 |
'hobo.profile', |
44 | 45 |
'hobo.theme', |
45 | 46 |
'hobo.emails', |
hobo/templates/hobo/home.html | ||
---|---|---|
9 | 9 |
<li><a href="{% url 'profile-home' %}">{% trans 'User Profile' %}</a></li> |
10 | 10 |
<li><a href="{% url 'theme-home' %}">{% trans 'Theme' %}</a></li> |
11 | 11 |
<li><a href="{% url 'emails-home' %}">{% trans 'Emails' %}</a></li> |
12 |
<li><a href="{% url 'franceconnect-home' %}">FranceConnect</a></li> |
|
12 | 13 |
<li><a href="{% url 'environment-home' %}">{% trans 'Services' %}</a></li> |
13 | 14 |
<li><a href="{% url 'environment-variables' %}">{% trans 'Variables' %}</a></li> |
14 | 15 |
</ul> |
hobo/urls.py | ||
---|---|---|
7 | 7 |
from .views import admin_required, login, login_local, logout, home, health_json, menu_json, hobo |
8 | 8 |
from .urls_utils import decorated_includes |
9 | 9 |
from .environment.urls import urlpatterns as environment_urls |
10 |
from .franceconnect.urls import urlpatterns as franceconnect_urls |
|
10 | 11 |
from .profile.urls import urlpatterns as profile_urls |
11 | 12 |
from .theme.urls import urlpatterns as theme_urls |
12 | 13 |
from .emails.urls import urlpatterns as emails_urls |
... | ... | |
17 | 18 |
include(environment_urls))), |
18 | 19 |
url(r'^profile/', decorated_includes(admin_required, |
19 | 20 |
include(profile_urls))), |
21 |
url(r'^franceconnect/', |
|
22 |
decorated_includes(admin_required, include(franceconnect_urls))), |
|
20 | 23 |
url(r'^theme/', decorated_includes(admin_required, |
21 | 24 |
include(theme_urls))), |
22 | 25 |
url(r'^emails/', decorated_includes(admin_required, include(emails_urls))), |
23 |
- |