Skip to content

Commit

Permalink
fix: Added signing for EntityConfigurationStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmathew committed Sep 2, 2024
1 parent 623d2be commit e9147e7
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import com.sphereon.oid.fed.common.builder.EntityConfigurationStatementBuilder
import com.sphereon.oid.fed.common.builder.FederationEntityMetadataBuilder
import com.sphereon.oid.fed.openapi.models.EntityConfigurationStatement
import com.sphereon.oid.fed.openapi.models.FederationEntityMetadata
import com.sphereon.oid.fed.openapi.models.JWTHeader
import com.sphereon.oid.fed.persistence.Persistence
import com.sphereon.oid.fed.services.extensions.toJwkDTO
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject

class EntityConfigurationStatementService {
private val accountService = AccountService()
private val keyService = KeyService()
private val kmsService = KmsService("local")
private val entityConfigurationStatementQueries = Persistence.entityConfigurationStatementQueries
private val accountQueries = Persistence.accountQueries
private val subordinateQueries = Persistence.subordinateQueries
Expand Down Expand Up @@ -64,12 +67,19 @@ class EntityConfigurationStatementService {

val entityConfigurationStatement = findByUsername(accountUsername)

// @TO-DO JWT creation and signing
val entityConfigurationStatementStr = Json.encodeToString(entityConfigurationStatement)
val entityConfigurationStatementObject = Json.parseToJsonElement(entityConfigurationStatementStr).jsonObject
val key = "key_id"
val jwt = kmsService.sign(
payload = entityConfigurationStatementObject,
header = JWTHeader(typ = "entity-statement+jwt"),
keyId = key
)

entityConfigurationStatementQueries.create(
account_id = account.id,
expires_at = entityConfigurationStatement.exp.toLong(),
statement = Json.encodeToString(EntityConfigurationStatement.serializer(), entityConfigurationStatement)
statement = jwt
).executeAsOne()

return entityConfigurationStatement
Expand Down

0 comments on commit e9147e7

Please sign in to comment.