0001-add-copyright-headers-32866.patch
setup.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
3 |
# Copyright (C) 2019 Entr'ouvert |
|
4 |
# |
|
5 |
# This program is free software: you can redistribute it and/or modify it |
|
6 |
# under the terms of the GNU Affero General Public License as published |
|
7 |
# by the Free Software Foundation, either version 3 of the License, or |
|
8 |
# (at your option) any later version. |
|
9 |
# |
|
10 |
# This program is distributed in the hope that it will be useful, |
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
# GNU Affero General Public License for more details. |
|
14 |
# |
|
15 |
# You should have received a copy of the GNU Affero General Public License |
|
16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 | ||
2 | 18 |
import sys |
3 | 19 |
import os |
4 | 20 |
import subprocess |
src/authentic2_auth_fc/__init__.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 | ||
1 | 17 |
from . import utils |
2 | 18 |
from . import app_settings |
3 | 19 |
src/authentic2_auth_fc/api_views.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 | ||
1 | 17 |
from django.shortcuts import get_object_or_404 |
2 | 18 |
from django.contrib.auth import get_user_model |
3 | 19 |
src/authentic2_auth_fc/app_settings.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 |
import sys |
|
18 | ||
1 | 19 | |
2 | 20 |
class AppSettings(object): |
3 | 21 |
'''Thanks django-allauth''' |
... | ... | |
10 | 28 |
from django.conf import settings |
11 | 29 |
from django.core.exceptions import ImproperlyConfigured |
12 | 30 | |
13 |
v = getattr(settings, self.prefix + name, dflt)
|
|
31 |
v = getattr(settings, self.prefix + name, dflt) |
|
14 | 32 |
if v is self.__SENTINEL: |
15 | 33 |
raise ImproperlyConfigured('Missing setting %r' % (self.prefix + name)) |
16 | 34 |
return v |
... | ... | |
118 | 136 |
def popup(self): |
119 | 137 |
return self._setting('POPUP', False) |
120 | 138 | |
121 | ||
122 |
import sys |
|
123 | ||
124 | 139 |
app_settings = AppSettings('A2_FC_') |
125 | 140 |
app_settings.__name__ = __name__ |
126 | 141 |
sys.modules[__name__] = app_settings |
src/authentic2_auth_fc/authenticators.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 | ||
1 | 17 |
from django.utils.translation import gettext_noop |
2 | 18 |
from django.template.loader import render_to_string |
3 | 19 |
from django.shortcuts import render |
src/authentic2_auth_fc/backends.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 | ||
1 | 17 |
import json |
2 | 18 |
import logging |
3 | 19 |
src/authentic2_auth_fc/locale/fr/LC_MESSAGES/django.po | ||
---|---|---|
1 |
# Authentic2 Mon.service-public.fr plugin french translations |
|
2 |
# Copyright (C) 2014 Entr'ouvert |
|
3 |
# This file is distributed under the same license as the authentic2-auth-fc package. |
|
4 |
# Benjamin Dauvergne <bdauvergne@entrouvert.com, 2017. |
|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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/>. |
|
5 | 16 |
# |
6 | 17 |
msgid "" |
7 | 18 |
msgstr "" |
src/authentic2_auth_fc/models.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 | ||
1 | 17 |
import base64 |
2 | 18 |
import json |
3 | 19 |
import hmac |
... | ... | |
24 | 40 |
def parse_id_token(id_token, client_id=None, client_secret=None): |
25 | 41 |
try: |
26 | 42 |
splitted = str(id_token).split('.') |
27 |
except: |
|
43 |
except Exception:
|
|
28 | 44 |
return None, 'invalid id_token' |
29 | 45 |
if len(splitted) != 3: |
30 | 46 |
return None, 'invalid id_token' |
... | ... | |
54 | 70 |
return False |
55 | 71 |
try: |
56 | 72 |
parsed_issuer = urlparse.urlparse(payload['iss']) |
57 |
except: |
|
73 |
except Exception:
|
|
58 | 74 |
return False |
59 | 75 |
return parsed_issuer.scheme == parsed.scheme and parsed_issuer.netloc == parsed.netloc |
60 | 76 | |
... | ... | |
86 | 102 | |
87 | 103 |
def __unicode__(self): |
88 | 104 |
user_info = self.get_user_info() |
89 |
id_token = self.id_token |
|
90 | 105 |
display_name = [] |
91 | 106 |
if 'given_name' in user_info: |
92 | 107 |
display_name.append(user_info['given_name']) |
src/authentic2_auth_fc/urls.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 | ||
1 | 17 |
from django.conf.urls import url, include |
2 | 18 | |
3 | 19 |
from . import views |
... | ... | |
8 | 24 |
] |
9 | 25 | |
10 | 26 |
urlpatterns = [ |
11 |
url(r'^fc/', include(fcpatterns)),
|
|
12 |
url(r'^accounts/fc/register/$', views.registration, name='fc-registration'),
|
|
13 |
url(r'^accounts/fc/unlink/$', views.unlink, name='fc-unlink'),
|
|
27 |
url(r'^fc/', include(fcpatterns)), |
|
28 |
url(r'^accounts/fc/register/$', views.registration, name='fc-registration'), |
|
29 |
url(r'^accounts/fc/unlink/$', views.unlink, name='fc-unlink'), |
|
14 | 30 |
] |
src/authentic2_auth_fc/utils.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 | ||
1 | 17 |
import urllib |
2 | 18 |
import logging |
3 | 19 |
import os |
src/authentic2_auth_fc/views.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 | ||
1 | 17 |
import uuid |
2 | 18 |
import logging |
3 | 19 |
import json |
4 | 20 |
import urlparse |
5 |
import urllib |
|
6 | 21 |
import requests |
7 | 22 | |
8 | 23 |
from requests_oauthlib import OAuth2Session |
... | ... | |
10 | 25 | |
11 | 26 |
import django |
12 | 27 |
from django.views.generic import View, FormView |
13 |
from django.views.generic.detail import SingleObjectMixin |
|
14 | 28 |
from django.http import HttpResponseRedirect, Http404 |
15 | 29 |
from django.contrib.auth import authenticate, REDIRECT_FIELD_NAME, get_user_model |
16 | 30 |
from django.contrib import messages |
... | ... | |
473 | 487 |
if self.get_in_popup(): |
474 | 488 |
params['popup'] = '' |
475 | 489 |
redirect_to = a2_utils.make_url('fc-login-or-link', params=params) |
476 |
if not 'email' in data:
|
|
490 |
if 'email' not in data:
|
|
477 | 491 |
data[REDIRECT_FIELD_NAME] = redirect_to |
478 | 492 |
messages.warning(request, |
479 | 493 |
_("FranceConnect didn't provide your email address, please do.")) |
tests/conftest.py | ||
---|---|---|
1 |
# authentic2-auth-fc - authentic2 authentication for FranceConnect |
|
2 |
# Copyright (C) 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 | ||
1 | 17 |
import json |
2 | 18 |
import pytest |
3 | 19 |
import django_webtest |
4 |
- |