Skip to content

Commit

Permalink
migrate language distinction to the meta field rather than title and …
Browse files Browse the repository at this point in the history
…claims

Signed-off-by: Gavin Jaeger-Freeborn <[email protected]>
  • Loading branch information
Gavinok committed Nov 18, 2024
1 parent 65d2321 commit c16e42f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
16 changes: 10 additions & 6 deletions oidc-controller/api/core/oidc/tests/__mocks__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from datetime import datetime, timedelta

from api.verificationConfigs.models import VerificationConfig, VerificationProofRequest
from api.verificationConfigs.models import (
VerificationConfig,
VerificationProofRequest,
MetaData,
)
from api.authSessions.models import AuthSession

# Presentation returned from the debug webhook
Expand Down Expand Up @@ -1342,13 +1346,13 @@
ver_config_id="verified-email",
subject_identifier="email",
metadata={
"title": {"en": "Get Name"},
"claims": {
"en": [
"en": MetaData(
title="Get Name",
claims=[
"That you are a BC Resident",
"That you are a member of the Law Society of British Columbia",
]
},
],
),
},
proof_request=VerificationProofRequest(
name="BCGov Verified Email",
Expand Down
22 changes: 8 additions & 14 deletions oidc-controller/api/routers/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

from ..verificationConfigs.crud import VerificationConfigCRUD
from ..verificationConfigs.helpers import VariableSubstitutionError
from ..verificationConfigs.models import MetaData


ChallengePollUri = "/poll"
Expand Down Expand Up @@ -202,6 +203,11 @@ async def get_authorize(request: Request, db: Database = Depends(get_db)):
# BC Wallet deep link
wallet_deep_link = gen_deep_link(auth_session)

metadata = (
ver_config.metadata["en"]
if ver_config.metadata and "en" in ver_config.metadata
else MetaData(title="Scan with a Digital Wallet", claims=[])
)
# This is the payload to send to the template
data = {
"image_contents": image_contents,
Expand All @@ -212,20 +218,8 @@ async def get_authorize(request: Request, db: Database = Depends(get_db)):
"controller_host": controller_host,
"challenge_poll_uri": ChallengePollUri,
"wallet_deep_link": wallet_deep_link,
"title": (
ver_config.metadata.title.get("en")
if ver_config.metadata
and ver_config.metadata.title
and ver_config.metadata.title.get("en")
else "Scan with a Digital Wallet"
),
"claims": (
ver_config.metadata.claims.get("en")
if ver_config.metadata
and ver_config.metadata.claims
and ver_config.metadata.claims.get("en")
else []
),
"title": metadata.title,
"claims": metadata.claims,
}

# Prepare the template
Expand Down
6 changes: 3 additions & 3 deletions oidc-controller/api/verificationConfigs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ class VerificationProofRequest(BaseModel):


class MetaData(BaseModel):
title: dict[str, str] | None = Field(default=None)
claims: dict[str, list[str]] | None = Field(default=None)
title: str | None = Field(default=None)
claims: list[str] | None = Field(default=None)


class VerificationConfigBase(BaseModel):
subject_identifier: str = Field()
proof_request: VerificationProofRequest = Field()
generate_consistent_identifier: bool | None = Field(default=False)
include_v1_attributes: bool | None = Field(default=False)
metadata: MetaData | None = Field(default=None)
metadata: dict[str, MetaData] | None = Field(default=None)

def get_now(self) -> int:
return int(time.time())
Expand Down

0 comments on commit c16e42f

Please sign in to comment.