send a verificable presentation
This commit is contained in:
parent
37908ba1e7
commit
501d2b2894
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.5 on 2023-12-01 18:29
|
||||
# Generated by Django 4.2.5 on 2023-12-04 08:44
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
@ -181,6 +181,7 @@ class Migration(migrations.Migration):
|
|||
(
|
||||
'subject_did',
|
||||
models.ForeignKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name='subject_credentials',
|
||||
to='idhub.did',
|
||||
|
|
|
@ -478,6 +478,7 @@ class VerificableCredential(models.Model):
|
|||
DID,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='subject_credentials',
|
||||
null=True
|
||||
)
|
||||
issuer_did = models.ForeignKey(
|
||||
DID,
|
||||
|
@ -528,7 +529,7 @@ class VerificableCredential(models.Model):
|
|||
context = {
|
||||
'vc_id': self.id,
|
||||
'issuer_did': self.issuer_did.did,
|
||||
'subject_did': self.subject_did,
|
||||
'subject_did': self.subject_did.did,
|
||||
'issuance_date': issuance_date,
|
||||
'first_name': self.user.first_name,
|
||||
'last_name': self.user.last_name,
|
||||
|
|
|
@ -44,7 +44,7 @@ class RequestCredentialForm(forms.Form):
|
|||
if not all([cred.exists(), did.exists()]):
|
||||
return
|
||||
|
||||
did = did[0].did
|
||||
did = did[0]
|
||||
cred = cred[0]
|
||||
try:
|
||||
cred.issue(did)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.5 on 2023-12-01 18:29
|
||||
# Generated by Django 4.2.5 on 2023-12-04 08:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import requests
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.template.loader import get_template
|
||||
|
||||
from utils.idhub_ssikit import issue_verifiable_presentation
|
||||
from oidc4vp.models import Organization
|
||||
|
@ -10,6 +12,7 @@ class AuthorizeForm(forms.Form):
|
|||
def __init__(self, *args, **kwargs):
|
||||
self.data = kwargs.get('data', {}).copy()
|
||||
self.user = kwargs.pop('user', None)
|
||||
self.org = kwargs.pop('org', None)
|
||||
self.presentation_definition = kwargs.pop('presentation_definition', [])
|
||||
|
||||
reg = r'({})'.format('|'.join(self.presentation_definition))
|
||||
|
@ -42,22 +45,22 @@ class AuthorizeForm(forms.Form):
|
|||
return
|
||||
|
||||
did = self.list_credentials[0].subject_did
|
||||
vp_template = get_template('credentials/verifiable_presentation.json')
|
||||
|
||||
# self.vp = issue_verifiable_presentation(
|
||||
# vp_template: Template,
|
||||
# vc_list: list[str],
|
||||
# jwk_holder: str,
|
||||
# holder_did: str)
|
||||
|
||||
self.vp = issue_verifiable_presentation(
|
||||
vp_template: Template,
|
||||
vc_list: list[str],
|
||||
jwk_holder: str,
|
||||
holder_did: str)
|
||||
|
||||
self.vp = issue_verifiable_presentation(
|
||||
vp_template: Template,
|
||||
vp_template,
|
||||
self.list_credentials,
|
||||
did.key_material,
|
||||
did.did)
|
||||
|
||||
if commit:
|
||||
result = requests.post(self.vp)
|
||||
return result
|
||||
return org.send(self.vp)
|
||||
|
||||
return
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ class Organization(models.Model):
|
|||
url = "{url}/verify".format(
|
||||
url=self.response_uri.strip("/"),
|
||||
)
|
||||
auth = (self.my_client_id, self.client_secret)
|
||||
auth = (self.my_client_id, self.my_client_secret)
|
||||
return requests.post(url, data=vp, auth=auth)
|
||||
|
||||
def demand_authorization(self):
|
||||
|
|
|
@ -38,6 +38,7 @@ class AuthorizeView(UserView, FormView):
|
|||
vps = self.request.GET.get('presentation_definition')
|
||||
# import pdb; pdb.set_trace()
|
||||
kwargs['presentation_definition'] = json.loads(vps)
|
||||
kwargs["org"] = self.get_org()
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
|
@ -48,6 +49,17 @@ class AuthorizeView(UserView, FormView):
|
|||
messages.error(self.request, _("Error sending credential!"))
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_org(self):
|
||||
client_id = self.request.GET.get("client_id")
|
||||
if not client_id:
|
||||
raise Http404("Organization not found!")
|
||||
|
||||
org = get_object_or_404(
|
||||
Organization,
|
||||
client_id=client_id,
|
||||
)
|
||||
return org
|
||||
|
||||
|
||||
class VerifyView(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue