[java-idp-plugin-vci] branch dev/REVIEWOFFERCALLERFLOW updated: credential offer response, credential_issuer source to published metadata also for the sealed code, client attestation audience from the OP issuer, null issuer refused, text/plain body, offer context checked, tests

Codeberg noreply at shibboleth.net
Mon Nov 16 11:43:05 UTC 2026


This is an automated email from the git hooks/post-receive script.

codeberg pushed a commit to branch dev/REVIEWOFFERCALLERFLOW
in repository java-idp-plugin-vci.

View the commit online:
https://codeberg.org/Shibboleth/java-idp-plugin-vci/commit/1c00508a2e74b2cdf5b827f4c35b1690f843baaf

The following commit(s) were added to refs/heads/dev/REVIEWOFFERCALLERFLOW by this push:
     new 1c00508  credential offer response, credential_issuer source to published metadata also for the sealed code, client attestation audience from the OP issuer, null issuer refused, text/plain body, offer context checked, tests
1c00508 is described below

commit 1c00508a2e74b2cdf5b827f4c35b1690f843baaf
Author: Janne Lauros <janne.lauros at csc.fi>
AuthorDate: Mon Nov 16 13:42:45 2026 +0200

    credential offer response, credential_issuer source to published metadata also for the sealed code, client attestation audience from the OP issuer, null issuer refused, text/plain body, offer context checked, tests
---
 README.md                                          |   3 +-
 .../impl/CredentialOfferSuccessResponse.java       |  93 +++++++++---------
 .../profile/impl/BuildCredentialOfferToken.java    |   8 +-
 ...FormOutboundCredentialOfferResponseMessage.java |  41 +++++---
 .../META-INF/net.shibboleth.idp/postconfig.xml     |   2 +-
 .../credential-offer/credential-offer-beans.xml    |   9 +-
 .../impl/CredentialOfferSuccessResponseTest.java   | 105 +++++++++++++++++++++
 .../impl/BuildCredentialOfferTokenTest.java        |   9 ++
 ...OutboundCredentialOfferResponseMessageTest.java |  27 ++++++
 9 files changed, 227 insertions(+), 70 deletions(-)

