Skip to content

Commit

Permalink
Add Option for Custom OpenID4VP Scheme to Verifier
Browse files Browse the repository at this point in the history
Added additional protocol - OpenID4VP (Custom URI scheme) -
to the verifier. When that protocol is selected, there is also
a text box which appears next to the dropdown where the user
can input the custom scheme.

Tested manually by registering the wallet app for a random
scheme and using it in the request.

Signed-off-by: Suzanna Jiwani <[email protected]>
  • Loading branch information
suzannajiwani authored and kdeus committed Nov 21, 2024
1 parent e575a79 commit 3577eae
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ enum class Protocol {
PLAIN_OPENID4VP,
EUDI_OPENID4VP,
MDOC_OPENID4VP,
CUSTOM_OPENID4VP,
}

@Serializable
Expand All @@ -98,7 +99,8 @@ private data class OpenID4VPBeginRequest(
val docType: String,
val requestId: String,
val protocol: String,
val origin: String
val origin: String,
val scheme: String
)

@Serializable
Expand Down Expand Up @@ -578,6 +580,7 @@ lrW+vvdmRHBgS+ss56uWyYor6W7ah9ygBwYFK4EEACI=
"openid4vp_plain" -> Protocol.PLAIN_OPENID4VP
"openid4vp_eudi" -> Protocol.EUDI_OPENID4VP
"openid4vp_mdoc" -> Protocol.MDOC_OPENID4VP
"openid4vp_custom" -> Protocol.CUSTOM_OPENID4VP
else -> {
Logger.w(TAG, "$remoteHost: Unknown protocol '$request.protocol'")
resp.status = HttpServletResponse.SC_BAD_REQUEST
Expand Down Expand Up @@ -766,6 +769,7 @@ lrW+vvdmRHBgS+ss56uWyYor6W7ah9ygBwYFK4EEACI=
"openid4vp_plain" -> Protocol.PLAIN_OPENID4VP
"openid4vp_eudi" -> Protocol.EUDI_OPENID4VP
"openid4vp_mdoc" -> Protocol.MDOC_OPENID4VP
"openid4vp_custom" -> Protocol.CUSTOM_OPENID4VP
else -> {
Logger.w(TAG, "$remoteHost: Unknown protocol '$request.protocol'")
resp.status = HttpServletResponse.SC_BAD_REQUEST
Expand Down Expand Up @@ -797,6 +801,7 @@ lrW+vvdmRHBgS+ss56uWyYor6W7ah9ygBwYFK4EEACI=
Protocol.PLAIN_OPENID4VP -> "openid4vp://"
Protocol.EUDI_OPENID4VP -> "eudi-openid4vp://"
Protocol.MDOC_OPENID4VP -> "mdoc-openid4vp://"
Protocol.CUSTOM_OPENID4VP -> request.scheme
else -> {
Logger.w(TAG, "$remoteHost: Unknown protocol '${session.protocol}'")
resp.status = HttpServletResponse.SC_BAD_REQUEST
Expand Down
10 changes: 8 additions & 2 deletions server/src/main/webapp/verifier.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ <h1 class="text-body-emphasis">Request Digital Documents</h1>

Selected protocol for retrieval:

<div class="">
<div class="d-flex gap-4 flex-wrap">
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle btn-lg" type="button"
<button class="btn btn-secondary dropdown-toggle btn-lg overflow-visible" type="button"
data-bs-toggle="dropdown" aria-expanded="false" id="protocolDropdown">
W3C Digital Credentials API (Preview)
</button>
Expand All @@ -53,8 +53,14 @@ <h1 class="text-body-emphasis">Request Digital Documents</h1>
<li><a class="dropdown-item" value="openid4vp_mdoc" href="#">
OpenID4VP (mdoc-openid4vp:// URI scheme)
</a></li>
<li><button class="dropdown-item" value="openid4vp_custom" href="#">
OpenID4VP (Custom URI scheme)
</button></li>
</ul>
</div>
<div id="scheme-form" class="input-group mb-3 w-25" hidden style="flex-basis: 40%;">
<input class="form-control text-end" type="text" placeholder="custom-uri-scheme" id="scheme-input">
</div>
</div>

</main>
Expand Down
29 changes: 26 additions & 3 deletions server/src/main/webapp/verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ async function onLoad() {
selected === 'w3c_dc_arf' ||
selected === 'openid4vp_plain' ||
selected === 'openid4vp_eudi' ||
selected === 'openid4vp_mdoc') {
selected === 'openid4vp_mdoc' ||
selected === 'openid4vp_custom') {
selectedProtocol = selected
preferredProtocol = selectedProtocol
protocolDropdown.innerHTML = target.innerHTML

const scheme = document.getElementById("scheme-form");
scheme.hidden = selected !== 'openid4vp_custom';
}
})

Expand Down Expand Up @@ -141,7 +145,11 @@ function redirectClose() {

async function requestDocument(format, docType, requestId) {
console.log('requestDocument, format=' + format + ' docType=' + docType + ' requestId=' + requestId + ' protocol=' + selectedProtocol)
if (selectedProtocol.startsWith('openid4vp_')) {
if (selectedProtocol === 'openid4vp_custom') {
if (document.getElementById("scheme-input").value === "") {
alert("You must specify a non-empty scheme when performing a custom OpenID4VP request.")
return
}
const response = await callServer(
'openid4vpBegin',
{
Expand All @@ -150,10 +158,25 @@ async function requestDocument(format, docType, requestId) {
requestId: requestId,
protocol: selectedProtocol,
origin: location.origin,
scheme: document.getElementById("scheme-input").value
}
)
console.log("URI " + response.uri)
window.open(response.uri, '_blank').focus()
} else if (selectedProtocol.startsWith('openid4vp_')) {
const response = await callServer(
'openid4vpBegin',
{
format: format,
docType: docType,
requestId: requestId,
protocol: selectedProtocol,
origin: location.origin,
scheme: ""
}
)
console.log("URI " + response.uri)
window.open(response.uri, '_blank').focus()
} else if (selectedProtocol === "w3c_dc_preview") {
try {
const response = await callServer(
Expand Down Expand Up @@ -247,4 +270,4 @@ async function callServer(command, params) {
}
)
return await response.json()
}
}

0 comments on commit 3577eae

Please sign in to comment.