FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

JCL-299: verify method by timea-solid · Pull Request #403 · inrupt/solid-client-java · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,39 @@ public CompletionStage<AccessGrant> 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<VerificationResponse> verify(final AccessGrant accessGrant) {
return v1Metadata().thenCompose(metadata -> {

final Map<String, Object> presentation = new HashMap<>();
presentation.put(VERIFIABLE_CREDENTIAL, accessGrant);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The /verify endpoint can also take a VerifiablePresentation. Do you need this in this client?


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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

In the case of an error the response will also contain an error, errorDescription and an optional reason. These could be useful for a downstream client to know but they are getting dropped here and we are only giving them the status.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

According to the VC-API spec, the verify endpoint will return a 200 in cases where the credential is invalid, but there is no defined response for, say, 4xx or 5xx category errors.

I think it would be great for the client to try to parse 4xx/5xx error bodies as if they contain those response, but that can be part of an overall improvement in how errors are processed.

status);
} catch (final IOException ex) {
throw new AccessGrantException(
"Unexpected I/O exception while verifying Access Grant", ex);
}
});
});
}

/**
* Perform an Access Grant query.
*
Expand Down Expand Up @@ -339,6 +372,10 @@ AccessGrant processVerifiableCredential(final InputStream input, final Set<Strin
}
}

VerificationResponse processVerificationResult(final InputStream input) throws IOException {
return jsonService.fromJson(input, VerificationResponse.class);
}

List<AccessGrant> processQueryResponse(final InputStream input, final Set<String> validTypes) throws IOException {
final Map<String, Object> data = jsonService.fromJson(input,
new HashMap<String, Object>(){}.getClass().getGenericSuperclass());
Expand Down Expand Up @@ -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<String> checks;

/**
* The verification warnings that were discovered.
*/
public List<String> warnings;

/**
* The verification errors that were discovered.
*/
public List<String> errors;
}
}

Back | FazBrowse Home | New Git URL