send credential as issuer to TA
This commit is contained in:
parent
a975d831f9
commit
fd8f404908
|
@ -3,6 +3,7 @@ import ujson
|
||||||
import pytz
|
import pytz
|
||||||
import hashlib
|
import hashlib
|
||||||
import datetime
|
import datetime
|
||||||
|
import requests
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -516,6 +517,51 @@ class DID(models.Model):
|
||||||
user.save()
|
user.save()
|
||||||
return user.encrypt_data(value)
|
return user.encrypt_data(value)
|
||||||
|
|
||||||
|
def send_credential_as_issuer_to_TA(self):
|
||||||
|
url = settings.VERIFIABLE_REGISTER_URL
|
||||||
|
token = settings.TOKEN_TA_API
|
||||||
|
if not url or not token:
|
||||||
|
return
|
||||||
|
|
||||||
|
headers = {"Bearer {}".format(token)}
|
||||||
|
|
||||||
|
credential = self._render_credential_issuer()
|
||||||
|
response = requests.post(url=url, data=credential, headers=headers)
|
||||||
|
if response.status_code >= 300:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.credential_as_issuer = response.text
|
||||||
|
|
||||||
|
def get_context(self):
|
||||||
|
format = "%Y-%m-%dT%H:%M:%SZ"
|
||||||
|
issuance_date = datetime.datetime.now().strftime(format)
|
||||||
|
credential_status_id = 'https://revocation.not.supported/'
|
||||||
|
org = Organization.objects.get(main=True)
|
||||||
|
allow_schemas = [x.url for x in Schemas.objects.all()]
|
||||||
|
context = {
|
||||||
|
"vc_id": "",
|
||||||
|
"id_credential": "",
|
||||||
|
"issuer_did": "",
|
||||||
|
"organization": "",
|
||||||
|
"validUntil": "",
|
||||||
|
"issuance_date": issuance_date,
|
||||||
|
"subject_did": self.did,
|
||||||
|
"legalName": org.name or "",
|
||||||
|
"allowedSchemas": allow_schemas,
|
||||||
|
"email": self.user.email,
|
||||||
|
"credential_status_id": credential_status_id,
|
||||||
|
}
|
||||||
|
return context
|
||||||
|
|
||||||
|
def _render_credential_issuer(self):
|
||||||
|
context = self.get_context()
|
||||||
|
template_name = "credentials/ereuse-issuer.json"
|
||||||
|
tmpl = get_template(template_name)
|
||||||
|
credential = ujson.loads(tmpl.render(context))
|
||||||
|
credential.pop("credentialStatus", None)
|
||||||
|
|
||||||
|
return ujson.dumps(credential)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Schemas(models.Model):
|
class Schemas(models.Model):
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
"email": "{{ email }}"
|
"email": "{{ email }}"
|
||||||
},
|
},
|
||||||
"credentialStatus": {
|
"credentialStatus": {
|
||||||
"id": "{{ credential_status_id}}",
|
"id": "{{ credential_status_id }}",
|
||||||
"type": "RevocationBitmap2022",
|
"type": "RevocationBitmap2022",
|
||||||
"revocationBitmapIndex": "{{ id_credential }}"
|
"revocationBitmapIndex": "{{ id_credential }}"
|
||||||
},
|
},
|
||||||
|
|
|
@ -242,3 +242,5 @@ CREATE_TEST_USERS = config('CREATE_TEST_USERS', default=False, cast=bool)
|
||||||
ENABLE_2FACTOR_AUTH = config('ENABLE_2FACTOR_AUTH', default=True, cast=bool)
|
ENABLE_2FACTOR_AUTH = config('ENABLE_2FACTOR_AUTH', default=True, cast=bool)
|
||||||
COMMIT = config('COMMIT', default='')
|
COMMIT = config('COMMIT', default='')
|
||||||
|
|
||||||
|
VERIFIABLE_REGISTER_URL = config('VERIFIABLE_REGISTER_URL', default='')
|
||||||
|
TOKEN_TA_API = config('TOKEN_TA_API', default='')
|
||||||
|
|
Loading…
Reference in New Issue