Skip to content

Commit

Permalink
Fix: Save SD-JWT raw token to DB
Browse files Browse the repository at this point in the history
Signed-off-by: George J Padayatti <[email protected]>
  • Loading branch information
georgepadayatti committed May 2, 2024
1 parent acd199e commit 6c3a6b0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
18 changes: 18 additions & 0 deletions certificate/migrations/0003_openid4vccertificate_credentialjwt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2024-05-02 06:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('certificate', '0002_openid4vccertificate'),
]

operations = [
migrations.AddField(
model_name='openid4vccertificate',
name='credentialJwt',
field=models.CharField(blank=True, max_length=256, null=True),
),
]
1 change: 1 addition & 0 deletions certificate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class OpenID4VCCertificate(models.Model):
user = models.ForeignKey(IGrantUser, on_delete=models.CASCADE)
acceptance_token = models.CharField(max_length=256, null=True, blank=True)
credential = JSONField(default={}, blank=True)
credentialJwt = models.CharField(max_length=256, null=True, blank=True)
status = models.CharField(
max_length=250, null=False, blank=False, default="pending"
)
Expand Down
45 changes: 25 additions & 20 deletions certificate/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,32 @@ def get_certificates(request):
)
if credential_response.status_code == 200:
credential_response_json = credential_response.json()
disclosures = credential_response_json.get("credential").split("~")
_, claims = decode_header_and_claims_in_jwt(
credential_response_json.get("credential")
)
disclosure1 = decode_disclosure(disclosures[1])
disclosure2 = decode_disclosure(disclosures[2])
disclosures = credential_response_json.get("credential", "").split("~")
if len(disclosures) == 3:
_, claims = decode_header_and_claims_in_jwt(
credential_response_json.get("credential")
)
disclosure1 = decode_disclosure(disclosures[1])
disclosure2 = decode_disclosure(disclosures[2])

credential = {}
credential[disclosure1[1]] = disclosure1[2]
credential[disclosure2[1]] = disclosure2[2]
credential = {}
credential[disclosure1[1]] = disclosure1[2]
credential[disclosure2[1]] = disclosure2[2]

# credential = {
# "legalName": claims.get("vc", {})
# .get("credentialSubject")
# .get("legalName", ""),
# "identifier": claims.get("vc", {})
# .get("credentialSubject")
# .get("identifier", ""),
# }
pending_oid4vc_certificate.credential = credential
pending_oid4vc_certificate.status = "ready"
pending_oid4vc_certificate.save()
# credential = {
# "legalName": claims.get("vc", {})
# .get("credentialSubject")
# .get("legalName", ""),
# "identifier": claims.get("vc", {})
# .get("credentialSubject")
# .get("identifier", ""),
# }
pending_oid4vc_certificate.credential = credential
pending_oid4vc_certificate.status = "ready"
pending_oid4vc_certificate.credentialJwt = credential_response_json.get(
"credential", ""
)
pending_oid4vc_certificate.save()

certificate_response = response.json()
if certificate_response.get("results"):
Expand All @@ -97,6 +101,7 @@ def get_certificates(request):
"cred_def_id": "Nej8DViZyVvfyaLqGgWUw2:3:CL:84:default",
"rev_reg_id": None,
"cred_rev_id": None,
"credentialJwt": ready_oid4vc_certificate.credentialJwt,
}
)
return Response(certificate_response, status=response.status_code)
Expand Down

0 comments on commit 6c3a6b0

Please sign in to comment.