get the credentials from form
This commit is contained in:
parent
8da426ef34
commit
d8c9e0b8b3
|
@ -45,34 +45,44 @@ from oidc4vp.models import Organization
|
||||||
|
|
||||||
|
|
||||||
class AuthorizeForm(forms.Form):
|
class AuthorizeForm(forms.Form):
|
||||||
organization = forms.ChoiceField(choices=[])
|
# organization = forms.ChoiceField(choices=[])
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
# import pdb; pdb.set_trace()
|
# import pdb; pdb.set_trace()
|
||||||
|
self.data = kwargs.get('data', {}).copy()
|
||||||
self.user = kwargs.pop('user', None)
|
self.user = kwargs.pop('user', None)
|
||||||
self.presentation_definition = kwargs.pop('presentation_definition', [])
|
self.presentation_definition = kwargs.pop('presentation_definition', [])
|
||||||
|
|
||||||
|
reg = r'({})'.format('|'.join(self.presentation_definition))
|
||||||
|
|
||||||
self.credentials = self.user.vcredentials.filter(
|
self.credentials = self.user.vcredentials.filter(
|
||||||
schema__type__in=self.presentation_definition
|
schema__type__iregex=reg
|
||||||
)
|
)
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields['organization'].choices = [
|
for vp in self.presentation_definition:
|
||||||
(x.id, x.name) for x in Organization.objects.filter()
|
vp = vp.lower()
|
||||||
if x.response_uri != settings.RESPONSE_URI
|
choices = [
|
||||||
|
(str(x.id), x.schema.type.lower()) for x in self.credentials.filter(
|
||||||
|
schema__type__iexact=vp)
|
||||||
]
|
]
|
||||||
|
self.fields[vp.lower()] = forms.ChoiceField(
|
||||||
|
widget=forms.RadioSelect,
|
||||||
|
choices=choices
|
||||||
|
)
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
self.org = Organization.objects.filter(
|
# self.org = Organization.objects.filter(
|
||||||
id=self.data['organization']
|
# id=self.data['organization']
|
||||||
)
|
# )
|
||||||
if not self.org.exists():
|
# if not self.org.exists():
|
||||||
return
|
# return
|
||||||
|
|
||||||
self.org = self.org[0]
|
# self.org = self.org[0]
|
||||||
|
|
||||||
if commit:
|
# if commit:
|
||||||
url = self.org.demand_authorization()
|
# url = self.org.demand_authorization()
|
||||||
if url.status_code == 200:
|
# if url.status_code == 200:
|
||||||
return url.json().get('redirect_uri')
|
# return url.json().get('redirect_uri')
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ from django.http import HttpResponse, Http404
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
|
from django.contrib import messages
|
||||||
|
|
||||||
from oidc4vp.models import Authorization, Organization
|
from oidc4vp.models import Authorization, Organization
|
||||||
from idhub.mixins import UserView
|
from idhub.mixins import UserView
|
||||||
|
|
Loading…
Reference in New Issue