first step authorize

This commit is contained in:
Cayo Puigdefabregas 2023-11-29 13:21:49 +01:00
parent a1700a9d6e
commit 4f1a5afea7
3 changed files with 35 additions and 10 deletions

View File

@ -115,7 +115,7 @@
</a> </a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link {% if path == 'user_demand_authorization' %}active2{% endif %}" href="{% url 'idhub:user_demand_authorization' %}"> <a class="nav-link {% if path in 'user_demand_authorization, authorize' %}active2{% endif %}" href="{% url 'idhub:user_demand_authorization' %}">
{% trans 'Present a credential' %} {% trans 'Present a credential' %}
</a> </a>
</li> </li>

View File

@ -9,6 +9,6 @@ app_name = 'oidc4vp'
urlpatterns = [ urlpatterns = [
path('verify', views.VerifyView.as_view(), path('verify', views.VerifyView.as_view(),
name="verify"), name="verify"),
path('authorization', views.AuthorizationView.as_view(), path('authorize', views.AuthorizeView.as_view(),
name="authorization"), name="authorize"),
] ]

View File

@ -2,12 +2,18 @@ import json
import base64 import base64
from django.conf import settings from django.conf import settings
from django.views.generic.edit import View from django.views.generic.edit import View, FormView
from django.http import HttpResponse, Http404
from django.shortcuts import get_object_or_404, redirect
from django.utils.translation import gettext_lazy as _
from django.urls import reverse_lazy
from oidc4vp.models import Authorization, Organization from oidc4vp.models import Authorization, Organization
from django.http import HttpResponse, Http404 from idhub.mixins import UserView
from django.shortcuts import get_object_or_404
from idhub.user.forms import (
DemandAuthorizationForm
)
# from django.core.mail import send_mail # from django.core.mail import send_mail
# from django.http import HttpResponse, HttpResponseRedirect # from django.http import HttpResponse, HttpResponseRedirect
@ -17,15 +23,32 @@ from django.shortcuts import get_object_or_404
# from more_itertools import flatten, unique_everseen # from more_itertools import flatten, unique_everseen
class AuthorizationView(View): class AuthorizeView(UserView, FormView):
pass title = _("My wallet")
section = "MyWallet"
template_name = "credentials_presentation.html"
subtitle = _('Credential presentation')
icon = 'bi bi-patch-check-fill'
form_class = DemandAuthorizationForm
success_url = reverse_lazy('idhub:user_demand_authorization')
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
kwargs['user'] = self.request.user
return kwargs
def form_valid(self, form):
authorization = form.save()
if authorization:
return redirect(authorization)
else:
messages.error(self.request, _("Error sending credential!"))
return super().form_valid(form)
class VerifyView(View): class VerifyView(View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
org = self.validate(request) org = self.validate(request)
if not org:
raise Http404("Organization not found!")
presentation_definition = json.dumps(settings.SUPPORTED_CREDENTIALS) presentation_definition = json.dumps(settings.SUPPORTED_CREDENTIALS)
authorization = Authorization( authorization = Authorization(
organization=org, organization=org,
@ -50,6 +73,8 @@ class VerifyView(View):
) )
return org return org
raise Http404("Organization not found!")
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
org = self.validate(request) org = self.validate(request)
import pdb; pdb.set_trace() import pdb; pdb.set_trace()