Skip to content

Commit

Permalink
fix: support update of client_id and client_secret
Browse files Browse the repository at this point in the history
Signed-off-by: Pat Losoponkul <[email protected]>
  • Loading branch information
Pat Losoponkul committed Jun 6, 2024
1 parent 1c6fd95 commit ddc08b9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,17 @@ case class CredentialIssuerControllerImpl(
): ZIO[WalletAccessContext, ErrorResponse, CredentialIssuer] =
for {
maybeAuthServerUrl <- ZIO
.succeed(request.authorizationServer)
.succeed(request.authorizationServer.flatMap(_.url))
.flatMap {
case Some(url) => parseURL(url).asSome
case None => ZIO.none
}
issuer <- issuerMetadataService.updateCredentialIssuer(issuerId, maybeAuthServerUrl)
issuer <- issuerMetadataService.updateCredentialIssuer(
issuerId,
maybeAuthServerUrl,
request.authorizationServer.flatMap(_.clientId),
request.authorizationServer.flatMap(_.clientSecret)
)
} yield issuer: CredentialIssuer

override def deleteCredentialIssuer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ object AuthorizationServer {
given decoder: JsonDecoder[AuthorizationServer] = DeriveJsonDecoder.gen
}

case class CredentialIssuer(id: UUID, authorizationServer: String)
case class CredentialIssuer(id: UUID, authorizationServerUrl: String)

case class PatchCredentialIssuerRequest(authorizationServer: Option[String] = None)
case class PatchAuthorizationServer(url: Option[String], clientId: Option[String], clientSecret: Option[String])

object PatchAuthorizationServer {
given schema: Schema[PatchAuthorizationServer] = Schema.derived
given encoder: JsonEncoder[PatchAuthorizationServer] = DeriveJsonEncoder.gen
given decoder: JsonDecoder[PatchAuthorizationServer] = DeriveJsonDecoder.gen
}

case class PatchCredentialIssuerRequest(authorizationServer: Option[PatchAuthorizationServer] = None)

object PatchCredentialIssuerRequest {
given schema: Schema[PatchCredentialIssuerRequest] = Schema.derived
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ trait OID4VCIIssuerMetadataRepository {
def findIssuerById(issuerId: UUID): UIO[Option[CredentialIssuer]]
def createIssuer(issuer: CredentialIssuer): URIO[WalletAccessContext, Unit]
def findWalletIssuers: URIO[WalletAccessContext, Seq[CredentialIssuer]]
def updateIssuer(issuerId: UUID, authorizationServer: Option[URL] = None): URIO[WalletAccessContext, Unit]
def updateIssuer(
issuerId: UUID,
authorizationServer: Option[URL] = None,
authorizationServerClientId: Option[String] = None,
authorizationServerClientSecret: Option[String] = None
): URIO[WalletAccessContext, Unit]
def deleteIssuer(issuerId: UUID): URIO[WalletAccessContext, Unit]
def createCredentialConfiguration(issuerId: UUID, config: CredentialConfiguration): URIO[WalletAccessContext, Unit]
def findCredentialConfigurationsByIssuer(issuerId: UUID): UIO[Seq[CredentialConfiguration]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ trait OID4VCIIssuerMetadataService {
def getCredentialIssuers: URIO[WalletAccessContext, Seq[CredentialIssuer]]
def updateCredentialIssuer(
issuerId: UUID,
authorizationServer: Option[URL] = None
authorizationServer: Option[URL] = None,
authorizationServerClientId: Option[String] = None,
authorizationServerClientSecret: Option[String] = None
): ZIO[WalletAccessContext, IssuerIdNotFound, CredentialIssuer]
def deleteCredentialIssuer(issuerId: UUID): ZIO[WalletAccessContext, IssuerIdNotFound, Unit]
def createCredentialConfiguration(
Expand Down Expand Up @@ -99,11 +101,18 @@ class OID4VCIIssuerMetadataServiceImpl(repository: OID4VCIIssuerMetadataReposito

override def updateCredentialIssuer(
issuerId: UUID,
authorizationServer: Option[URL]
authorizationServer: Option[URL],
authorizationServerClientId: Option[String],
authorizationServerClientSecret: Option[String]
): ZIO[WalletAccessContext, IssuerIdNotFound, CredentialIssuer] =
for {
_ <- repository
.updateIssuer(issuerId, authorizationServer = authorizationServer)
.updateIssuer(
issuerId = issuerId,
authorizationServer = authorizationServer,
authorizationServerClientId = authorizationServerClientId,
authorizationServerClientSecret = authorizationServerClientSecret
)
.catchSomeDefect { case _: UnexpectedAffectedRow =>
ZIO.fail(IssuerIdNotFound(issuerId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ class JdbcOID4VCIIssuerMetadataRepository(xa: Transactor[ContextAwareTask], xb:

override def updateIssuer(
issuerId: UUID,
authorizationServer: Option[URL]
authorizationServer: Option[URL],
authorizationServerClientId: Option[String],
authorizationServerClientSecret: Option[String]
): URIO[WalletAccessContext, Unit] = {
val setFr = (now: Instant) =>
Fragments.set(
fr"updated_at = $now",
(Seq(authorizationServer.map(url => fr"authorization_server = $url")).flatten): _*
(Seq(
authorizationServer.map(url => fr"authorization_server = $url"),
authorizationServerClientId.map(i => fr"authorization_server_client_id = $i"),
authorizationServerClientSecret.map(i => fr"authorization_server_client_secret = $i")
).flatten)*
)
val cxnIO = (setFr: Fragment) => sql"""
|UPDATE public.issuer_metadata
Expand Down

0 comments on commit ddc08b9

Please sign in to comment.