-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from walt-id/feat-siopv2
Feat siopv2
- Loading branch information
Showing
5 changed files
with
184 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package id.walt.model.siopv2 | ||
|
||
import com.beust.klaxon.Json | ||
import com.beust.klaxon.Klaxon | ||
import id.walt.model.Claim | ||
import io.javalin.http.Context | ||
import java.net.URLEncoder | ||
import java.nio.charset.StandardCharsets | ||
|
||
data class SIOPv2Request( | ||
val response_type: String = "id_token", | ||
val client_id: String, | ||
val redirect_uri: String, | ||
val scope: String = "openid", | ||
val nonce: String, | ||
val registration: Registration = Registration(), | ||
@Json("exp") val expiration: Long, | ||
@Json("iat") val issuedAt: Long, | ||
val claims: Claims | ||
|
||
) { | ||
private fun enc(str: String): String = URLEncoder.encode(str, StandardCharsets.UTF_8) | ||
fun toUriQueryString(): String { | ||
return "response_type=${enc(response_type)}&client_id=${enc(client_id)}&redirect_uri=${enc(redirect_uri)}" + | ||
"&scope=${enc(scope)}&nonce=${enc(nonce)}®istration=${enc(Klaxon().toJsonString(registration))}" + | ||
"&exp=$expiration&iat=$issuedAt&claims=${enc(Klaxon().toJsonString(claims))}" | ||
} | ||
|
||
companion object { | ||
fun fromHttpContext(ctx: Context): SIOPv2Request { | ||
val requiredParams = setOf("client_id", "redirect_uri", "nonce", "registration", "exp", "iat", "claims") | ||
if (requiredParams.any { ctx.queryParam(it).isNullOrEmpty() }) | ||
throw IllegalArgumentException("HTTP context missing mandatory query parameters") | ||
return SIOPv2Request( | ||
ctx.queryParam("response_type") ?: "id_token", | ||
ctx.queryParam("client_id")!!, | ||
ctx.queryParam("redirect_uri")!!, | ||
ctx.queryParam("scope") ?: "openid", | ||
ctx.queryParam("nonce")!!, | ||
Klaxon().parse<Registration>(ctx.queryParam("registration")!!)!!, | ||
ctx.queryParam("exp")!!.toLong(), | ||
ctx.queryParam("iat")!!.toLong(), | ||
Klaxon().parse<Claims>(ctx.queryParam("claims")!!)!! | ||
) | ||
} | ||
} | ||
} | ||
|
||
data class Registration( | ||
val subject_identifier_types_supported: List<String> = listOf("did"), | ||
val did_methods_supported: List<String> = listOf("did:ebsi:"), | ||
val vp_formats: VPFormats = VPFormats(), | ||
val client_name: String? = null, | ||
val client_purpose: String? = null, | ||
val tos_uri: String? = null, | ||
val logo_uri: String? = null | ||
) | ||
|
||
data class VPFormats( | ||
val jwt_vp: JwtVPFormat? = JwtVPFormat(), | ||
val ldp_vp: LdpVpFormat? = LdpVpFormat() | ||
) | ||
|
||
data class JwtVPFormat ( | ||
val alg: Set<String> = setOf("EdDSA", "ES256K") | ||
) | ||
|
||
data class LdpVpFormat( | ||
val proof_type: Set<String> = setOf("Ed25519Signature2018") | ||
) | ||
|
||
data class InputDescriptor ( | ||
val id: String, | ||
val schema: String | ||
) | ||
|
||
data class PresentationDefinition ( | ||
val id: String, | ||
val input_descriptors: List<InputDescriptor> | ||
) | ||
|
||
data class VpTokenClaim ( | ||
val presentation_definition: PresentationDefinition | ||
) | ||
|
||
data class Claims ( | ||
val vp_token: VpTokenClaim? = null | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package id.walt.model.siopv2 | ||
|
||
import com.beust.klaxon.Json | ||
import com.beust.klaxon.Klaxon | ||
import id.walt.services.did.DidService | ||
import id.walt.services.jwt.JwtService | ||
import id.walt.services.vc.VcUtils | ||
import id.walt.vclib.Helpers.encode | ||
import id.walt.vclib.VcLibManager | ||
import id.walt.vclib.vclist.VerifiablePresentation | ||
import java.time.Instant | ||
import java.time.temporal.Temporal | ||
import java.util.* | ||
|
||
data class SIOPv2Response ( | ||
val did: String, | ||
val id_token: SIOPv2IDToken, | ||
val vp_token: SIOPv2VPToken | ||
) { | ||
fun getIdToken(): String { | ||
return JwtService.getService().sign(did, Klaxon().toJsonString(id_token)) | ||
} | ||
|
||
fun getVpToken(): String { | ||
return JwtService.getService().sign(did, Klaxon().toJsonString(vp_token)) | ||
} | ||
} | ||
|
||
data class SIOPv2IDToken( | ||
@Json("iss") val issuer: String = "https://self-issued.me/v2", | ||
@Json("sub") val subject: String, | ||
@Json("aud") val client_id: String, | ||
@Json("exp") val expiration: Long = Instant.now().plusSeconds(60*60).epochSecond, | ||
@Json("iat") val issueDate: Long = Instant.now().epochSecond, | ||
val nonce: String) | ||
|
||
data class SIOPv2VPToken( | ||
val vp_token: List<SIOPv2Presentation> | ||
) | ||
|
||
data class SIOPv2Presentation( | ||
val format: String, | ||
val presentation: String | ||
) { | ||
companion object { | ||
fun createFromVPString(vpStr: String): SIOPv2Presentation { | ||
return SIOPv2Presentation( | ||
format = when(VcLibManager.isJWT(vpStr)) { | ||
true -> "jwt_vp" | ||
else -> "ldp_vp" | ||
}, | ||
presentation = vpStr | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters