From 8234449ec3e9abd11b75743c45a1208f56378ff4 Mon Sep 17 00:00:00 2001 From: Christian Kollmann Date: Thu, 14 Nov 2024 21:35:53 +0100 Subject: [PATCH] Extract more constants --- .../kotlin/at/asitplus/openid/OpenIdConstants.kt | 7 +++++++ .../wallet/lib/ktor/openid/OpenId4VciClient.kt | 13 +++++++------ .../wallet/lib/ktor/openid/OpenId4VpWallet.kt | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/openid-data-classes/src/commonMain/kotlin/at/asitplus/openid/OpenIdConstants.kt b/openid-data-classes/src/commonMain/kotlin/at/asitplus/openid/OpenIdConstants.kt index 6552f150..224c0662 100644 --- a/openid-data-classes/src/commonMain/kotlin/at/asitplus/openid/OpenIdConstants.kt +++ b/openid-data-classes/src/commonMain/kotlin/at/asitplus/openid/OpenIdConstants.kt @@ -24,6 +24,8 @@ object OpenIdConstants { const val TOKEN_TYPE_BEARER = "bearer" + const val TOKEN_TYPE_DPOP = "dpop" + const val URN_TYPE_JWK_THUMBPRINT = "urn:ietf:params:oauth:jwk-thumbprint" const val BINDING_METHOD_COSE_KEY = "cose_key" @@ -51,6 +53,11 @@ object OpenIdConstants { const val AUTH_METHOD_ATTEST_JWT_CLIENT_AUTH = "attest_jwt_client_auth" + const val PARAMETER_PROMPT = "prompt" + + const val PARAMETER_PROMPT_LOGIN = "login" + + @Serializable(with = ProofType.Serializer::class) sealed class ProofType(val stringRepresentation: String) { override fun toString(): String = this::class.simpleName + "(" + stringRepresentation + ")" diff --git a/vck-openid-ktor/src/commonMain/kotlin/at/asitplus/wallet/lib/ktor/openid/OpenId4VciClient.kt b/vck-openid-ktor/src/commonMain/kotlin/at/asitplus/wallet/lib/ktor/openid/OpenId4VciClient.kt index 44295900..f5b139df 100644 --- a/vck-openid-ktor/src/commonMain/kotlin/at/asitplus/wallet/lib/ktor/openid/OpenId4VciClient.kt +++ b/vck-openid-ktor/src/commonMain/kotlin/at/asitplus/wallet/lib/ktor/openid/OpenId4VciClient.kt @@ -4,6 +4,9 @@ import at.asitplus.jsonpath.core.NormalizedJsonPath import at.asitplus.jsonpath.core.NormalizedJsonPathSegment import at.asitplus.openid.* import at.asitplus.openid.OpenIdConstants.AUTH_METHOD_ATTEST_JWT_CLIENT_AUTH +import at.asitplus.openid.OpenIdConstants.PARAMETER_PROMPT +import at.asitplus.openid.OpenIdConstants.PARAMETER_PROMPT_LOGIN +import at.asitplus.openid.OpenIdConstants.TOKEN_TYPE_DPOP import at.asitplus.signum.indispensable.josef.JsonWebAlgorithm import at.asitplus.wallet.lib.agent.CryptoService import at.asitplus.wallet.lib.agent.Holder @@ -38,8 +41,6 @@ import kotlinx.serialization.json.Json import kotlin.time.Duration.Companion.minutes - - /** * Implements the client side of [OpenID for Verifiable Credential Issuance - draft 14](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html). * @@ -105,7 +106,7 @@ class OpenId4VciClient( } } } - private val oid4vciService = WalletService( + val oid4vciService = WalletService( clientId = clientId, cryptoService = cryptoService, redirectUrl = redirectUrl @@ -305,7 +306,7 @@ class OpenId4VciClient( credentialIssuer = credentialIssuer, ).getOrThrow() - val dpopHeader = if (tokenResponse.tokenType.lowercase() == "dpop") + val dpopHeader = if (tokenResponse.tokenType.equals(TOKEN_TYPE_DPOP, true)) jwsService.buildDPoPHeader(url = credentialEndpointUrl, accessToken = tokenResponse.accessToken) else null @@ -468,7 +469,7 @@ class OpenId4VciClient( authRequest.encodeToParameters().forEach { builder.parameters.append(it.key, it.value) } - builder.parameters.append("prompt", "login") + builder.parameters.append(PARAMETER_PROMPT, PARAMETER_PROMPT_LOGIN) }.build().toString() } Napier.d("Provisioning starts by opening URL $authorizationUrl") @@ -497,7 +498,7 @@ class OpenId4VciClient( url = url, formParameters = parameters { authRequest.encodeToParameters().forEach { append(it.key, it.value) } - append("prompt", "login") + append(PARAMETER_PROMPT, PARAMETER_PROMPT_LOGIN) } ) { headers { diff --git a/vck-openid-ktor/src/commonMain/kotlin/at/asitplus/wallet/lib/ktor/openid/OpenId4VpWallet.kt b/vck-openid-ktor/src/commonMain/kotlin/at/asitplus/wallet/lib/ktor/openid/OpenId4VpWallet.kt index e025b976..49768bff 100644 --- a/vck-openid-ktor/src/commonMain/kotlin/at/asitplus/wallet/lib/ktor/openid/OpenId4VpWallet.kt +++ b/vck-openid-ktor/src/commonMain/kotlin/at/asitplus/wallet/lib/ktor/openid/OpenId4VpWallet.kt @@ -59,7 +59,7 @@ class OpenId4VpWallet( } httpClientConfig?.let { apply(it) } } - private val oidcSiopWallet = OidcSiopWallet( + val oidcSiopWallet = OidcSiopWallet( holder = holderAgent, agentPublicKey = cryptoService.keyMaterial.publicKey, jwsService = DefaultJwsService(cryptoService),