franceconnect: add scopes setting (#39286)

This commit is contained in:
Benjamin Dauvergne 2020-01-27 13:22:04 +01:00
parent 6f927f0196
commit 8c29562d35
3 changed files with 28 additions and 4 deletions

View File

@ -33,6 +33,25 @@ class SettingsForm(forms.Form):
client_secret = forms.CharField(
label=_('Client Secret'),
widget=forms.TextInput(attrs={'size': 64}))
scopes = forms.MultipleChoiceField(
label=_('Scopes'),
choices=[
('given_name', _('given name (given_name)')),
('gender', _('gender (gender)')),
('birthdate', _('birthdate (birthdate)')),
('birthcountry', _('birthcountry (birthcountry)')),
('birthplace', _('birthplace (birthplace)')),
('family_name', _('family name (family_name)')),
('email', _('email (email)')),
('preferred_username', _('usual family name (preferred_username)')),
('address', _('address (address)')),
('phone', _('phone (phone)')),
('identite_pivot', _('identite_pivot (identite_pivot)')),
('profile', _('profile (profile)')),
('birth', _('birth profile (birth)')),
],
widget=forms.CheckboxSelectMultiple,
help_text=_('These scopes will be requested in addition to openid'))
class EnableForm(forms.Form):

View File

@ -60,6 +60,7 @@ class HomeView(FormView):
initial['client_id'] = get_variable('A2_FC_CLIENT_ID').value
initial['client_secret'] = get_variable('A2_FC_CLIENT_SECRET').value
initial['scopes'] = get_variable('A2_FC_SCOPES').json or ['profile', 'email']
return initial
@ -104,6 +105,10 @@ class HomeView(FormView):
})
variable.save()
variable = get_variable('A2_FC_SCOPES')
variable.json = form.cleaned_data['scopes']
variable.save()
return super(HomeView, self).form_valid(form)
def get_context_data(self, **kwargs):

View File

@ -28,17 +28,17 @@ def test_franceconnect(app, admin_user):
response = app.get('/franceconnect/')
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 5
assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 0
response = response.click('Enable')
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 5
assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 0
response = response.form.submit().follow()
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 4
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 5
assert Variable.objects.filter(name__startswith='SETTING_A2_FC_ENABLE', value='true').count() == 1
response.form.set('platform', 'prod')
@ -46,7 +46,7 @@ def test_franceconnect(app, admin_user):
response.form.set('client_secret', '1234')
response = response.form.submit().follow()
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 9
assert Variable.objects.filter(name__startswith='SETTING_A2_FC').count() == 10
for key, value in PLATFORMS['prod'].items():
assert Variable.objects.filter(name='SETTING_' + key, value=value).count() == 1