Skip to content

Commit

Permalink
Fix : Authorization request to support EWC RFC
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed Jun 28, 2024
1 parent 5612dbe commit 6872667
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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<String>? = 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<String>? = arrayListOf(),
@SerializedName("locations") var locations: ArrayList<String>? = arrayListOf()
@SerializedName("locations") var locations: ArrayList<String>? = arrayListOf(),
@SerializedName("credential_definition") var credentialDefinition: CredentialTypeDefinition? = CredentialTypeDefinition()

)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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,
*
Expand Down

0 comments on commit 6872667

Please sign in to comment.