Skip to content

Commit

Permalink
Merge pull request #204 from lalithkota/17.0-develop-disctrict-code
Browse files Browse the repository at this point in the history
Fixed utc Datetimes
  • Loading branch information
shibu-narayanan authored Nov 11, 2024
2 parents a439edd + 658ead3 commit 2d859fc
Show file tree
Hide file tree
Showing 24 changed files with 502 additions and 47 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ addon | version | maintainers | summary
[g2p_odk_importer](g2p_odk_importer/) | 17.0.0.0.0 | | Import records from ODK
[g2p_odk_user_mapping](g2p_odk_user_mapping/) | 17.0.0.0.0 | | ODK App User Mapping
[g2p_openid_vci](g2p_openid_vci/) | 17.0.0.0.0 | | G2P OpenID VCI: Base
[g2p_openid_vci_group](g2p_openid_vci_group/) | 17.0.0.0.0 | | G2P OpenID VCI: Group
[g2p_openid_vci_rest_api](g2p_openid_vci_rest_api/) | 17.0.0.0.0 | | G2P OpenID VCI: Rest API
[g2p_portal_auth](g2p_portal_auth/) | 17.0.0.0.0 | | G2P Portal Auth
[g2p_profile_image](g2p_profile_image/) | 17.0.0.0.0 | | OpenG2P Profile Image
Expand Down
2 changes: 1 addition & 1 deletion g2p_auth_id_oidc/models/g2p_auth_id_oidc_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def oidc_signin_process_phone(self, validation, params, oauth_partner=None, **kw
append = True
if oauth_partner:
for phone_num in oauth_partner.phone_number_ids:
if phone_num == phone: # TODO: Check without country code
if phone_num.phone_no == phone: # TODO: Check without country code
validation.pop("phone")
append = False
break
Expand Down
6 changes: 3 additions & 3 deletions g2p_auth_oidc/models/auth_oauth_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import logging
import secrets
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from urllib.request import urlopen

import requests
Expand Down Expand Up @@ -209,8 +209,8 @@ def oidc_create_private_key_jwt(self):
"iss": self.client_id,
"sub": self.client_id,
"aud": self.jwt_assertion_aud or self.token_endpoint,
"exp": datetime.now(timezone.utc) + timedelta(hours=1),
"iat": datetime.now(timezone.utc),
"exp": datetime.now() + timedelta(hours=1),
"iat": datetime.now(),
},
secret,
algorithm="RS256",
Expand Down
6 changes: 3 additions & 3 deletions g2p_encryption_keymanager/models/encryption_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import os
import secrets
from datetime import datetime, timezone
from datetime import datetime

import requests
from cryptography import x509
Expand Down Expand Up @@ -39,7 +39,7 @@ def _km_random_secret(self):

@api.model
def km_generate_current_time(self):
return f'{datetime.now(timezone.utc).isoformat(timespec = "milliseconds")}Z'
return f'{datetime.now().isoformat(timespec = "milliseconds")}Z'

