From 6872667b543545cfacbc079977b387418cefc92e Mon Sep 17 00:00:00 2001 From: milan Date: Fri, 28 Jun 2024 16:45:37 +0530 Subject: [PATCH] Fix : Authorization request to support EWC RFC --- .../models/AuthorizationDetails.kt | 8 ++- .../services/issue/IssueService.kt | 59 +++++++++++++------ 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/AuthorizationDetails.kt b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/AuthorizationDetails.kt index 4c039e2..9e35957 100644 --- a/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/AuthorizationDetails.kt +++ b/eudi-wallet-oidc-android/src/main/java/com/ewc/eudi_wallet_oidc_android/models/AuthorizationDetails.kt @@ -1,12 +1,16 @@ package com.ewc.eudi_wallet_oidc_android.models import com.google.gson.annotations.SerializedName +data class CredentialTypeDefinition( + @SerializedName("type") var type: ArrayList? = arrayListOf() +) data class AuthorizationDetails( @SerializedName("type") var type: String? = "openid_credential", - @SerializedName("format") var format: String? = "jwt_vc", + @SerializedName("format") var format: String? = null, @SerializedName("types") var types: ArrayList? = arrayListOf(), - @SerializedName("locations") var locations: ArrayList? = arrayListOf() + @SerializedName("locations") var locations: ArrayList? = arrayListOf(), + @SerializedName("credential_definition") var credentialDefinition: CredentialTypeDefinition? = CredentialTypeDefinition() ) \ 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 fe63aa3..d2fe320 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 @@ -9,6 +9,7 @@ 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.CredentialTypeDefinition 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 @@ -95,15 +96,7 @@ class IssueService : IssueServiceInterface { val scope = "openid" val state = UUID.randomUUID().toString() val clientId = did - val authorisationDetails = Gson().toJson( - arrayListOf( - AuthorizationDetails( - types = getTypesFromCredentialOffer(credentialOffer), - locations = arrayListOf(credentialOffer?.credentialIssuer ?: "") - ) - ) - ) - + val authorisationDetails = buildAuthorizationRequest(credentialOffer) val redirectUri = "http://localhost:8080" val nonce = UUID.randomUUID().toString() @@ -176,14 +169,7 @@ class IssueService : IssueServiceInterface { val scope = "openid" val state = UUID.randomUUID().toString() val clientId = did - val authorisationDetails = Gson().toJson( - arrayListOf( - AuthorizationDetails( - types = getTypesFromCredentialOffer(credentialOffer), - locations = arrayListOf(credentialOffer?.credentialIssuer ?: "") - ) - ) - ) + val authorisationDetails = buildAuthorizationRequest(credentialOffer) val redirectUri = "http://localhost:8080" val nonce = UUID.randomUUID().toString() @@ -285,6 +271,45 @@ class IssueService : IssueServiceInterface { } } + private fun buildAuthorizationRequest(credentialOffer: CredentialOffer?):String{ + val gson = Gson() + var credentialDefinitionNeeded = false + try { + val credentialOfferV1 = + gson.fromJson(gson.toJson(credentialOffer), CredentialOfferV1::class.java) + + if (credentialOfferV1?.credentials?.get(0)?.trustFramework == null) + credentialDefinitionNeeded = true + + } catch (e: Exception) { + credentialDefinitionNeeded = true + } + if (credentialDefinitionNeeded) { + return gson.toJson( + arrayListOf( + AuthorizationDetails( + format = "jwt_vc_json", + locations = arrayListOf(credentialOffer?.credentialIssuer ?: ""), + credentialDefinition = CredentialTypeDefinition( + type = getTypesFromCredentialOffer(credentialOffer) + ) + ) + ) + ) + + }else{ + return gson.toJson( + arrayListOf( + AuthorizationDetails( + format = "jwt_vc", + types = getTypesFromCredentialOffer(credentialOffer), + locations = arrayListOf(credentialOffer?.credentialIssuer ?: "") + ) + ) + ) + } + } + /** * To process the token, *