Skip to content

Commit

Permalink
authorize method
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Sep 12, 2023
1 parent 6a43a9d commit 625299b
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,95 @@
package id.walt.services.ecosystems.essif.conformance

import com.beust.klaxon.Klaxon
import id.walt.crypto.KeyAlgorithm
import id.walt.model.DidMethod
import id.walt.servicematrix.ServiceMatrix
import id.walt.services.WaltIdServices
import id.walt.services.did.DidEbsiCreateOptions
import id.walt.services.did.DidService
import id.walt.services.jwt.JwtService
import id.walt.services.key.KeyService
import io.ktor.client.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.logging.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
import java.util.*

object CredentialIssuanceFlow {
fun getCredential(type: String) {
val queryParams = authorizeRequest()
const val authorizationServer = "https://conformance-test.ebsi.eu/conformance/v3/auth-mock"
const val authorizationEndpoint = "https://conformance-test.ebsi.eu/conformance/v3/auth-mock/authorize"
const val credentialIssuer = "https://conformance-test.ebsi.eu/conformance/v3/issuer-mock"

private val klaxon = Klaxon()
private val http = HttpClient {
install(ContentNegotiation) {
json(Json { ignoreUnknownKeys = true })
}
if (WaltIdServices.httpLogging) {
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.ALL
}
}
}

suspend fun getCredential(type: String) {
val queryParams = authorizeRequest(type)
val idTokenParams = directPostIdTokenRequest()
val authToken = authTokenRequest()
val jwtCredential = credentialRequest()
decodeCredential(jwtCredential)
}

private fun authorizeRequest() {}
/*private */suspend fun authorizeRequest(credential: String): String {
// create keys (ES256 & ES256k)
val key = KeyService.getService().generate(KeyAlgorithm.ECDSA_Secp256k1)
// create did
val did = DidService.create(DidMethod.ebsi, key.id, DidEbsiCreateOptions(version = 1))
// client-id
val clientId = "https://conformance-test.ebsi.eu/conformance/v3/client-mock/$did"
val scope = "openid"
val clientMetadata = getClientMetadata(clientId)
val authorizationDetails = listOf(getAuthorizationDetails(getCredentialRequestedTypesList(credential), credentialIssuer))
val queryParams = mapOf(
"scope" to scope,
"client_id" to clientId,
"client_metadata" to clientMetadata,
"redirect_uri" to "$clientId/code-cb",
"response_type" to "code",
"state" to UUID.randomUUID().toString(),
"authorization_details" to authorizationDetails,
//TODO:???
// "code_challenge" to "",
// "code_challenge_method" to "",
// "issuer_state" to "",
)
val jwtPayload = mapOf(
"client_metadata" to clientMetadata,
"authorization_details" to authorizationDetails
).plus(queryParams)
.plus(mapOf(
"iss" to clientId,
"aud" to credentialIssuer
))
// TODO: set issuer, set audience
val requestParam = JwtService.getService().sign(key.id, klaxon.toJsonString(jwtPayload))
val authResponse = http.get(authorizationEndpoint){
url{
queryParams.forEach{
parameters.append(it.key, klaxon.toJsonString(it.value))
}
parameters.append("request", requestParam)
}
}
//TODO: parse response
val parseResponse = authResponse.bodyAsText()
return parseResponse
}
private fun directPostIdTokenRequest() {}
private fun authTokenRequest() {}
private fun credentialRequest(): String {
Expand All @@ -26,4 +106,17 @@ object CredentialIssuanceFlow {
else -> {}
}
}.plus(type)

private fun getClientMetadata(clientId: String) = mapOf(
"redirect_uris" to listOf("$clientId/code-cb"),
"jwks_uri" to "$clientId/jwks",
"authorization_endpoint" to "$clientId/authorize"
)

private fun getAuthorizationDetails(credentialTypes: List<String>, credentialIssuer: String) = mapOf(
"type" to "openid_credential",
"format" to "jwt_vc",
"types" to credentialTypes,
"locations" to listOf(credentialIssuer),
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package id.walt.services.ecosystems.essif.conformance

interface Test {
fun run()
suspend fun run()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import id.walt.services.ecosystems.essif.conformance.accreditandauthorize.tao.Tr
import id.walt.services.ecosystems.essif.conformance.accreditandauthorize.ti.TrustedIssuerTests

object AccreditAndAuthorizeTests : Test {
override fun run() {
override suspend fun run() {
TrustedIssuerTests.run()
TrustedAccreditationOrganizationTests.run()
RootTrustedAccreditationOrganizationTests.run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.rtao
import id.walt.services.ecosystems.essif.conformance.Test

object RegisterVerifiableAuthorisationForTrustChainToTIR : Test {
override fun run() {
override suspend fun run() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.rtao
import id.walt.services.ecosystems.essif.conformance.Test

object RequestVerifiableAuthorisationForTrustChain : Test {
override fun run() {
override suspend fun run() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.rtao
import id.walt.services.ecosystems.essif.conformance.Test

object RootTrustedAccreditationOrganizationTests : Test {
override fun run() {
override suspend fun run() {
RequestVerifiableAuthorisationForTrustChain.run()
RegisterVerifiableAuthorisationForTrustChainToTIR.run()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.tao
import id.walt.services.ecosystems.essif.conformance.Test

object IssueVerifiableAccreditationToAccreditForSubAccount : Test {
override fun run() {
override suspend fun run() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.tao
import id.walt.services.ecosystems.essif.conformance.Test

object IssueVerifiableAccreditationToAttestForSubAccount : Test {
override fun run() {
override suspend fun run() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.tao
import id.walt.services.ecosystems.essif.conformance.Test

object IssueVerifiableAuthorisationToOnboardForSubAccount : Test {
override fun run() {
override suspend fun run() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.tao
import id.walt.services.ecosystems.essif.conformance.Test

object RegisterVerifiableAccreditationToAccreditToTIR : Test {
override fun run() {
override suspend fun run() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import id.walt.services.ecosystems.essif.conformance.CredentialIssuanceFlow
import id.walt.services.ecosystems.essif.conformance.Test

object RequestVerifiableAccreditationToAccredit : Test {
override fun run() {
override suspend fun run() {
val credential = CredentialIssuanceFlow.getCredential("VerifiableAccreditationToAccredit")
TODO("Not yet implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.tao
import id.walt.services.ecosystems.essif.conformance.Test

object RevokeAccreditationsForSubAccount : Test {
override fun run() {
override suspend fun run() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.tao
import id.walt.services.ecosystems.essif.conformance.Test

object TrustedAccreditationOrganizationTests : Test {
override fun run() {
override suspend fun run() {
RequestVerifiableAccreditationToAccredit.run()
RegisterVerifiableAccreditationToAccreditToTIR.run()
IssueVerifiableAuthorisationToOnboardForSubAccount.run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.ti
import id.walt.services.ecosystems.essif.conformance.Test

object AccreditationAsTrustedIssuer: Test {
override fun run() {
override suspend fun run() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.ti
import id.walt.services.ecosystems.essif.conformance.Test

object IssuerAndRevoke: Test {
override fun run() {
override suspend fun run() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import id.walt.services.ecosystems.essif.conformance.CredentialIssuanceFlow
import id.walt.services.ecosystems.essif.conformance.Test

object Onboarding : Test {
override fun run() {
override suspend fun run() {
ConformanceLog.log("Onboarding")
requestCredential()
registerDidDocument("")
}

fun requestCredential() {
suspend fun requestCredential() {
ConformanceLog.log("Request VerifiableAuthorisationToOnboard")
val credential = CredentialIssuanceFlow.getCredential("VerifiableAuthorizationToOnboard")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package id.walt.services.ecosystems.essif.conformance.accreditandauthorize.ti
import id.walt.services.ecosystems.essif.conformance.Test

object TrustedIssuerTests : Test {
override fun run() {
override suspend fun run() {
Onboarding.run()
AccreditationAsTrustedIssuer.run()
IssuerAndRevoke.run()
Expand Down

0 comments on commit 625299b

Please sign in to comment.