Skip to content

Commit

Permalink
add human readable metadata to ver config to for use with QR
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Jaeger-Freeborn <[email protected]>
  • Loading branch information
Gavinok committed Nov 8, 2024
1 parent ec1ee82 commit 30f19c7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
7 changes: 7 additions & 0 deletions oidc-controller/api/core/oidc/tests/__mocks__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,13 @@
ver_config = VerificationConfig(
ver_config_id="verified-email",
subject_identifier="email",
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",
version="1.0",
Expand Down
6 changes: 6 additions & 0 deletions oidc-controller/api/routers/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ 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
if ver_config.metadata
else "Scan with a Digital Wallet"
),
"claims": (ver_config.metadata.claims if ver_config.metadata else []),
}

# Prepare the template
Expand Down
39 changes: 33 additions & 6 deletions oidc-controller/api/templates/verified_credentials.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
<main class="container flex-fill mt-4 text-center">
<div v-if="!mobileDevice" class="desktop-head">
<a v-if="backToUrl" :href="backToUrl" class="back-btn"
>&#129144; Go back
>&#129144; Go back
</a>
<h1 class="mb-3">Scan with a Digital Wallet</h1>
<h1 class="mb-3">{{title}}</h1>
</div>
<div v-if="!mobileDevice" class="ml-12" >
<display-claims :claims="claims"/>
</div>
<div class="row">
<div
Expand All @@ -35,9 +38,11 @@ <h1 class="mb-3">Scan with a Digital Wallet</h1>
>
<div v-if="mobileDevice" class="text-start">
<a v-if="backToUrl" :href="backToUrl" class="back-btn"
>&#129144; Go back
>&#129144; Go back
</a>
<h1 class="mb-3 fw-bolder fs-1">Continue with:</h1>
<display-claims :claims="claims"/>

</div>
<status-description
key="state.current"
Expand Down Expand Up @@ -117,12 +122,13 @@ <h1 class="mb-3 fw-bolder fs-1">Continue with:</h1>
<a
title="Download BC Wallet"
href="https://www2.gov.bc.ca/gov/content/governments/government-id/bc-wallet"
>Download the BC Wallet app
>Download the BC Wallet app
</a>
</p>
</div>
</div>
</div>
</div>
</main>

<footer>
Expand Down Expand Up @@ -188,6 +194,17 @@ <h1 class="mb-3 fw-bolder fs-1">Continue with:</h1>
</div>
</script>

<script type="text/x-template" id="display-claims">
<div v-if="claims.length > 0" class="text-start flex-none">
The proof request will ask you to prove the following:
<ul>
<li v-for="claim in claims">
[[claim]]
</li>
</ul>
</div>
</script>

<script type="text/x-template" id="qr-code">
<div class="qr-code-container mb-3">
<button
Expand Down Expand Up @@ -270,7 +287,6 @@ <h5 v-if="state.showScanned" class="fw-bolder mb-3">

<script type="text/javascript">
const { createApp, ref, reactive, computed, watch } = Vue;

/**
* @typedef {"intro" |"verified" | "failed" | "pending"| "expired" |"abandoned"} AppStates
*/
Expand Down Expand Up @@ -307,9 +323,11 @@ <h5 v-if="state.showScanned" class="fw-bolder mb-3">
const mobileDevice = ref(
getBrowser() === "Android" || getBrowser() === "iOS" ? true : false
);
const claims = ref(JSON.parse('{{claims|tojson}}'));

return {
mobileDevice,
claims,
state,
displayQr: mobileDevice.value ? false : true,
bcIdClicks: 0,
Expand Down Expand Up @@ -504,7 +522,16 @@ <h5 v-if="state.showScanned" class="fw-bolder mb-3">
},
},
});
app.component("qr-code", {
app.component("display-claims", {
template: `#display-claims`,
props: {
claims: {
required: true,
},
},
delimiters: ["[[", "]]"],
});
app.component("qr-code", {
template: `#qr-code`,
props: {
state: {
Expand Down
7 changes: 7 additions & 0 deletions oidc-controller/api/verificationConfigs/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
from typing_extensions import TypedDict
from pydantic import BaseModel, ConfigDict, Field

from .examples import ex_ver_config
Expand Down Expand Up @@ -38,11 +39,17 @@ class VerificationProofRequest(BaseModel):
requested_predicates: list[ReqPred]


class MetaData(BaseModel):
title: str = Field()
claims: list[str] = Field()


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)

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

0 comments on commit 30f19c7

Please sign in to comment.