authentic/src/authentic2_idp_oidc/manager/forms.py

65 lines
2.2 KiB
Python

# authentic2 - versatile identity manager
# Copyright (C) 2022 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django import forms
from authentic2.attributes_ng.engine import get_service_attributes
from authentic2.forms.mixins import SlugMixin
from authentic2.forms.widgets import DatalistTextInput
from authentic2_idp_oidc.models import OIDCClaim, OIDCClient
class OIDCClientForm(SlugMixin, forms.ModelForm):
class Meta:
model = OIDCClient
fields = [
'name',
'redirect_uris',
'post_logout_redirect_uris',
'sector_identifier_uri',
'frontchannel_logout_uri',
'ou',
'identifier_policy',
'idtoken_algo',
'unauthorized_url',
'authorization_mode',
'authorization_flow',
'home_url',
'colour',
'logo',
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['colour'].widget = forms.TextInput(attrs={'type': 'color'})
class OIDCClaimForm(forms.ModelForm):
class Meta:
model = OIDCClaim
fields = ('name', 'value', 'scopes')
widgets = {
'value': DatalistTextInput,
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
data = dict(get_service_attributes(getattr(self.instance, 'client', None))).keys()
widget = self.fields['value'].widget
widget.data = data
widget.name = 'list__oidcclaim-inline'
widget.attrs.update({'list': 'list__oidcclaim-inline'})