Set option to return whole JWT payload as credential

This commit is contained in:
Xavi Aracil 2024-04-04 15:12:35 +02:00
parent 3d643b579b
commit 7608773cd8
6 changed files with 8 additions and 0 deletions

View File

@ -354,4 +354,5 @@ public class Assertion extends Credential {
private static final String ISSUED_ON_PROPERTY_NAME = "issuedOn"; private static final String ISSUED_ON_PROPERTY_NAME = "issuedOn";
private static final String EXPIRES_AT_PROPERTY_NAME = "expires"; private static final String EXPIRES_AT_PROPERTY_NAME = "expires";
public static final String JWT_NODE_NAME = ""; // empty because the whole payload is the assertion public static final String JWT_NODE_NAME = ""; // empty because the whole payload is the assertion
public static final Boolean JWT_ALLOW_WHOLE_PAYLOAD = true;
} }

View File

@ -91,6 +91,7 @@ public class OB20Inspector extends VCInspector {
.put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB20) .put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB20)
.put(Key.JSON_DOCUMENT_LOADER, documentLoader) .put(Key.JSON_DOCUMENT_LOADER, documentLoader)
.put(Key.JWT_CREDENTIAL_NODE_NAME, Assertion.JWT_NODE_NAME) .put(Key.JWT_CREDENTIAL_NODE_NAME, Assertion.JWT_NODE_NAME)
.put(Key.JWT_CREDENTIAL_ALLOW_WHOLE_PAYLOAD, Assertion.JWT_ALLOW_WHOLE_PAYLOAD)
.put(Key.URI_RESOURCE_FACTORY, uriResourceFactory) .put(Key.URI_RESOURCE_FACTORY, uriResourceFactory)
.build(); .build();

View File

@ -99,6 +99,7 @@ public class OB30Inspector extends VCInspector implements SubInspector {
.put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30) .put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30)
.put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30) .put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30)
.put(Key.JWT_CREDENTIAL_NODE_NAME, VerifiableCredential.JWT_NODE_NAME) .put(Key.JWT_CREDENTIAL_NODE_NAME, VerifiableCredential.JWT_NODE_NAME)
.put(Key.JWT_CREDENTIAL_ALLOW_WHOLE_PAYLOAD, VerifiableCredential.JWT_ALLOW_WHOLE_PAYLOAD)
.build(); .build();
List<ReportItems> accumulator = new ArrayList<>(); List<ReportItems> accumulator = new ArrayList<>();

View File

@ -234,6 +234,7 @@ public class VerifiableCredential extends Credential {
private static final String EXPIRES_AT_PROPERTY_NAME_V11 = "expirationDate"; private static final String EXPIRES_AT_PROPERTY_NAME_V11 = "expirationDate";
private static final String EXPIRES_AT_PROPERTY_NAME_V20 = "validUntil"; private static final String EXPIRES_AT_PROPERTY_NAME_V20 = "validUntil";
public static final String JWT_NODE_NAME = "vc"; public static final String JWT_NODE_NAME = "vc";
public static final Boolean JWT_ALLOW_WHOLE_PAYLOAD = true;
public static final List<MimeType> REFRESH_SERVICE_MIME_TYPES = public static final List<MimeType> REFRESH_SERVICE_MIME_TYPES =
List.of(MimeType.JSON, MimeType.JSON_LD, MimeType.TEXT_PLAIN); List.of(MimeType.JSON, MimeType.JSON_LD, MimeType.TEXT_PLAIN);
} }

View File

@ -57,6 +57,9 @@ public abstract class PayloadParser {
return outerPayload; return outerPayload;
} }
JsonNode vcNode = outerPayload.get(nodeName); JsonNode vcNode = outerPayload.get(nodeName);
if (vcNode == null && (Boolean) context.get(Key.JWT_CREDENTIAL_ALLOW_WHOLE_PAYLOAD)) {
return outerPayload;
}
return vcNode; return vcNode;
} }

View File

@ -120,6 +120,7 @@ public class PayloadParserTests {
.put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30) .put(Key.PNG_CREDENTIAL_KEY, PngParser.Keys.OB30)
.put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30) .put(Key.SVG_CREDENTIAL_QNAME, SvgParser.QNames.OB30)
.put(Key.JWT_CREDENTIAL_NODE_NAME, VerifiableCredential.JWT_NODE_NAME) .put(Key.JWT_CREDENTIAL_NODE_NAME, VerifiableCredential.JWT_NODE_NAME)
.put(Key.JWT_CREDENTIAL_ALLOW_WHOLE_PAYLOAD, VerifiableCredential.JWT_ALLOW_WHOLE_PAYLOAD)
.build(); .build();
} }
} }