diff --git a/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt b/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt index 1b1efca..6bf8012 100644 --- a/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt +++ b/src/main/kotlin/id/walt/service/SSIKit2WalletService.kt @@ -161,6 +161,12 @@ class SSIKit2WalletService(accountId: UUID) : WalletService(accountId) { followRedirects = false } + + data class PresentationError( + override val message: String, + val redirectUri: String? + ) : IllegalArgumentException(message) + /** * @return redirect uri */ @@ -178,15 +184,33 @@ class SSIKit2WalletService(accountId: UUID) : WalletService(accountId) { entry.value.forEach { append(entry.key, it) } } }) - println("HTTP Response: $resp, body: ${resp.bodyAsText()}") + val httpResponseBody = runCatching { resp.bodyAsText() }.getOrNull() + val isResponseRedirectUrl = + httpResponseBody != null && httpResponseBody.take(8).lowercase().let { + @Suppress("HttpUrlsUsage") + it.startsWith("http://") || it.startsWith("https://") + } + println("HTTP Response: $resp, body: $httpResponseBody") return if (resp.status.isSuccess()) { - val redirectUri = resp.bodyAsText() - if (redirectUri.startsWith("http")) - Result.success(redirectUri) - else Result.success(null) + Result.success(if (isResponseRedirectUrl) httpResponseBody else null) } else { - Result.failure(IllegalStateException("https://error.org/")) + if (isResponseRedirectUrl) { + Result.failure( + PresentationError( + message = "Presentation failed - redirecting to error page", + redirectUri = httpResponseBody + ) + ) + } else { + println("Response body: $httpResponseBody") + Result.failure( + PresentationError( + message = if (httpResponseBody != null) "Presentation failed:\n $httpResponseBody" else "Presentation failed", + redirectUri = "" + ) + ) + } } } diff --git a/src/main/kotlin/id/walt/web/controllers/ExchangeController.kt b/src/main/kotlin/id/walt/web/controllers/ExchangeController.kt index 0a4c9f2..5a91744 100644 --- a/src/main/kotlin/id/walt/web/controllers/ExchangeController.kt +++ b/src/main/kotlin/id/walt/web/controllers/ExchangeController.kt @@ -1,5 +1,6 @@ package id.walt.web.controllers +import id.walt.service.SSIKit2WalletService import id.walt.service.dto.WalletOperationHistory import id.walt.web.getWalletService import io.github.smiley4.ktorswaggerui.dsl.post @@ -62,6 +63,12 @@ fun Application.exchange() = walletRoute { description = """{"redirectUri": String}""" } } + HttpStatusCode.BadRequest to { + description = "Presentation was not accepted" + body { + description = """{"redirectUri": String?, "errorMessage": String}""" + } + } } }) { val wallet = getWalletService() @@ -79,20 +86,43 @@ fun Application.exchange() = walletRoute { wallet.addOperationHistory( WalletOperationHistory.new( wallet, "usePresentationRequest", - mapOf("did" to did, "request" to request, "success" to "true", "redirect" to result.getOrThrow()) // change string true to bool + mapOf( + "did" to did, + "request" to request, + "success" to "true", + "redirect" to result.getOrThrow() + ) // change string true to bool ) ) context.respond(HttpStatusCode.OK, mapOf("redirectUri" to result.getOrThrow())) } else { + val err = result.exceptionOrNull() + println("Presentation failed: $err") + wallet.addOperationHistory( WalletOperationHistory.new( wallet, "usePresentationRequest", - mapOf("did" to did, "request" to request, "success" to "false", "redirect" to result.getOrThrow()) // change string true to bool + mapOf( + "did" to did, + "request" to request, + "success" to "false", + //"redirect" to "" + ) // change string false to bool ) ) + when (err) { + is SSIKit2WalletService.PresentationError -> { + context.respond( + HttpStatusCode.BadRequest, mapOf( + "redirectUri" to err.redirectUri, + "errorMessage" to err.message + ) + ) + } - context.respond(HttpStatusCode.BadRequest, mapOf("redirectUri" to result.exceptionOrNull()!!.message)) + else -> context.respond(HttpStatusCode.BadRequest, mapOf("errorMessage" to err?.message)) + } } } post("resolvePresentationRequest", { diff --git a/web/src/pages/credentials/[credentialId].vue b/web/src/pages/credentials/[credentialId].vue index 70c2841..3b3a854 100644 --- a/web/src/pages/credentials/[credentialId].vue +++ b/web/src/pages/credentials/[credentialId].vue @@ -258,7 +258,7 @@
DID
- {{ jwtJson.vc.issuer.id ? jwtJson.vc.issuer.id : jwtJson.vc.issuer }} + {{ jwtJson.vc?.issuer?.id ?? jwtJson.vc.issuer }}

diff --git a/web/src/pages/exchange/presentation.vue b/web/src/pages/exchange/presentation.vue index b4e5620..308db98 100644 --- a/web/src/pages/exchange/presentation.vue +++ b/web/src/pages/exchange/presentation.vue @@ -10,14 +10,19 @@ @@ -32,15 +37,18 @@
+ class="sticky top-0 z-10 border-y border-b-gray-200 border-t-gray-100 bg-gray-50 px-3 py-1.5 text-sm font-semibold leading-6 text-gray-900" + >

{{ group }}s:

  • + class="flex gap-x-4 px-3 py-5" + > + class="h-6 w-6 flex-none rounded-full bg-gray-50" + >
    {{ credential.id }}. @@ -56,18 +64,18 @@