keymanager_api_base_url = fields.Char("Keymanager API Base URL", default=KEYMANAGER_API_BASE_URL)
keymanager_api_timeout = fields.Integer("Keymanager API Timeout", default=10)
Expand Down Expand Up @@ -261,7 +261,7 @@ def km_get_access_token(self):
if (
self.keymanager_access_token
and self.keymanager_access_token_expiry
and self.keymanager_access_token_expiry > datetime.now(timezone.utc)
and self.keymanager_access_token_expiry > datetime.now()
):
return self.keymanager_access_token
data = {
Expand Down
15 changes: 4 additions & 11 deletions g2p_openid_vci/data/default_contexts.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@
"@type": "@id",
"@context": {
"@vocab": "https://openg2p.org/credential#OpenG2PRegistryVerifiableCredential#credentialSubject#",
"name": {
"@id": "name",
"@type": "@id",
"@context": {
"value": "@value",
"language": "@language"
}
},
"fullName": {
"@id": "fullName",
"@type": "@id",
Expand Down Expand Up @@ -62,8 +54,8 @@
"language": "@language"
}
},
"province": {
"@id": "province",
"locality": {
"@id": "locality",
"@type": "@id",
"@context": {
"value": "@value",
Expand All @@ -81,7 +73,8 @@
"postalCode": "postalCode",
"face": "face",
"vcVer": "vcVer",
"UIN": "UIN"
"UIN": "UIN",
"nationalID": "nationalID"
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions g2p_openid_vci/data/default_credential_format.jq
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
"credentialSubject": {
"vcVer": "VC-V1",
"id": (.web_base_url + "/api/v1/registry/individual/" + (.partner.id | tostring)),
"name": [
{
"language": "eng",
"value": (.partner.name // null)
}
],
"fullName": [
{
"language": "eng",
Expand All @@ -37,7 +31,7 @@
"value": .partner_address.street_address
}
] else null end),
"province": (if .partner_address.locality then [
"locality": (if .partner_address.locality then [
{
"language": "eng",
"value": .partner_address.locality
Expand All @@ -51,6 +45,10 @@
] else null end),
"postalCode": .partner_address.postal_code,
"face": .partner_face,
"UIN": .reg_ids["NATIONAL ID"]?.value
"nationalID": (.reg_ids["NATIONAL ID"]?.value // null),
"UIN": (.partner.ref_id? // (
(.reg_ids["NATIONAL ID"]?.value[0:5] | explode | reverse | implode)
+ (.reg_ids["NATIONAL ID"]?.value[6:10] | explode | reverse| implode)
))
}
}
34 changes: 27 additions & 7 deletions g2p_openid_vci/data/default_issuer_metadata.jq
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,42 @@
}
]
},
"dateOfBirth": {
"dateOfBirth": {
"display": [
{
"name": "Date of Birth",
"locale": "en"
}
]
},
"address": {
"addressLine1": {
"display": [
{
"name": "Address",
"name": "Address Line 1",
"locale": "en"
}
]
},
"locality": {
"display": [
{
"name": "Locality",
"locale": "en"
}
]
},
"region": {
"display": [
{
"name": "region",
"locale": "en"
}
]
},
"UIN": {
"display": [
{
"name": "Beneficiary ID",
"name": "Registrant ID",
"locale": "en"
}
]
Expand All @@ -76,14 +92,18 @@
"url": (.web_base_url + "/g2p_openid_vci/static/description/icon.png"),
"alt_text": "a square logo of a OpenG2P"
},
"background_color": "#12107c",
"text_color": "#FFFFFF"
"background_color": "#13b9cf",
"text_color": "#19234f"
}
],
"order": [
"fullName",
"UIN",
"gender",
"dateOfBirth"
"dateOfBirth",
"addressLine1",
"locality",
"region"
]
}
]
6 changes: 3 additions & 3 deletions g2p_openid_vci/models/vci_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
import uuid
from datetime import datetime, timezone
from datetime import datetime

import jq
import requests
Expand Down Expand Up @@ -136,7 +136,7 @@ def issue_vc_Registry(self, auth_claims, credential_request):
partner_dict = partner.read()[0]
reg_ids_dict = {reg_id.id_type.name: reg_id.read()[0] for reg_id in partner.reg_ids}

curr_datetime = f'{datetime.now(timezone.utc).isoformat(timespec = "milliseconds")}Z'
curr_datetime = f'{datetime.now().isoformat(timespec = "milliseconds")}Z'
credential = jq.first(
self.credential_format,
VCJSONEncoder.python_dict_to_json_dict(
Expand Down Expand Up @@ -183,7 +183,7 @@ def sign_and_issue_credential(self, credential: dict) -> dict:

def build_empty_ld_proof(self):
self.ensure_one()
curr_datetime = f'{datetime.now(timezone.utc).isoformat(timespec = "milliseconds")}Z'
curr_datetime = f'{datetime.now().isoformat(timespec = "milliseconds")}Z'
web_base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url").rstrip("/")
# TODO: Remove this hardcoding
return {
Expand Down
14 changes: 7 additions & 7 deletions g2p_openid_vci/tests/test_openid_vc_issuer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import base64
import os
from datetime import datetime, timezone
from datetime import datetime
from unittest.mock import MagicMock, patch

import requests
Expand Down Expand Up @@ -67,7 +67,7 @@ def setUp(self):
"iss": "http://openg2p.local/auth",
"aud": "http://openg2p.local/api/v1/vci/credential",
"sub": self.registrant_national_id,
"exp": int(datetime.now(timezone.utc).timestamp()) + 5 * 60,
"exp": int(datetime.now().timestamp()) + 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_issue_vc_normal(self, mock_jwt_sign, mock_request):
cred_subject = cred["credentialSubject"]

self.assertTrue("OpenG2PRegistryVerifiableCredential" in cred["type"])
self.assertTrue("Givenname Familyname" in [name["value"] for name in cred_subject["name"]])
self.assertTrue("Givenname Familyname" in [name["value"] for name in cred_subject["fullName"]])
self.assertTrue(not cred_subject["email"])
self.assertTrue(not cred_subject["phone"])
self.assertTrue(not cred_subject["addressLine1"])
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_issue_vc_no_scope(self):
"iss": "http://openg2p.local/auth",
"aud": "http://openg2p.local/api/v1/vci/credential",
"sub": self.registrant_national_id,
"exp": int(datetime.now(timezone.utc).timestamp()) + 5 * 60,
"exp": int(datetime.now().timestamp()) + 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand All @@ -164,7 +164,7 @@ def test_issue_vc_invalid_id(self, mock_request):
"iss": "http://openg2p.local/auth",
"aud": "http://openg2p.local/api/v1/vci/credential",
"sub": "random-value",
"exp": int(datetime.now(timezone.utc).timestamp()) + 5 * 60,
"exp": int(datetime.now().timestamp()) + 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand All @@ -187,7 +187,7 @@ def test_issue_vc_check_audience(self, mock_request):
"iss": "http://openg2p.local/auth",
"aud": ["http://random.url/credential"],
"sub": self.registrant_national_id,
"exp": int(datetime.now(timezone.utc).timestamp()) + 5 * 60,
"exp": int(datetime.now().timestamp()) + 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand All @@ -207,7 +207,7 @@ def test_issue_vc_auth_expired(self, mock_request):
"iss": "http://openg2p.local/auth",
"aud": "http://openg2p.local/api/v1/vci/credential",
"sub": self.registrant_national_id,
"exp": int(datetime.now(timezone.utc).timestamp()) - 5 * 60,
"exp": int(datetime.now().timestamp()) - 5 * 60,
},
self.jwk,
algorithm="RS256",
Expand Down
5 changes: 5 additions & 0 deletions g2p_openid_vci_group/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# G2P OpenID VCI: Group

OpenG2P Group OpenID for Verifiable Credential Issuance

Refer to https://docs.openg2p.org.
1 change: 1 addition & 0 deletions g2p_openid_vci_group/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
24 changes: 24 additions & 0 deletions g2p_openid_vci_group/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Part of OpenG2P. See LICENSE file for full copyright and licensing details.
{
"name": "G2P OpenID VCI: Group",
"category": "G2P",
"version": "17.0.0.0.0",
"sequence": 1,
"author": "OpenG2P",
"website": "https://openg2p.org",
"license": "LGPL-3",
"depends": [
"g2p_registry_membership",
"g2p_openid_vci",
],
"data": [],
"assets": {
"web.assets_backend": [],
"web.assets_qweb": [],
},
"demo": [],
"images": [],
"application": False,
"installable": True,
"auto_install": False,
}
Loading

0 comments on commit 2d859fc

Please sign in to comment.