diff --git a/app/src/main/java/com/ewc/eudiwalletoidcandroid/MainViewModel.kt b/app/src/main/java/com/ewc/eudiwalletoidcandroid/MainViewModel.kt index 7506175..4f0083c 100644 --- a/app/src/main/java/com/ewc/eudiwalletoidcandroid/MainViewModel.kt +++ b/app/src/main/java/com/ewc/eudiwalletoidcandroid/MainViewModel.kt @@ -119,6 +119,8 @@ class MainViewModel : ViewModel() { } private suspend fun getCredential() { + val types = IssueService().getTypesFromCredentialOffer(offerCredential) + val format = IssueService().getFormatFromIssuerConfig(issuerConfig, types.lastOrNull() ?:"") val credential = IssueService().processCredentialRequest( did, subJwk, @@ -126,7 +128,8 @@ class MainViewModel : ViewModel() { tokenResponse?.tokenResponse?.cNonce, offerCredential, issuerConfig?.credentialEndpoint, - tokenResponse?.tokenResponse?.accessToken + tokenResponse?.tokenResponse?.accessToken, + format?:"jwt_vc" ) withContext(Dispatchers.Main) { diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/AuthorisationServerWellKnownConfiguration.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/AuthorisationServerWellKnownConfiguration.kt index b476819..c70b506 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/AuthorisationServerWellKnownConfiguration.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/AuthorisationServerWellKnownConfiguration.kt @@ -14,7 +14,6 @@ data class AuthorisationServerWellKnownConfiguration( @SerializedName("response_modes_supported") var responseModesSupported: ArrayList = arrayListOf(), @SerializedName("grant_types_supported") var grantTypesSupported: ArrayList = arrayListOf(), @SerializedName("subject_types_supported") var subjectTypesSupported: ArrayList = arrayListOf(), -// @SerializedName("id_token_signing_alg_values_supported") var idTokenSigningAlgValuesSupported: ArrayList = arrayListOf(), @SerializedName("request_object_signing_alg_values_supported") var requestObjectSigningAlgValuesSupported: ArrayList = arrayListOf(), @SerializedName("request_parameter_supported") var requestParameterSupported: Boolean? = null, @SerializedName("request_uri_parameter_supported") var requestUriParameterSupported: Boolean? = null, diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/CredentialOffer.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/CredentialOffer.kt index cd1a671..129ed49 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/CredentialOffer.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/CredentialOffer.kt @@ -3,11 +3,21 @@ package com.ewc.eudi_wallet_oidc_android.models import com.google.gson.annotations.SerializedName data class CredentialOffer( + @SerializedName("credential_issuer") var credentialIssuer: String? = null, + @SerializedName("credentials") var credentials: ArrayList? = null, + @SerializedName("grants") var grants: Grants? = null +) +data class CredentialOfferV1( @SerializedName("credential_issuer") var credentialIssuer: String? = null, @SerializedName("credentials") var credentials: ArrayList? = null, @SerializedName("grants") var grants: Grants? = null +) +data class CredentialOfferV2( + @SerializedName("credential_issuer") var credentialIssuer: String? = null, + @SerializedName("credentials") var credentials: ArrayList? = null, + @SerializedName("grants") var grants: Grants? = null ) data class Credentials( diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/IssuerWellKnownConfiguration.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/IssuerWellKnownConfiguration.kt index ce764d1..a133fad 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/IssuerWellKnownConfiguration.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/IssuerWellKnownConfiguration.kt @@ -3,40 +3,34 @@ package com.ewc.eudi_wallet_oidc_android.models import com.google.gson.annotations.SerializedName data class IssuerWellKnownConfiguration( - @SerializedName("issuer") var issuer: String? = null, @SerializedName("credential_issuer") var credentialIssuer: String? = null, @SerializedName("authorization_server") var authorizationServer: String? = null, + @SerializedName("authorization_servers") var authorizationServers: ArrayList? = null, @SerializedName("credential_endpoint") var credentialEndpoint: String? = null, @SerializedName("deferred_credential_endpoint") var deferredCredentialEndpoint: String? = null, - @SerializedName("display") var display: Display? = null, - @SerializedName("credentials_supported") var credentialsSupported: ArrayList = arrayListOf() - + @SerializedName("display") var display: Any? = null, + @SerializedName("credentials_supported") var credentialsSupported: Any? = null ) data class CredentialsSupported( - @SerializedName("format") var format: String? = null, @SerializedName("types") var types: ArrayList = arrayListOf(), @SerializedName("trust_framework") var trustFramework: TrustFramework? = TrustFramework(), @SerializedName("display") var display: ArrayList = arrayListOf() - ) data class Display( - @SerializedName("name") var name: String? = null, @SerializedName("location") var location: String? = null, @SerializedName("locale") var locale: String? = null, @SerializedName("cover") var cover: Image? = Image(), @SerializedName("logo") var logo: Image? = Image(), @SerializedName("description") var description: String? = null - ) data class Image( - + @SerializedName("uri") var uri: String? = null, @SerializedName("url") var url: String? = null, @SerializedName("alt_text") var altText: String? = 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 62e0dfd..0ad3634 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 @@ -4,11 +4,13 @@ import android.net.Uri 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.CredentialOffer +import com.ewc.eudi_wallet_oidc_android.models.CredentialOfferV1 +import com.ewc.eudi_wallet_oidc_android.models.CredentialOfferV2 import com.ewc.eudi_wallet_oidc_android.models.CredentialRequest import com.ewc.eudi_wallet_oidc_android.models.ErrorResponse +import com.ewc.eudi_wallet_oidc_android.models.IssuerWellKnownConfiguration import com.ewc.eudi_wallet_oidc_android.models.Jwt import com.ewc.eudi_wallet_oidc_android.models.ProofV3 -import com.ewc.eudi_wallet_oidc_android.models.TokenResponse import com.ewc.eudi_wallet_oidc_android.models.VpFormatsSupported import com.ewc.eudi_wallet_oidc_android.models.WrappedCredentialResponse import com.ewc.eudi_wallet_oidc_android.models.WrappedTokenResponse @@ -84,7 +86,7 @@ class IssueService : IssueServiceInterface { val authorisationDetails = Gson().toJson( arrayListOf( AuthorizationDetails( - types = credentialOffer?.credentials?.get(0)?.types, + types = getTypesFromCredentialOffer(credentialOffer), locations = arrayListOf(credentialOffer?.credentialIssuer ?: "") ) ) @@ -267,7 +269,8 @@ class IssueService : IssueServiceInterface { nonce: String?, credentialOffer: CredentialOffer?, credentialIssuerEndPoint: String?, - accessToken: String? + accessToken: String?, + format:String ): WrappedCredentialResponse? { // Add claims @@ -296,8 +299,8 @@ class IssueService : IssueServiceInterface { // Construct credential request val body = CredentialRequest( - types = credentialOffer?.credentials?.get(0)?.types, - format = credentialOffer?.credentials?.get(0)?.format, + types = getTypesFromCredentialOffer(credentialOffer), + format = format, ProofV3( proofType = "jwt", jwt = jwt.serialize() @@ -413,5 +416,79 @@ class IssueService : IssueServiceInterface { } } + /** + * Get format from IssuerWellKnownConfiguration + * + * @param issuerConfig + * @param type + */ + override fun getFormatFromIssuerConfig( + issuerConfig: IssuerWellKnownConfiguration?, + type: String? + ): String? { + var format: String = "jwt_vc" + val credentialOfferJsonString = Gson().toJson(issuerConfig) + + val jsonObject = JSONObject(credentialOfferJsonString) + + val credentialsSupported: Any = jsonObject.opt("credentials_supported") ?: return null + + when (credentialsSupported) { + is JSONObject -> { + val credentialSupported = credentialsSupported.getJSONObject(type ?: "") + format = credentialSupported.getString("format") + } + + is JSONArray -> { + for (i in 0 until credentialsSupported.length()) { + val jsonObject: JSONObject = credentialsSupported.getJSONObject(i) + + // Get the "types" JSONArray + val typesArray = jsonObject.getJSONArray("types") + + // Check if the string is present in the "types" array + for (j in 0 until typesArray.length()) { + if (typesArray.getString(j) == type) { + format = jsonObject.getString("format") + break + } + } + } + } + + else -> { + // Neither JSONObject nor JSONArray + println("Child is neither JSONObject nor JSONArray") + } + } + + return format + } + + /** + * Get types from credential offer + * + * @param credentialOffer + * @return + */ + override fun getTypesFromCredentialOffer(credentialOffer: CredentialOffer?): ArrayList { + var types: ArrayList = ArrayList() + val credentialOfferJsonString = Gson().toJson(credentialOffer) + try { + try { + val credentialOfferV2 = + Gson().fromJson(credentialOfferJsonString, CredentialOfferV2::class.java) + types = credentialOfferV2.credentials ?: ArrayList() + } catch (e: Exception) { + val credentOfferV1 = + Gson().fromJson(credentialOfferJsonString, CredentialOfferV1::class.java) + types = credentOfferV1?.credentials?.get(0)?.types ?: ArrayList() + } + } catch (e: Exception) { + + } + + return types + } } \ No newline at end of file diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueServiceInterface.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueServiceInterface.kt index 5d650bd..c49da64 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueServiceInterface.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/services/issue/IssueServiceInterface.kt @@ -1,6 +1,7 @@ package com.ewc.eudi_wallet_oidc_android.services.issue import com.ewc.eudi_wallet_oidc_android.models.CredentialOffer +import com.ewc.eudi_wallet_oidc_android.models.IssuerWellKnownConfiguration import com.ewc.eudi_wallet_oidc_android.models.WrappedCredentialResponse import com.ewc.eudi_wallet_oidc_android.models.WrappedTokenResponse import com.nimbusds.jose.jwk.ECKey @@ -83,7 +84,8 @@ interface IssueServiceInterface { nonce: String?, credentialOffer: CredentialOffer?, credentialIssuerEndPoint: String?, - accessToken: String? + accessToken: String?, + format: String ): WrappedCredentialResponse? /** @@ -97,4 +99,25 @@ interface IssueServiceInterface { acceptanceToken: String?, deferredCredentialEndPoint: String? ): WrappedCredentialResponse? + + /** + * Get format from IssuerWellKnownConfiguration + * + * @param issuerConfig + * @param type + */ + fun getFormatFromIssuerConfig( + issuerConfig: IssuerWellKnownConfiguration?, + type: String? + ): String? + + /** + * Get types from credential offer + * + * @param credentialOffer + * @return + */ + fun getTypesFromCredentialOffer( + credentialOffer: CredentialOffer? + ): ArrayList } \ No newline at end of file