From 7d88b1e0cb4e0f9500eef874eb9c913418523e36 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 7 Mar 2024 17:52:39 +0100 Subject: [PATCH] add code into the email --- oidc4vp/models.py | 7 +++++++ oidc4vp/views.py | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/oidc4vp/models.py b/oidc4vp/models.py index 9037a8b..2ed3d30 100644 --- a/oidc4vp/models.py +++ b/oidc4vp/models.py @@ -264,6 +264,12 @@ class OAuth2VPToken(models.Model): self.authorization = Authorization.objects.filter(code=code).first() + @property + def code(self): + if not self.authorization: + return '' + return self.authorization.code + def verifing(self): self.result_verify = verify_presentation(self.vp_token) @@ -312,3 +318,4 @@ class OAuth2VPToken(models.Model): self.user_info = tk.get( "verifiableCredential", [{}] )[-1].get("credentialSubject") + return json.dumps(self.user_info, indent=2) diff --git a/oidc4vp/views.py b/oidc4vp/views.py index e5e8cec..359a638 100644 --- a/oidc4vp/views.py +++ b/oidc4vp/views.py @@ -110,9 +110,9 @@ class AuthorizeView(UserView, FormView): @method_decorator(csrf_exempt, name='dispatch') class VerifyView(View): - subject_template_name = 'verify_subject.txt' - email_template_name = 'verify_email.txt' - html_email_template_name = 'verify_email.html' + subject_template_name = 'email/verify_subject.txt' + email_template_name = 'email/verify_email.txt' + html_email_template_name = 'email/verify_email.html' def get(self, request, *args, **kwargs): org = self.validate(request) @@ -128,7 +128,6 @@ class VerifyView(View): def post(self, request, *args, **kwargs): code = self.request.POST.get("code") vp_tk = self.request.POST.get("vp_token") - self.verification = {} if not vp_tk or not code: raise Http404("Page not Found!") @@ -200,6 +199,7 @@ class VerifyView(View): "domain": settings.DOMAIN, "url_domain": url_domain, "verification": self.get_verification(), + "code": self.vp_token.code, } return context @@ -218,6 +218,8 @@ class VerifyView(View): email_message.attach_alternative(html_email, 'text/html') return email_message + def get_verification(self): + return self.vp_token.get_user_info() class AllowCodeView(View): def get(self, request, *args, **kwargs):