Skip to content

Commit

Permalink
Fix #52 - Support for client metadata during verification
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed Aug 30, 2024
1 parent 013c372 commit 9ea9b43
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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 =
Expand Down Expand Up @@ -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 -> {
Expand Down

0 comments on commit 9ea9b43

Please sign in to comment.