From 9ea9b435bdb7407a3b4a94ab60c8e2a88a038be3 Mon Sep 17 00:00:00 2001 From: "Josep Milan K.A" Date: Fri, 30 Aug 2024 13:02:17 +0530 Subject: [PATCH] Fix #52 - Support for client metadata during verification --- .../models/ClientMetaData.kt | 2 +- .../models/PresentationRequest.kt | 12 ++++- .../services/issue/IssueService.kt | 6 +-- .../verification/VerificationService.kt | 47 ++++++++++++++++--- 4 files changed, 55 insertions(+), 12 deletions(-) diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/ClientMetaData.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/ClientMetaData.kt index 47ef5da..17ad31d 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/ClientMetaData.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/ClientMetaData.kt @@ -2,7 +2,7 @@ package com.ewc.eudi_wallet_oidc_android.models import com.google.gson.annotations.SerializedName -data class ClientMetaData( +data class ClientMetaDataas( @SerializedName("vp_formats_supported") var vpFormatsSupported: VpFormatsSupported? = VpFormatsSupported( jwtVp = Jwt(arrayListOf("ES256")), jwtVc = Jwt(arrayListOf("ES256")) diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/PresentationRequest.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/PresentationRequest.kt index a6221f4..01c4994 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/PresentationRequest.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/PresentationRequest.kt @@ -2,6 +2,13 @@ package com.ewc.eudi_wallet_oidc_android.models import com.google.gson.annotations.SerializedName +data class ClientMetaDetails( + @SerializedName("client_name") var clientName: String? = null, + @SerializedName("cover_uri") var coverUri: String? = null, + @SerializedName("description") var description: String? = null, + @SerializedName("location") var location: String? = null, + @SerializedName("logo_uri") var logoUri: String? = null +) data class PresentationRequest( @SerializedName("state") var state: String? = null, @SerializedName("client_id") var clientId: String? = null, @@ -12,5 +19,6 @@ data class PresentationRequest( @SerializedName("nonce") var nonce: String? = null, @SerializedName("request_uri") var requestUri: String? = null, @SerializedName("response_uri") var responseUri: String? = null, - @SerializedName("presentation_definition") var presentationDefinition: Any? = null -) + @SerializedName("presentation_definition") var presentationDefinition: Any? = null, + @SerializedName("client_metadata") var clientMetaDetails: ClientMetaDetails? = null +) \ No newline at end of file diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueService.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueService.kt index c12792a..e0e224f 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueService.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueService.kt @@ -3,7 +3,7 @@ package com.ewc.eudi_wallet_oidc_android.services.issue import android.net.Uri import android.util.Log import com.ewc.eudi_wallet_oidc_android.models.AuthorizationDetails -import com.ewc.eudi_wallet_oidc_android.models.ClientMetaData +import com.ewc.eudi_wallet_oidc_android.models.ClientMetaDataas import com.ewc.eudi_wallet_oidc_android.models.CredentialDefinition import com.ewc.eudi_wallet_oidc_android.models.CredentialOffer import com.ewc.eudi_wallet_oidc_android.models.CredentialOfferV1 @@ -104,7 +104,7 @@ class IssueService : IssueServiceInterface { val codeChallenge = CodeVerifierService().generateCodeChallenge(codeVerifier) val codeChallengeMethod = "S256" val clientMetadata = Gson().toJson( - ClientMetaData( + ClientMetaDataas( vpFormatsSupported = VpFormatsSupported( jwtVp = Jwt(arrayListOf("ES256")), jwtVc = Jwt(arrayListOf("ES256")) ), responseTypesSupported = arrayListOf( @@ -178,7 +178,7 @@ class IssueService : IssueServiceInterface { val codeChallenge = CodeVerifierService().generateCodeChallenge(codeVerifier) val codeChallengeMethod = "S256" val clientMetadata = Gson().toJson( - ClientMetaData( + ClientMetaDataas( vpFormatsSupported = VpFormatsSupported( jwtVp = Jwt(arrayListOf("ES256")), jwtVc = Jwt(arrayListOf("ES256")) ), responseTypesSupported = arrayListOf( diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/verification/VerificationService.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/verification/VerificationService.kt index 8e8ace2..afff03c 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/verification/VerificationService.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/verification/VerificationService.kt @@ -2,6 +2,7 @@ package com.ewc.eudi_wallet_oidc_android.services.verification import android.net.Uri import android.util.Base64 +import com.ewc.eudi_wallet_oidc_android.models.ClientMetaDetails import com.ewc.eudi_wallet_oidc_android.models.DescriptorMap import com.ewc.eudi_wallet_oidc_android.models.ErrorResponse import com.ewc.eudi_wallet_oidc_android.models.PathNested @@ -63,6 +64,13 @@ class VerificationService : VerificationServiceInterface { val requestUri = Uri.parse(data).getQueryParameter("request_uri") val responseUri = Uri.parse(data).getQueryParameter("response_uri") val responseMode = Uri.parse(data).getQueryParameter("response_mode") + val clientMetadataJson = Uri.parse(data).getQueryParameter("client_metadata") + + val clientMetadetails: ClientMetaDetails? = if (!clientMetadataJson.isNullOrBlank()) { + Gson().fromJson(clientMetadataJson, ClientMetaDetails::class.java) + } else { + null + } if (presentationDefinition != null) { return PresentationRequest( @@ -75,7 +83,9 @@ class VerificationService : VerificationServiceInterface { responseType = responseType, scope = scope, requestUri = requestUri, - responseUri = responseUri + responseUri = responseUri, + clientMetaDetails = clientMetadetails + ) } else if (!requestUri.isNullOrBlank() || !responseUri.isNullOrBlank()) { val response = @@ -267,12 +277,37 @@ class VerificationService : VerificationServiceInterface { val tokenResponse = when { response?.code() == 302 || response?.code() == 200 -> { - WrappedVpTokenResponse( - vpTokenResponse = VPTokenResponse( - location = response.headers()["Location"] - ?: "https://www.example.com?code=1" +// WrappedVpTokenResponse( +// vpTokenResponse = VPTokenResponse( +// location = response.headers()["Location"] +// ?: "https://www.example.com?code=1" +// ) +// ) + val locationHeader = response.headers()["Location"] + if (locationHeader?.contains("error=") == true) { + // Parse the error from the location header + val errorParams = locationHeader.substringAfter("?").split("&").associate { + val (key, value) = it.split("=") + key to value + } + + WrappedVpTokenResponse( + errorResponse = ErrorResponse( + error = when (errorParams["error"]) { + "invalid_request" -> 400 + else -> null + }, + errorDescription = errorParams["error_description"] + ) ) - ) + } else { + WrappedVpTokenResponse( + vpTokenResponse = VPTokenResponse( + location = locationHeader ?: "https://www.example.com?code=1" + ) + ) + } + } (response?.code() ?: 0) >= 400 -> {