diff --git a/access-grant/src/main/java/com/inrupt/client/accessgrant/AccessGrantClient.java b/access-grant/src/main/java/com/inrupt/client/accessgrant/AccessGrantClient.java index 94779381012..b44272fe8a9 100644 --- a/access-grant/src/main/java/com/inrupt/client/accessgrant/AccessGrantClient.java +++ b/access-grant/src/main/java/com/inrupt/client/accessgrant/AccessGrantClient.java @@ -200,6 +200,39 @@ public CompletionStage issue(final URI type, final URI agent, final }); } + /** + * Verify an access grant or request. + * + * @param accessGrant the access grant to verify + * @return the next stage of completion containing the resulting credential + */ + public CompletionStage verify(final AccessGrant accessGrant) { + return v1Metadata().thenCompose(metadata -> { + + final Map presentation = new HashMap<>(); + presentation.put(VERIFIABLE_CREDENTIAL, accessGrant); + + final Request req = Request.newBuilder(metadata.verifyEndpoint) + .header(CONTENT_TYPE, APPLICATION_JSON) + .POST(Request.BodyPublishers.ofByteArray(serialize(presentation))).build(); + + return client.send(req, Response.BodyHandlers.ofInputStream()) + .thenApply(res -> { + try (final InputStream input = res.body()) { + final int status = res.statusCode(); + if (isSuccess(status)) { + return processVerificationResult(input); + } + throw new AccessGrantException("Unable to perform Access Grant verify: HTTP error " + status, + status); + } catch (final IOException ex) { + throw new AccessGrantException( + "Unexpected I/O exception while verifying Access Grant", ex); + } + }); + }); + } + /** * Perform an Access Grant query. * @@ -339,6 +372,10 @@ AccessGrant processVerifiableCredential(final InputStream input, final Set processQueryResponse(final InputStream input, final Set validTypes) throws IOException { final Map data = jsonService.fromJson(input, new HashMap(){}.getClass().getGenericSuperclass()); @@ -546,4 +583,24 @@ static boolean isAccessRequest(final URI type) { return "SolidAccessRequest".equals(type.toString()) || ACCESS_REQUEST.equals(type); } + + /** + * A data objects for verification responses. + */ + public static class VerificationResponse { + /** + * The verification checks that were performed. + */ + public List checks; + + /** + * The verification warnings that were discovered. + */ + public List warnings; + + /** + * The verification errors that were discovered. + */ + public List errors; + } }