demand authorization get to verifier

This commit is contained in:
Cayo Puigdefabregas 2023-11-28 12:49:28 +01:00
parent cfbbaf491e
commit 5e95d6b15c
1 changed files with 46 additions and 59 deletions

View File

@ -2,7 +2,7 @@ import json
from django.views.generic.edit import View from django.views.generic.edit import View
from oidc4vp.models import Authorization from oidc4vp.models import Authorization, Organization
from django.http import HttpResponse from django.http import HttpResponse
@ -11,69 +11,56 @@ from django.http import HttpResponse
# from utils.idhub_ssikit import verify_presentation # from utils.idhub_ssikit import verify_presentation
# from oidc4vp.models import VPVerifyRequest # from oidc4vp.models import VPVerifyRequest
# from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
# from more_itertools import flatten, unique_everseen # from more_itertools import flatten, unique_everseen
class VerifyView(View): class VerifyView(View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
import pdb; pdb.set_trace() org_url = request.GET.get('demand_uri')
res = json.dumps({"uri": "http://localhost:10000"}) org = get_object_or_404(Organization, response_uri=org_url)
return HttpResponse(res)
def DemandAuthorizationView(request):
assert request.method == "GET"
import pdb; pdb.set_trace()
params = request.GET.params
org = Organization.objects.filter(
url=params.get('redirect_uri')
)
authorization = Authorization( authorization = Authorization(
organization=org, organization=org,
presentation_definition="MemberCredential" presentation_definition="MemberCredential"
) )
# authorization.save() import pdb; pdb.set_trace()
res = json.dumps({"uri": authorization.authorize()}) res = json.dumps({"redirect_uri": authorization.authorize()})
return HttpResponse(res) return HttpResponse(res)
def post(self, request, *args, **kwargs):
def verify(request):
import pdb; pdb.set_trace() import pdb; pdb.set_trace()
# assert request.method == "POST" # # TODO: incorporate request.POST["presentation_submission"] as schema definition
# # TODO: incorporate request.POST["presentation_submission"] as schema definition # (presentation_valid, _) = verify_presentation(request.POST["vp_token"])
# (presentation_valid, _) = verify_presentation(request.POST["vp_token"]) # if not presentation_valid:
# if not presentation_valid: # raise Exception("Failed to verify signature on the given Verifiable Presentation.")
# raise Exception("Failed to verify signature on the given Verifiable Presentation.") # vp = json.loads(request.POST["vp_token"])
# vp = json.loads(request.POST["vp_token"]) # nonce = vp["nonce"]
# nonce = vp["nonce"] # # "vr" = verification_request
# # "vr" = verification_request # vr = get_object_or_404(VPVerifyRequest, nonce=nonce) # TODO: return meaningful error, not 404
# vr = get_object_or_404(VPVerifyRequest, nonce=nonce) # TODO: return meaningful error, not 404 # # Get a list of all included verifiable credential types
# # Get a list of all included verifiable credential types # included_credential_types = unique_everseen(flatten([
# included_credential_types = unique_everseen(flatten([ # vc["type"] for vc in vp["verifiableCredential"]
# vc["type"] for vc in vp["verifiableCredential"] # ]))
# ])) # # Check that it matches what we requested
# # Check that it matches what we requested # for requested_vc_type in json.loads(vr.expected_credentials):
# for requested_vc_type in json.loads(vr.expected_credentials): # if requested_vc_type not in included_credential_types:
# if requested_vc_type not in included_credential_types: # raise Exception("You're missing some credentials we requested!") # TODO: return meaningful error
# raise Exception("You're missing some credentials we requested!") # TODO: return meaningful error # # Perform whatever action we have to do
# # Perform whatever action we have to do # action = json.loads(vr.action)
# action = json.loads(vr.action) # if action["action"] == "send_mail":
# if action["action"] == "send_mail": # subject = action["params"]["subject"]
# subject = action["params"]["subject"] # to_email = action["params"]["to"]
# to_email = action["params"]["to"] # from_email = "noreply@verifier-portal"
# from_email = "noreply@verifier-portal" # body = request.POST["vp-token"]
# body = request.POST["vp-token"] # send_mail(
# send_mail( # subject,
# subject, # body,
# body, # from_email,
# from_email, # [to_email]
# [to_email] # )
# ) # elif action["action"] == "something-else":
# elif action["action"] == "something-else": # pass
# pass # else:
# else: # raise Exception("Unknown action!")
# raise Exception("Unknown action!") # # OK! Your verifiable presentation was successfully presented.
# # OK! Your verifiable presentation was successfully presented. # return HttpResponseRedirect(vr.response_or_redirect)
# return HttpResponseRedirect(vr.response_or_redirect)