Skip to content

Commit

Permalink
Merge pull request #852 from walt-id/issuance_status_cb_fix
Browse files Browse the repository at this point in the history
restore issuance status callbacks that got lost during refactoring
  • Loading branch information
philpotisk authored Dec 10, 2024
2 parents 66e2030 + b3e1e96 commit 183ff59
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*

class IssuerApi(private val client: HttpClient) {
class IssuerApi(private val client: HttpClient, private val cbUrl: String? = null) {
suspend fun jwt(request: IssuanceRequest, output: ((String) -> Unit)? = null) = issue(
name = "/openid4vc/jwt/issue - issue jwt credential",
url = "/openid4vc/jwt/issue",
Expand Down Expand Up @@ -47,6 +47,9 @@ class IssuerApi(private val client: HttpClient) {
private suspend fun issue(name: String, url: String, request: IssuanceRequest, output: ((String) -> Unit)? = null) =
test(name) {
client.post(url) {
if(!cbUrl.isNullOrEmpty()) {
header("statusCallbackUri", cbUrl)
}
setBody(request)
}.expectSuccess().apply {
output?.invoke(body<String>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ class WaltidServicesE2ETests {

//region -Issuer / offer url-
lateinit var offerUrl: String
val issuerApi = IssuerApi(client)
val issuerApi = IssuerApi(client,
// uncomment the following line, to test status callbacks, update webhook id as required.
// "https://webhook.site/d879094b-2275-4ae7-b1c5-ebfb9f08dfdb"
)
val issuanceRequest = Json.decodeFromJsonElement<IssuanceRequest>(jwtCredential)
println("issuance-request:")
println(issuanceRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ open class CIProvider(
val baseUrl: String = let { ConfigManager.getConfig<OIDCIssuerServiceConfig>().baseUrl },
val config: CredentialIssuerConfig = CredentialIssuerConfig(credentialConfigurationsSupported = ConfigManager.getConfig<CredentialTypeConfig>().parse())
) {
private val log = KotlinLogging.logger { }
val metadata
get() = OpenID4VCI.createDefaultProviderMetadata(baseUrl).copy(
credentialConfigurationsSupported = config.credentialConfigurationsSupported
)

companion object {

private val log = KotlinLogging.logger { }
private val http = HttpClient() {
install(ContentNegotiation) {
json()
Expand All @@ -93,13 +92,14 @@ open class CIProvider(

suspend fun sendCallback(sessionId: String, type: String, data: JsonObject, callbackUrl: String) {
try {
http.post(callbackUrl.replace("\$id", sessionId)) {
val response = http.post(callbackUrl.replace("\$id", sessionId)) {
setBody(buildJsonObject {
put("id", sessionId)
put("type", type)
put("data", data)
})
}
log.trace { "Sent issuance status callback: $callbackUrl, $type, $sessionId; respone: ${response.status}" }
} catch (ex: Exception) {
throw IllegalArgumentException("Error sending HTTP POST request to issuer callback url.", ex)
}
Expand Down Expand Up @@ -235,7 +235,10 @@ open class CIProvider(
issuerKey = resolvedIssuerKey,
selectiveDisclosure = request.selectiveDisclosure,
dataMapping = request.mapping,
x5Chain = request.x5Chain)
x5Chain = request.x5Chain).also {
if(!issuanceSession.callbackUrl.isNullOrEmpty())
sendCallback(issuanceSession.id, "sdjwt_issue", buildJsonObject { put("sdjwt", it) }, issuanceSession.callbackUrl)
}
else -> OpenID4VCI.generateW3CJwtVC(
credentialRequest = credentialRequest,
credentialData = vc,
Expand All @@ -245,7 +248,10 @@ open class CIProvider(
selectiveDisclosure = request.selectiveDisclosure,
dataMapping = request.mapping,
x5Chain = request.x5Chain
)
).also {
if(!issuanceSession.callbackUrl.isNullOrEmpty())
sendCallback(issuanceSession.id, "jwt_issue", buildJsonObject { put("jwt", it) }, issuanceSession.callbackUrl)
}
}
}.also { log.debug { "Respond VC: $it" } }
}))
Expand Down Expand Up @@ -577,6 +583,11 @@ open class CIProvider(
cNonce = generateProofOfPossessionNonceFor(session).cNonce,
cNonceExpiresIn = session.expirationTimestamp - Clock.System.now(),
state = session.authorizationRequest?.state
)
).also {
if(!session.callbackUrl.isNullOrEmpty())
sendCallback(sessionId, "requested_token", buildJsonObject {
put("request", Json.encodeToJsonElement(session.issuanceRequests.first()))
}, session.callbackUrl)
}
}
}

0 comments on commit 183ff59

Please sign in to comment.