diff --git a/README.md b/README.md
index 39a3bbd..73c65c7 100644
--- a/README.md
+++ b/README.md
@@ -4728,7 +4728,8 @@ Request, a `POST` of `application/json`:
 | `preAuthorizedCredentials` | Object | Required. Keyed with credential configuration ID, each an array of `{"path": [...], "value": ...}`, or a list of datasets `{"dataset_id": ..., "claims": [...]}`. See [Several credentials of one configuration](#several-credentials-of-one-configuration). |
 | `txCode` | Object | `value`, and hints `input_mode` (`numeric` or `text`), `length` and `description`. `value` is not in the offer. |
 
-Response is the Credential Offer as an `openid-credential-offer://` deep link. An offer of a
+Response is the Credential Offer as an `openid-credential-offer://` deep link, a `text/plain` body.
+Its `credential_issuer` is the one of the Credential Issuer metadata. An offer of a
 credential configuration whose `scope` is not in the `scope` of the client is refused with
 `400 invalid_scope`, a client without `scope` may offer every credential configuration.
 
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponse.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponse.java
index d9e3bba..3350991 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponse.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponse.java
@@ -23,9 +23,7 @@ import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -35,21 +33,19 @@ import com.nimbusds.oauth2.sdk.SuccessResponse;
 import com.nimbusds.oauth2.sdk.http.HTTPResponse;
 
 /**
- * https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#name-credential-offer
- * 
- * Forms a credential offer response. Implements only the most basic case of
- * pre-authorized flow response.
- *
+ * Credential Offer response, the Credential Offer as an {@code openid-credential-offer://} deep link.
  */
 public class CredentialOfferSuccessResponse implements SuccessResponse {
 
-    /** Class logger. */
+    /** Pre-authorized code grant type. */
     @Nonnull
-    private Logger log = LoggerFactory.getLogger(CredentialOfferSuccessResponse.class);
+    private static final String GRANT_TYPE_PRE_AUTHORIZED_CODE = "urn:ietf:params:oauth:grant-type:pre-authorized_code";
 
-    /**
-     * Percent-encoder for the Credential Offer query parameter value.
-     */
+    /** Deep link prefix of the Credential Offer. */
+    @Nonnull
+    private static final String OFFER_PREFIX = "openid-credential-offer://?credential_offer=";
+
+    /** Percent-encoder for the Credential Offer query parameter value. */
     @Nonnull
     private static final PercentEscaper OFFER_ESCAPER = new PercentEscaper("-._~:/,", false);
 
@@ -62,29 +58,34 @@ public class CredentialOfferSuccessResponse implements SuccessResponse {
     private final List<String> credentialConfigurationIds;
 
     /** grants parameter. */
-    private final Object grants;
+    @JsonProperty("grants")
+    private final Map<String, Object> grants;
+
+    /** The Credential Offer deep link. */
+    @JsonIgnore
+    private final String offer;
 
     /**
      * Constructor.
      *
-     * @param issuer                Credential Issuer identifier.
-     * @param preAuthorizedCode     Pre-authorized code.
-     * @param preAuthCredentials    Credentials offered in the pre-authorized code
-     *                              flow.
-     * @param credentialOfferTxCode Transaction Code the wallet must present.
+     * @param issuer                Credential Issuer identifier
+     * @param preAuthorizedCode     pre-authorized code
+     * @param preAuthCredentials    credentials offered in the pre-authorized code flow
+     * @param credentialOfferTxCode Transaction Code the wallet must present, or null
+     * @throws JsonProcessingException if the offer cannot be serialized
      */
     public CredentialOfferSuccessResponse(@Nonnull final String issuer, @Nonnull final String preAuthorizedCode,
             @Nonnull final Map<String, List<CredentialDataset>> preAuthCredentials,
-            @Nullable final CredentialOfferTxCode credentialOfferTxCode) {
-
+            @Nullable final CredentialOfferTxCode credentialOfferTxCode) throws JsonProcessingException {
         credentialIssuer = issuer;
         credentialConfigurationIds = preAuthCredentials.keySet().stream().collect(Collectors.toList());
         grants = buildPreAuthGrant(preAuthorizedCode, credentialOfferTxCode);
+        offer = OFFER_PREFIX + OFFER_ESCAPER.escape(new ObjectMapper().writeValueAsString(this));
     }
 
     /**
      * Get credential_issuer parameter.
-     * 
+     *
      * @return credential_issuer parameter.
      */
     public String getCredentialIssuer() {
@@ -93,7 +94,7 @@ public class CredentialOfferSuccessResponse implements SuccessResponse {
 
     /**
      * Get credential_configuration_ids parameter.
-     * 
+     *
      * @return credential_configuration_ids parameter
      */
     public List<String> getCredentialConfigurationIds() {
@@ -102,23 +103,22 @@ public class CredentialOfferSuccessResponse implements SuccessResponse {
 
     /**
      * Get grants parameter.
-     * 
+     *
      * @return grants parameter
      */
-    public Object getGrants() {
+    public Map<String, Object> getGrants() {
         return grants;
     }
 
     /**
-     * Form offer message content.
-     * 
-     * @return offer message content
-     * @throws JsonProcessingException
+     * Get the Credential Offer deep link.
+     *
+     * @return Credential Offer deep link
      */
-    private String toOffer() throws JsonProcessingException {
-        final ObjectMapper objectMapper = new ObjectMapper();
-        return "openid-credential-offer://?credential_offer="
-                + OFFER_ESCAPER.escape(objectMapper.writeValueAsString(this));
+    @JsonIgnore
+    @Nonnull
+    public String getOffer() {
+        return offer;
     }
 
     /** {@inheritDoc} */
@@ -131,13 +131,8 @@ public class CredentialOfferSuccessResponse implements SuccessResponse {
     @Override
     public HTTPResponse toHTTPResponse() {
         final HTTPResponse httpResponse = new HTTPResponse(HTTPResponse.SC_OK);
-        httpResponse.setEntityContentType(ContentType.APPLICATION_JSON);
-        try {
-            httpResponse.setContent(toOffer());
-        } catch (final JsonProcessingException e) {
-            log.error("Internal message processing error", e);
-            return null;
-        }
+        httpResponse.setEntityContentType(ContentType.TEXT_PLAIN);
+        httpResponse.setContent(offer);
         return httpResponse;
     }
 
@@ -148,18 +143,16 @@ public class CredentialOfferSuccessResponse implements SuccessResponse {
      * @param txCode      Transaction Code the wallet must present, or null
      * @return grant as a map
      */
-    @SuppressWarnings("unchecked")
-    public static Map<String, Object> buildPreAuthGrant(@Nonnull final String preauthCode,
-            final CredentialOfferTxCode txCode) {
-        assert preauthCode != null;
-        final Map<String, Object> grant = new HashMap<>();
-        grant.put("urn:ietf:params:oauth:grant-type:pre-authorized_code", new HashMap<>());
-        ((Map<String, Object>) grant.get("urn:ietf:params:oauth:grant-type:pre-authorized_code"))
-                .put("pre-authorized_code", preauthCode);
+    @Nonnull
+    private static Map<String, Object> buildPreAuthGrant(@Nonnull final String preauthCode,
+            @Nullable final CredentialOfferTxCode txCode) {
+        final Map<String, Object> preAuthorizedCodeGrant = new HashMap<>();
+        preAuthorizedCodeGrant.put("pre-authorized_code", preauthCode);
         if (txCode != null) {
-            ((Map<String, Object>) grant.get("urn:ietf:params:oauth:grant-type:pre-authorized_code")).put("tx_code",
-                    txCode.toResponseMap());
+            preAuthorizedCodeGrant.put("tx_code", txCode.toResponseMap());
         }
+        final Map<String, Object> grant = new HashMap<>();
+        grant.put(GRANT_TYPE_PRE_AUTHORIZED_CODE, preAuthorizedCodeGrant);
         return grant;
     }
 
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferToken.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferToken.java
index 5af4805..90e6362 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferToken.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferToken.java
@@ -254,10 +254,16 @@ public class BuildCredentialOfferToken extends AbstractProfileAction {
                 return;
             }
         } else {
+            final String issuer = issuerLookupStrategy.apply(profileRequestContext);
+            if (issuer == null) {
+                log.error("{} No Credential Issuer identifier", getLogPrefix());
+                ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+                return;
+            }
             final CredentialOfferClaimsSet claimsSet;
             try {
                 claimsSet = new CredentialOfferClaimsSet.Builder()
-                        .setIssuer(issuerLookupStrategy.apply(profileRequestContext)).setClientID(new ClientID(rpId))
+                        .setIssuer(issuer).setClientID(new ClientID(rpId))
                         .setJWTID(idGeneratorLookupStrategy.apply(profileRequestContext)).setIssuedAt(Instant.now())
                         .setAuthenticationTime(Instant.now()).setSubject(credentialRequest.serialize())
                         .setExpiresAt(Instant.now().plus(expiration)).build();
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessage.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessage.java
index 3c9e1f2..3993f4f 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessage.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessage.java
@@ -17,7 +17,9 @@
 package org.geant.shibboleth.plugin.openidvci.profile.impl;
 
 import java.util.function.Function;
+
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequest;
 import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferSuccessResponse;
@@ -28,11 +30,12 @@ import org.opensaml.profile.context.ProfileRequestContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+
 import jakarta.servlet.http.HttpServletResponse;
 import net.shibboleth.idp.profile.AbstractProfileAction;
 import net.shibboleth.idp.profile.IdPEventIds;
 import net.shibboleth.profile.context.navigate.IssuerLookupFunction;
-import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.servlet.HttpServletSupport;
 
@@ -43,12 +46,10 @@ public class FormOutboundCredentialOfferResponseMessage extends AbstractProfileA
 
     /** Class logger. */
     @Nonnull
-    private Logger log = LoggerFactory.getLogger(FormOutboundCredentialOfferResponseMessage.class);
+    private final Logger log = LoggerFactory.getLogger(FormOutboundCredentialOfferResponseMessage.class);
 
-    /**
-     * Credential offer context.
-     */
-    @NonnullAfterInit
+    /** Credential offer context. */
+    @Nullable
     private CredentialOfferContext ctx;
 
     /** Strategy used to obtain the response issuer value. */
@@ -73,9 +74,7 @@ public class FormOutboundCredentialOfferResponseMessage extends AbstractProfileA
     /** {@inheritDoc} */
     @Override
     protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
-        if (getHttpServletRequest() == null) {
-            log.error("{} Profile action does not contain an HttpServletRequest", getLogPrefix());
-            ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
+        if (!super.doPreExecute(profileRequestContext)) {
             return false;
         }
         if (profileRequestContext.getInboundMessageContext() == null
@@ -85,17 +84,19 @@ public class FormOutboundCredentialOfferResponseMessage extends AbstractProfileA
             return false;
         }
         ctx = profileRequestContext.getInboundMessageContext().getSubcontext(CredentialOfferContext.class);
-        if (ctx == null) {
+        if (ctx == null || ctx.getCredentialOfferToken() == null
+                || ctx.getValidatedPreAuthorizedCredentials() == null) {
             log.error("{} No credential offer context", getLogPrefix());
             ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
             return false;
         }
-        return super.doPreExecute(profileRequestContext);
+        return true;
     }
 
     /** {@inheritDoc} */
     @Override
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
+        assert ctx != null;
         final HttpServletResponse response = getHttpServletResponse();
         if (response == null) {
             log.error("{} Could not fetch HttpServletResponse", getLogPrefix());
@@ -103,9 +104,21 @@ public class FormOutboundCredentialOfferResponseMessage extends AbstractProfileA
             return;
         }
         HttpServletSupport.addNoCacheHeaders(response);
-        final CredentialOfferSuccessResponse offer = new CredentialOfferSuccessResponse(
-                issuerLookupStrategy.apply(profileRequestContext), ctx.getCredentialOfferToken(),
-                ctx.getValidatedPreAuthorizedCredentials(), ctx.getCredentialOfferTxCode());
+        final String issuer = issuerLookupStrategy.apply(profileRequestContext);
+        if (issuer == null) {
+            log.error("{} No Credential Issuer identifier", getLogPrefix());
+            ActionSupport.buildEvent(profileRequestContext, IdPEventIds.INVALID_PROFILE_CONFIG);
+            return;
+        }
+        final CredentialOfferSuccessResponse offer;
+        try {
+            offer = new CredentialOfferSuccessResponse(issuer, ctx.getCredentialOfferToken(),
+                    ctx.getValidatedPreAuthorizedCredentials(), ctx.getCredentialOfferTxCode());
+        } catch (final JsonProcessingException e) {
+            log.error("{} Failed to serialize the credential offer", getLogPrefix(), e);
+            ActionSupport.buildEvent(profileRequestContext, EventIds.MESSAGE_PROC_ERROR);
+            return;
+        }
         profileRequestContext.ensureOutboundMessageContext().setMessage(offer);
     }
 }
\ No newline at end of file
diff --git a/openid-vci-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml b/openid-vci-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
index 74ecb63..4e69adf 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net.shibboleth.idp/postconfig.xml
@@ -100,7 +100,7 @@
         p:trustEvaluator="#{getObject('openidvci.AttestationTrustEvaluator') ?: getObject('openidvci.DefaultAttestationTrustEvaluator')}"
         p:httpServletRequestSupplier-ref="shibboleth.HttpServletRequestSupplier"
         p:replayCache-ref="shibboleth.ReplayCache"
-        p:audienceLookupStrategy-ref="shibboleth.ResponderIdLookup.Simple"
+        p:audienceLookupStrategy="#{T(net.shibboleth.shared.logic.FunctionSupport).constant(getObject('shibboleth.oidc.issuer'))}"
         p:clockSkew="%{openidvci.attestation.clockSkew:PT5M}"
         p:proofLifetime="%{openidvci.attestation.proofLifetime:PT5M}" />
         
diff --git a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-beans.xml b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-beans.xml
index db3b8ff..c3b4082 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-beans.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credential-offer/credential-offer-beans.xml
@@ -35,14 +35,17 @@
  <bean id="ValidateCredentialOfferScope" class="org.geant.shibboleth.plugin.openidvci.profile.impl.ValidateCredentialOfferScope"
      scope="prototype" p:allowedCredentialConfigurationsLookupStrategy-ref="openidvci.AllowedCredentialConfigurationsLookup"/>
      
+ <bean id="OpenIDVCICredentialOfferIssuerLookup"
+    class="org.geant.shibboleth.plugin.openidvci.metadata.impl.CredentialIssuerIdentifierLookupFunction"
+    c:resolver-ref="#{'%{openidvci.issuerMetadata.resolver:openidvci.DefaultCredentialIssuerMetadataResolver}'.trim()}" />
+
  <bean id="BuildCredentialOfferToken" class="org.geant.shibboleth.plugin.openidvci.profile.impl.BuildCredentialOfferToken"
-    p:issuerLookupStrategy-ref="shibboleth.ResponderIdLookup.Simple"
+    p:issuerLookupStrategy-ref="OpenIDVCICredentialOfferIssuerLookup"
     scope="prototype" p:credentialOfferCache-ref="openidvci.CredentialOfferCache"
     c:sealer-ref="#{'%{idp.oidc.tokenSealer:shibboleth.oidc.TokenSealer}'.trim()}"/>
        
  <bean id="OpenIDVCIFormOutboundMessage" class="org.geant.shibboleth.plugin.openidvci.profile.impl.FormOutboundCredentialOfferResponseMessage"
-    p:issuerLookupStrategy-ref="shibboleth.ResponderIdLookup.Simple"
-    p:httpServletRequestSupplier-ref="shibboleth.HttpServletRequestSupplier"
+    p:issuerLookupStrategy-ref="OpenIDVCICredentialOfferIssuerLookup"
     p:httpServletResponseSupplier-ref="shibboleth.HttpServletResponseSupplier" scope="prototype"/>
     
  <bean id="OpenIDVCIBuildErrorResponseFromEvent"
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponseTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponseTest.java
new file mode 100644
index 0000000..799e2cd
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/messaging/impl/CredentialOfferSuccessResponseTest.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * Licensed under the Apache License, Version 2.0 (the “License”); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an “AS IS” BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.geant.shibboleth.plugin.openidvci.messaging.impl;
+
+import java.net.URI;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.nimbusds.common.contenttype.ContentType;
+import com.nimbusds.oauth2.sdk.http.HTTPRequest;
+import com.nimbusds.oauth2.sdk.http.HTTPResponse;
+
+/**
+ * Unit tests for {@link CredentialOfferSuccessResponse}.
+ */
+public class CredentialOfferSuccessResponseTest {
+
+    private static final String PREFIX = "openid-credential-offer://?credential_offer=";
+
+    private Map<String, List<CredentialDataset>> credentials;
+
+    @BeforeMethod
+    protected void setUp() throws Exception {
+        final HTTPRequest httpRequest = new HTTPRequest(HTTPRequest.Method.POST, new URI("http://example.com"));
+        httpRequest.setAuthorization("Basic dGVzdDp0ZXN0");
+        httpRequest.setContentType("application/json");
+        httpRequest.setBody("{\"preAuthorizedCredentials\":{\"GeantIncubatorSdJwt2\":"
+                + "[{\"path\":[\"mail\"],\"value\":\"incubatorUser at example.org\"}]}}");
+        credentials = CredentialOfferRequest.parse(httpRequest).getPreAuthorizedCredentials();
+    }
+
+    private Map<String, Object> decode(final String offer) throws Exception {
+        Assert.assertTrue(offer.startsWith(PREFIX));
+        final String json = URLDecoder.decode(offer.substring(PREFIX.length()), StandardCharsets.UTF_8);
+        return new ObjectMapper().readValue(json, new TypeReference<Map<String, Object>>() {
+        });
+    }
+
+    @SuppressWarnings("unchecked")
+    private Map<String, Object> preAuthorizedCodeGrant(final Map<String, Object> offer) {
+        return (Map<String, Object>) ((Map<String, Object>) offer.get("grants"))
+                .get("urn:ietf:params:oauth:grant-type:pre-authorized_code");
+    }
+
+    @Test
+    public void testOffer() throws Exception {
+        final CredentialOfferSuccessResponse response =
+                new CredentialOfferSuccessResponse("https://issuer.example.org", "code", credentials, null);
+        final Map<String, Object> offer = decode(response.getOffer());
+
+        Assert.assertEquals(offer.keySet(), Set.of("credential_issuer", "credential_configuration_ids", "grants"));
+        Assert.assertEquals(offer.get("credential_issuer"), "https://issuer.example.org");
+        Assert.assertEquals(offer.get("credential_configuration_ids"), List.of("GeantIncubatorSdJwt2"));
+        Assert.assertEquals(preAuthorizedCodeGrant(offer), Map.of("pre-authorized_code", "code"));
+    }
+
+    @Test
+    public void testOfferWithTxCode() throws Exception {
+        final CredentialOfferSuccessResponse response = new CredentialOfferSuccessResponse(
+                "https://issuer.example.org", "code", credentials,
+                new CredentialOfferTxCode("numeric", 5, "The code we sent to your phone", "12345"));
+        final Map<String, Object> grant = preAuthorizedCodeGrant(decode(response.getOffer()));
+
+        Assert.assertEquals(grant.get("pre-authorized_code"), "code");
+        Assert.assertEquals(grant.get("tx_code"),
+                Map.of("input_mode", "numeric", "length", 5, "description", "The code we sent to your phone"));
+        Assert.assertFalse(response.getOffer().contains("12345"));
+    }
+
+    @Test
+    public void testHTTPResponse() throws Exception {
+        final CredentialOfferSuccessResponse response =
+                new CredentialOfferSuccessResponse("https://issuer.example.org", "code", credentials, null);
+        final HTTPResponse httpResponse = response.toHTTPResponse();
+
+        Assert.assertTrue(response.indicatesSuccess());
+        Assert.assertEquals(httpResponse.getStatusCode(), 200);
+        Assert.assertEquals(httpResponse.getEntityContentType().getType(), ContentType.TEXT_PLAIN.getType());
+        Assert.assertEquals(httpResponse.getContent(), response.getOffer());
+    }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java
index 53519c4..f547aa3 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/BuildCredentialOfferTokenTest.java
@@ -161,6 +161,15 @@ public class BuildCredentialOfferTokenTest {
         Assert.assertTrue(offer.getPreAuthorizedCredentials().containsKey("GeantIncubatorSdJwt2"));
     }
 
+    @Test
+    public void testSealedCodeNoIssuer() throws Exception {
+        configuration.setPreAuthorizedCodeLength(0);
+        action.setIssuerLookupStrategy(prc -> null);
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
+    }
+
     @Test
     public void testStorageFailure() throws Exception {
         configuration.setPreAuthorizedCodeLength(10);
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessageTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessageTest.java
index f1e83a1..cb37537 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessageTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/impl/FormOutboundCredentialOfferResponseMessageTest.java
@@ -23,6 +23,7 @@ import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialOfferCo
 import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequest;
 import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferSuccessResponse;
 import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.action.EventIds;
 import org.opensaml.profile.context.ProfileRequestContext;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
@@ -137,4 +138,30 @@ public class FormOutboundCredentialOfferResponseMessageTest {
         ActionTestingSupport.assertEvent(noResponse.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
     }
 
+    @Test
+    public void testNoIssuer() throws Exception {
+        action.setIssuerLookupStrategy(prc -> null);
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), IdPEventIds.INVALID_PROFILE_CONFIG);
+    }
+
+    @Test
+    public void testNoCode() throws Exception {
+        profileRequestCtx.getInboundMessageContext().getSubcontext(CredentialOfferContext.class)
+                .setCredentialOfferToken(null);
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_PROFILE_CTX);
+    }
+
+    @Test
+    public void testNoValidatedCredentials() throws Exception {
+        profileRequestCtx.getInboundMessageContext().getSubcontext(CredentialOfferContext.class)
+                .setValidatedPreAuthorizedCredentials(null);
+        action.initialize();
+
+        ActionTestingSupport.assertEvent(action.execute(requestCtx), EventIds.INVALID_PROFILE_CTX);
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list