Skip to content

Commit

Permalink
Merge pull request #119 from niscy-eudiw/main
Browse files Browse the repository at this point in the history
Simplified and added support for deeplink handling with multiple schemas
  • Loading branch information
stzouvaras authored Jun 5, 2024
2 parents 69731c0 + ce40d24 commit 8eab877
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
addConfigField("MDOC_OPENID4VP_SCHEME", mdocOpenId4VpScheme)
addConfigField("OPENID4VP_SCHEME", openId4VpScheme)
addConfigField("CREDENTIAL_OFFER_SCHEME", credentialOfferScheme)
addConfigField("ISSUE_AUTHORIZATION_SCHEME", openId4VciAuthorizationScheme)
addConfigField("ISSUE_AUTHORIZATION_HOST", openId4VciAuthorizationHost)
addConfigField(
"ISSUE_AUTHORIZATION_DEEPLINK",
"$openId4VciAuthorizationScheme://$openId4VciAuthorizationHost"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.content.Intent
import android.net.Uri
import androidx.core.net.toUri
import androidx.navigation.NavController
import eu.europa.ec.businesslogic.util.safeLet
import eu.europa.ec.corelogic.util.CoreActions
import eu.europa.ec.eudi.wallet.EudiWallet
import eu.europa.ec.uilogic.BuildConfig
Expand Down Expand Up @@ -79,8 +80,11 @@ fun generateNewTaskDeepLink(
}

fun hasDeepLink(deepLinkUri: Uri?): DeepLinkAction? {
return deepLinkUri?.let { uri ->
DeepLinkAction(link = uri, type = DeepLinkType.parse(uri))
return safeLet(
deepLinkUri,
deepLinkUri?.scheme
) { uri, scheme ->
DeepLinkAction(link = uri, type = DeepLinkType.parse(scheme, uri.host))
}
}

Expand Down Expand Up @@ -128,25 +132,36 @@ fun handleDeepLinkAction(
}

data class DeepLinkAction(val link: Uri, val type: DeepLinkType)
enum class DeepLinkType(val schema: String, val host: String? = null) {

OPENID4VP(schema = "openid4vp"),
CREDENTIAL_OFFER(schema = "credential-offer"),
ISSUANCE(schema = "issuance", host = "authorization"),
EXTERNAL("external");
enum class DeepLinkType(val schemas: List<String>, val host: String? = null) {

OPENID4VP(
schemas = listOf(
BuildConfig.OPENID4VP_SCHEME,
BuildConfig.EUDI_OPENID4VP_SCHEME,
BuildConfig.MDOC_OPENID4VP_SCHEME
)
),
CREDENTIAL_OFFER(
schemas = listOf(BuildConfig.CREDENTIAL_OFFER_SCHEME)
),
ISSUANCE(
schemas = listOf(BuildConfig.ISSUE_AUTHORIZATION_SCHEME),
host = BuildConfig.ISSUE_AUTHORIZATION_HOST
),
EXTERNAL(listOf("external"));

companion object {
fun parse(uri: Uri): DeepLinkType = when {
fun parse(scheme: String, host: String? = null): DeepLinkType = when {

uri.scheme?.contains(OPENID4VP.schema) == true -> {
OPENID4VP.schemas.contains(scheme) -> {
OPENID4VP
}

uri.scheme?.contains(CREDENTIAL_OFFER.schema) == true -> {
CREDENTIAL_OFFER.schemas.contains(scheme) -> {
CREDENTIAL_OFFER
}

uri.scheme?.contains(ISSUANCE.schema) == true && uri.host == ISSUANCE.host -> {
ISSUANCE.schemas.contains(scheme) && host == ISSUANCE.host -> {
ISSUANCE
}

Expand Down

0 comments on commit 8eab877

Please sign in to comment.