From 4f1a5afea72a8f3aa8eca593a37feca90d1d6385 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 29 Nov 2023 13:21:49 +0100 Subject: [PATCH] first step authorize --- idhub/templates/idhub/base.html | 2 +- oidc4vp/urls.py | 4 ++-- oidc4vp/views.py | 39 +++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/idhub/templates/idhub/base.html b/idhub/templates/idhub/base.html index 3514c33..834b7ef 100644 --- a/idhub/templates/idhub/base.html +++ b/idhub/templates/idhub/base.html @@ -115,7 +115,7 @@ diff --git a/oidc4vp/urls.py b/oidc4vp/urls.py index 03010e8..b151a85 100644 --- a/oidc4vp/urls.py +++ b/oidc4vp/urls.py @@ -9,6 +9,6 @@ app_name = 'oidc4vp' urlpatterns = [ path('verify', views.VerifyView.as_view(), name="verify"), - path('authorization', views.AuthorizationView.as_view(), - name="authorization"), + path('authorize', views.AuthorizeView.as_view(), + name="authorize"), ] diff --git a/oidc4vp/views.py b/oidc4vp/views.py index 8abbf66..699f926 100644 --- a/oidc4vp/views.py +++ b/oidc4vp/views.py @@ -2,12 +2,18 @@ import json import base64 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 django.http import HttpResponse, Http404 -from django.shortcuts import get_object_or_404 +from idhub.mixins import UserView +from idhub.user.forms import ( + DemandAuthorizationForm +) # from django.core.mail import send_mail # 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 -class AuthorizationView(View): - pass +class AuthorizeView(UserView, FormView): + 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): def get(self, request, *args, **kwargs): org = self.validate(request) - if not org: - raise Http404("Organization not found!") presentation_definition = json.dumps(settings.SUPPORTED_CREDENTIALS) authorization = Authorization( organization=org, @@ -50,6 +73,8 @@ class VerifyView(View): ) return org + raise Http404("Organization not found!") + def post(self, request, *args, **kwargs): org = self.validate(request) import pdb; pdb.set_trace()