Skip to content

Commit

Permalink
Rename objects and classes to match expected casing
Browse files Browse the repository at this point in the history
  • Loading branch information
nodh committed Oct 21, 2024
1 parent a7abe9d commit b3c1b00
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Release 5.1.0:
- Replace `buildIssuerCredentialDataProviderOverride` in `CredentialIssuer` with `credentialProvider` to extract user information into a credential
- Remove `dataProvider` from `IssuerAgent`s constructor, as it is not needed with the new issuing interface anyway
- Replace `relyingPartyUrl` with `clientIdScheme` on `OidcSiopVerifier`s constructor, to clarify use of `client_id` in requests
- Rename objects in `OpenIdConstants.ProofType`, `OpenIdConstants.CliendIdScheme` and `OpenIdConstants.ResponseMode`

Release 5.0.1:
- Update JsonPath4K to 2.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object OpenIdConstants {
* Any proof type not natively supported by this library
*/
@Serializable(with = Serializer::class)
class OTHER(stringRepresentation: String) : ProofType(stringRepresentation)
class Other(stringRepresentation: String) : ProofType(stringRepresentation)

object Serializer : KSerializer<ProofType> {
override val descriptor: SerialDescriptor =
Expand All @@ -88,7 +88,7 @@ object OpenIdConstants {
return when (val str = decoder.decodeString()) {
STRING_JWT -> JWT
STRING_CWT -> CWT
else -> OTHER(str)
else -> Other(str)
}
}

Expand Down Expand Up @@ -263,7 +263,7 @@ object OpenIdConstants {
* with a redirect URI to the Wallet.
*/
@Serializable(with = Serializer::class)
object DIRECT_POST : ResponseMode(STRING_DIRECT_POST)
object DirectPost : ResponseMode(STRING_DIRECT_POST)

/**
* OID4VP: The Response Mode `direct_post.jwt` causes the Wallet to send the Authorization Response using an
Expand All @@ -272,37 +272,37 @@ object OpenIdConstants {
* using the `application/x-www-form-urlencoded` content type.
*/
@Serializable(with = Serializer::class)
object DIRECT_POST_JWT : ResponseMode(STRING_DIRECT_POST_JWT)
object DirectPostJwt : ResponseMode(STRING_DIRECT_POST_JWT)

/**
* OAuth 2.0: In this mode, Authorization Response parameters are encoded in the query string added to the
* `redirect_uri` when redirecting back to the Client.
*/
@Serializable(with = Serializer::class)
object QUERY : ResponseMode(STRING_QUERY)
object Query : ResponseMode(STRING_QUERY)

/**
* OAuth 2.0: In this mode, Authorization Response parameters are encoded in the fragment added to the
* `redirect_uri` when redirecting back to the Client.
*/
@Serializable(with = Serializer::class)
object FRAGMENT : ResponseMode(STRING_FRAGMENT)
object Fragment : ResponseMode(STRING_FRAGMENT)

/**
* Any not natively supported Client ID Scheme, so it can still be parsed
*/
@Serializable(with = Serializer::class)
class OTHER(stringRepresentation: String) : ResponseMode(stringRepresentation)
class Other(stringRepresentation: String) : ResponseMode(stringRepresentation)

object Serializer : KSerializer<ResponseMode> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("ResponseMode", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): ResponseMode {
return when (val string = decoder.decodeString()) {
STRING_DIRECT_POST -> DIRECT_POST
STRING_DIRECT_POST_JWT -> DIRECT_POST_JWT
STRING_QUERY -> QUERY
STRING_FRAGMENT -> FRAGMENT
else -> OTHER(string)
STRING_DIRECT_POST -> DirectPost
STRING_DIRECT_POST_JWT -> DirectPostJwt
STRING_QUERY -> Query
STRING_FRAGMENT -> Fragment
else -> Other(string)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ class OidcSiopVerifier private constructor(
val credentials: Set<RequestOptionsCredential>,
/**
* Response mode to request, see [OpenIdConstants.ResponseMode],
* by default [OpenIdConstants.ResponseMode.FRAGMENT].
* by default [OpenIdConstants.ResponseMode.Fragment].
* Setting this to any other value may require setting [responseUrl] too.
*/
val responseMode: OpenIdConstants.ResponseMode = OpenIdConstants.ResponseMode.FRAGMENT,
val responseMode: OpenIdConstants.ResponseMode = OpenIdConstants.ResponseMode.Fragment,
/**
* Response URL to set in the [AuthenticationRequestParameters.responseUrl],
* required if [responseMode] is set to [OpenIdConstants.ResponseMode.DIRECT_POST] or
* [OpenIdConstants.ResponseMode.DIRECT_POST_JWT].
* required if [responseMode] is set to [OpenIdConstants.ResponseMode.DirectPost] or
* [OpenIdConstants.ResponseMode.DirectPostJwt].
*/
val responseUrl: String? = null,
/**
Expand Down Expand Up @@ -394,8 +394,8 @@ class OidcSiopVerifier private constructor(
).joinToString(" ")

private val RequestOptions.isAnyDirectPost
get() = (responseMode == OpenIdConstants.ResponseMode.DIRECT_POST) ||
(responseMode == OpenIdConstants.ResponseMode.DIRECT_POST_JWT)
get() = (responseMode == OpenIdConstants.ResponseMode.DirectPost) ||
(responseMode == OpenIdConstants.ResponseMode.DirectPostJwt)

//TODO extend for InputDescriptor interface in case QES
private fun RequestOptionsCredential.toInputDescriptor() = DifInputDescriptor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ internal class AuthenticationResponseFactory(
request: AuthenticationRequestParametersFrom,
response: AuthenticationResponse,
) = when (request.parameters.responseMode) {
DIRECT_POST -> authnResponseDirectPost(request, response)
DIRECT_POST_JWT -> authnResponseDirectPostJwt(request, response)
QUERY -> authnResponseQuery(request, response)
FRAGMENT, null -> authnResponseFragment(request, response)
is OTHER -> TODO()
DirectPost -> authnResponseDirectPost(request, response)
DirectPostJwt -> authnResponseDirectPostJwt(request, response)
Query -> authnResponseQuery(request, response)
Fragment, null -> authnResponseFragment(request, response)
is Other -> TODO()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import at.asitplus.openid.AuthenticationRequestParameters
import at.asitplus.openid.OpenIdConstants
import at.asitplus.openid.OpenIdConstants.Errors
import at.asitplus.openid.OpenIdConstants.ID_TOKEN
import at.asitplus.openid.OpenIdConstants.ResponseMode.DIRECT_POST
import at.asitplus.openid.OpenIdConstants.ResponseMode.DIRECT_POST_JWT
import at.asitplus.openid.OpenIdConstants.ResponseMode.DirectPost
import at.asitplus.openid.OpenIdConstants.ResponseMode.DirectPostJwt
import at.asitplus.openid.OpenIdConstants.VP_TOKEN
import at.asitplus.signum.indispensable.pki.leaf
import at.asitplus.wallet.lib.oidc.AuthenticationRequestParametersFrom
Expand Down Expand Up @@ -119,7 +119,7 @@ internal class AuthorizationRequestValidator {
}

private fun OpenIdConstants.ResponseMode?.isAnyDirectPost() =
(this == DIRECT_POST) || (this == DIRECT_POST_JWT)
(this == DirectPost) || (this == DirectPostJwt)

@Throws(OAuth2Exception::class)
private fun AuthenticationRequestParameters.verifyResponseModeDirectPost() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ import at.asitplus.wallet.lib.data.ConstantIndex.AtomicAttribute2023.CLAIM_FAMIL
import at.asitplus.wallet.lib.data.ConstantIndex.AtomicAttribute2023.CLAIM_GIVEN_NAME
import at.asitplus.wallet.lib.jws.DefaultJwsService
import at.asitplus.wallet.lib.oidvci.decode
import at.asitplus.wallet.lib.oidvci.decodeFromUrlQuery
import com.benasher44.uuid.uuid4
import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.collections.shouldBeSingleton
import io.kotest.matchers.collections.shouldHaveSingleElement
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.types.shouldBeInstanceOf
import io.ktor.http.*
import io.ktor.util.*
import kotlinx.datetime.Instant

/**
Expand Down Expand Up @@ -252,7 +249,7 @@ class OidcSiopInteropTest : FreeSpec({
parsed.responseType shouldBe "vp_token"
parsed.nonce shouldBe "nonce"
parsed.clientId shouldBe "verifier-backend.eudiw.dev"
parsed.responseMode shouldBe OpenIdConstants.ResponseMode.DIRECT_POST_JWT
parsed.responseMode shouldBe OpenIdConstants.ResponseMode.DirectPostJwt
parsed.audience shouldBe "https://self-issued.me/v2"
parsed.scope shouldBe ""
val pd = parsed.presentationDefinition
Expand Down Expand Up @@ -334,7 +331,7 @@ class OidcSiopInteropTest : FreeSpec({
walletUrl = "https://wallet.a-sit.at/mobile",
requestUrl = requestUrl,
requestOptions = OidcSiopVerifier.RequestOptions(
responseMode = OpenIdConstants.ResponseMode.DIRECT_POST,
responseMode = OpenIdConstants.ResponseMode.DirectPost,
responseUrl = "https://example.com/response",
credentials = setOf(
OidcSiopVerifier.RequestOptionsCredential(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class OidcSiopIsoProtocolTest : FreeSpec({
MobileDrivingLicenceScheme, ConstantIndex.CredentialRepresentation.ISO_MDOC, listOf(requestedClaim)
)
),
responseMode = OpenIdConstants.ResponseMode.DIRECT_POST_JWT,
responseMode = OpenIdConstants.ResponseMode.DirectPostJwt,
responseUrl = "https://example.com/response",
encryption = true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class OidcSiopProtocolTest : FreeSpec({
walletUrl = walletUrl,
requestOptions = RequestOptions(
credentials = setOf(OidcSiopVerifier.RequestOptionsCredential(ConstantIndex.AtomicAttribute2023)),
responseMode = OpenIdConstants.ResponseMode.DIRECT_POST,
responseMode = OpenIdConstants.ResponseMode.DirectPost,
responseUrl = clientId,
)
)
Expand All @@ -182,7 +182,7 @@ class OidcSiopProtocolTest : FreeSpec({
walletUrl = walletUrl,
requestOptions = RequestOptions(
credentials = setOf(OidcSiopVerifier.RequestOptionsCredential(ConstantIndex.AtomicAttribute2023)),
responseMode = OpenIdConstants.ResponseMode.DIRECT_POST_JWT,
responseMode = OpenIdConstants.ResponseMode.DirectPostJwt,
responseUrl = clientId,
)
)
Expand All @@ -206,7 +206,7 @@ class OidcSiopProtocolTest : FreeSpec({
walletUrl = walletUrl,
requestOptions = RequestOptions(
credentials = setOf(OidcSiopVerifier.RequestOptionsCredential(ConstantIndex.AtomicAttribute2023)),
responseMode = OpenIdConstants.ResponseMode.QUERY,
responseMode = OpenIdConstants.ResponseMode.Query,
state = expectedState
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class OidcSiopX509SanDnsTest : FreeSpec({
listOf(CLAIM_GIVEN_NAME)
)
),
responseMode = OpenIdConstants.ResponseMode.DIRECT_POST_JWT,
responseMode = OpenIdConstants.ResponseMode.DirectPostJwt,
responseUrl = "https://example.com/response",
)
).getOrThrow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SerializationTest : FunSpec({
types = setOf(randomString(), randomString()),
),
proof = CredentialRequestProof(
proofType = OpenIdConstants.ProofType.OTHER(randomString()),
proofType = OpenIdConstants.ProofType.Other(randomString()),
jwt = randomString()
)
)
Expand Down

0 comments on commit b3c1b00

Please sign in to comment.