From 4a3cf5c5df86be6b662d369bb83738392e20683d Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 29 Nov 2023 10:54:05 +0100 Subject: [PATCH] fix models --- oidc4vp/migrations/0001_initial.py | 34 +++++++++++++++++++++++++++++- oidc4vp/models.py | 27 ++++++++++++++++++------ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/oidc4vp/migrations/0001_initial.py b/oidc4vp/migrations/0001_initial.py index c88d0f8..917553d 100644 --- a/oidc4vp/migrations/0001_initial.py +++ b/oidc4vp/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.5 on 2023-11-24 17:10 +# Generated by Django 4.2.5 on 2023-11-29 09:52 from django.conf import settings from django.db import migrations, models @@ -59,6 +59,18 @@ class Migration(migrations.Migration): default=oidc4vp.models.set_client_secret, max_length=48 ), ), + ( + 'my_client_id', + models.CharField( + default=oidc4vp.models.set_client_id, max_length=24, unique=True + ), + ), + ( + 'my_client_secret', + models.CharField( + default=oidc4vp.models.set_client_secret, max_length=48 + ), + ), ( 'response_uri', models.URLField( @@ -68,6 +80,26 @@ class Migration(migrations.Migration): ), ], ), + migrations.CreateModel( + name='VPVerifyRequest', + fields=[ + ( + 'id', + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name='ID', + ), + ), + ('nonce', models.CharField(max_length=50)), + ('expected_credentials', models.CharField(max_length=255)), + ('expected_contents', models.TextField()), + ('action', models.TextField()), + ('response_or_redirect', models.CharField(max_length=255)), + ('submitted_on', models.DateTimeField(auto_now=True)), + ], + ), migrations.CreateModel( name='OAuth2VPToken', fields=[ diff --git a/oidc4vp/models.py b/oidc4vp/models.py index 83cdef1..3a711bf 100644 --- a/oidc4vp/models.py +++ b/oidc4vp/models.py @@ -33,7 +33,14 @@ def set_code(): class Organization(models.Model): """ - This class represent a member of one net trust or federated host + This class represent a member of one net trust or federated host. + Client_id and client_secret are the credentials of this organization + get a connection to my. (receive a request) + My_client_id and my_client_secret are my credentials than to use if I + want to connect to this organization. (send a request) + For use the packages requests we need use my_client_id + For use in the get or post method of a View, then we need use client_id + and secret_id """ name = models.CharField(max_length=250) client_id = models.CharField( @@ -45,6 +52,15 @@ class Organization(models.Model): max_length=48, default=set_client_secret ) + my_client_id = models.CharField( + max_length=24, + default=set_client_id, + unique=True + ) + my_client_secret = models.CharField( + max_length=48, + default=set_client_secret + ) response_uri = models.URLField( help_text=_("Url where to send the verificable presentation"), max_length=250 @@ -54,11 +70,8 @@ class Organization(models.Model): """ Send the verificable presentation to Verifier """ - org = self.__class__.objects.get( - response_uri=settings.RESPONSE_URI - ) - auth = (org.client_id, org.client_secret) - return requests.post(self.url, data=vp, auth=auth) + auth = (self.my_client_id, self.client_secret) + return requests.post(self.response_uri, data=vp, auth=auth) def demand_authorization(self): """ @@ -72,7 +85,7 @@ class Organization(models.Model): url=self.response_uri.strip("/"), redirect_uri=settings.RESPONSE_URI ) - auth = (org.client_id, org.client_secret) + auth = (self.my_client_id, self.client_secret) return requests.get(url, auth=auth) def __str__(self):