Skip to content

Commit

Permalink
feat: add api docs, option asJwt
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandra-bel authored and andreibogus committed Feb 27, 2024
1 parent 579a5ec commit 9dc628b
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.eclipse.tractusx.managedidentitywallets.apidocs;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
Expand All @@ -13,6 +8,11 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public class PresentationControllerApiDocs {
public static final String API_TAG_VERIFIABLE_PRESENTATIONS_GENERATION = "Verifiable Presentations - Generation";
public static final String API_TAG_VERIFIABLE_PRESENTATIONS_VALIDATION = "Verifiable Presentations - Validation";
Expand Down Expand Up @@ -286,4 +286,102 @@ public class PresentationControllerApiDocs {
public @interface PostVerifiablePresentationValidationApiDocs {
}

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Tag(name = API_TAG_VERIFIABLE_PRESENTATIONS_GENERATION)
@Operation(summary = "Create Verifiable Presentation", description = "Create a verifiable presentation for the verifiable credential types listed in STS token")
@ApiResponses(value = {
@ApiResponse(responseCode = "401", description = "The request could not be completed due to a failed authorization.", content = {
@Content(examples = {
@ExampleObject(name = "The following errors were found on token validation", value = "TOKEN_ALREADY_EXPIRED, NONCE_MISSING")
}) }),
@ApiResponse(responseCode = "403", description = "The request could not be completed due to a forbidden scope value", content = {
@Content(examples = {}) }),
@ApiResponse(responseCode = "500", description = "Any other internal server error", content = {
@Content(examples = {
@ExampleObject(name = "Internal server error", value = """
{
"type": "about:blank",
"title": "Error Title",
"status": 500,
"detail": "Error Details",
"instance": "API endpoint",
"properties": {
"timestamp": 1689762476720
}
}
""")
}) }),
@ApiResponse(responseCode = "404", description = "One or more of the requested verifiable credential types were not found", content = {
@Content(examples = {
@ExampleObject(name = "One or more of the requested verifiable credential types were not found", value = """
{
"type": "about:blank",
"title": "Error Title",
"status": 404,
"detail": "Verifiable credential types that were not found",
"instance": "API endpoint",
"properties": {
"timestamp": 1689762476720
}
}
""")
}) }),
@ApiResponse(responseCode = "200", description = "Verifiable Presentation", content = {
@Content(examples = {
@ExampleObject(name = "VP as Json-LD", value = """
{
"vp": {
"@context": [
"https://www.w3.org/2018/credentials/v1"
],
"id": "did:web:localhost:BPNL000000000000#b2e69e47-95f3-48ff-af30-eaaab36431d5",
"type": [
"VerifiablePresentation"
],
"verifiableCredential": [
{
"id": "did:web:localhost:BPNL000000000000#f73e3631-ba87-4a03-bea3-b28700056879",
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://catenax-ng.github.io/product-core-schemas/businessPartnerData.json",
"https://w3id.org/security/suites/jws-2020/v1"
],
"type": [
"VerifiableCredential",
"BpnCredential"
],
"issuer": "did:web:localhost:BPNL000000000000",
"expirationDate": "2024-12-31T18:30:00Z",
"issuanceDate": "2023-07-19T09:11:34Z",
"credentialSubject": [
{
"bpn": "BPNL000000000000",
"id": "did:web:localhost:BPNL000000000000",
"type": "BpnCredential"
}
],
"proof": {
"created": "2023-07-19T09:11:39Z",
"jws": "eyJhbGciOiJFZERTQSJ9..fdn2qU85auOltdHDLdHI7sJVV1ZPdftpiXd_ndXN0dFgSDWiIrScdD03wtvKLq_H-shQWfh2RYeMmrlEzAhfDw",
"proofPurpose": "proofPurpose",
"type": "JsonWebSignature2020",
"verificationMethod": "did:web:localhost:BPNL000000000000#"
}
}
]
}
}
"""),
@ExampleObject(name = "VP as JWT", value = """
{
"vp": "eyJraWQiOiJkaWQ6d2ViOmxvY2FsaG9zdDpCUE5MMDAwMDA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6bG9jYWxob3N0OkJQTkwwMDAwMDAwMDAwMDAiLCJicG4iOiJCUE5MMDAwMDAwMDAwMDAwIiwidHlwZSI6IkJwbkNyZWRlbnRpYWwifSwicHJvb2YiOnsicHJvb2ZQdXJwb3NlIjoicHJvb2ZQdXJwb3NlIiwidHlwZSI6Ikpzb25XZWJTaWduYXR1cmUyMDIwIiwidmVyaWZpY2F0aW9uTWV0aG9kIjoiZGlkOndlYjpsb2NhbGhvc3Q6QlBOTDAwMDAwMDAwMDAwMCMiLCJjcmVhdGVkIjoiMjAyMy0wNy0xOVQwOToxMTozOVoiLCJqd3MiOiJleUpoYkdjaU9pSkZaRVJUUVNKOS4uZmRuMnFVODVhdU9sdGRIRExkSEk3c0pWVjFaUGRmdHBpWGRfbmRYTjBkRmdTRFdpSXJTY2REMDN3dHZLTHFfSC1zaFFXZmgyUlllTW1ybEV6QWhmRHcifX19LCJleHAiOjE2ODk4MzQ4MDUsImp0aSI6ImIwODYzOWZiLWQ5MWEtNGUwZS1iNmY4LTYzYjdhMzQ1ZTRhZiJ9.80x0AB-OauefdeZfx1cwhitdVKRvCRFeFzYwU73DL7y4w34vu6BdfHWLBGjkwELxkQEoFfiTPOqtuyqhtsyDBg"
}
""")
})
})
})
public @interface GetVerifiablePresentationIATPApiDocs {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.nimbusds.jwt.SignedJWT;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.managedidentitywallets.apidocs.PresentationControllerApiDocs.GetVerifiablePresentationIATPApiDocs;
import org.eclipse.tractusx.managedidentitywallets.apidocs.PresentationControllerApiDocs.PostVerifiablePresentationApiDocs;
import org.eclipse.tractusx.managedidentitywallets.apidocs.PresentationControllerApiDocs.PostVerifiablePresentationValidationApiDocs;
import org.eclipse.tractusx.managedidentitywallets.constant.RestURI;
Expand Down Expand Up @@ -102,12 +102,13 @@ public ResponseEntity<Map<String, Object>> validatePresentation(@RequestBody Map
* @param stsToken the STS token with required scopes
* @return the VP response entity
*/
@SneakyThrows

@GetMapping(path = RestURI.API_PRESENTATIONS_IATP, produces = { MediaType.APPLICATION_JSON_VALUE })
// @SecureTokenControllerApiDoc.PostSecureTokenDoc TODO create API docs
public ResponseEntity<Map<String, Object>> createPresentation(@RequestHeader(name = "Authorization") String stsToken) {
@GetVerifiablePresentationIATPApiDocs
public ResponseEntity<Map<String, Object>> createPresentation(@RequestHeader(name = "Authorization") String stsToken,
@RequestParam(name = "asJwt", required = false, defaultValue = "false") boolean asJwt) {
SignedJWT accessToken = getAccessToken(stsToken);
Map<String, Object> vp = presentationService.createVpWithRequiredScopes(accessToken);
Map<String, Object> vp = presentationService.createVpWithRequiredScopes(accessToken, asJwt);
return ResponseEntity.ok(vp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private boolean validateCredential(VerifiableCredential credential) {
return isValid;
}

public Map<String, Object> createVpWithRequiredScopes(SignedJWT innerJWT) {
public Map<String, Object> createVpWithRequiredScopes(SignedJWT innerJWT, boolean asJwt) {
List<HoldersCredential> holdersCredentials = new ArrayList<>();
List<String> missingVCTypes = new ArrayList<>();
List<VerifiableCredential> verifiableCredentials = new ArrayList<>();
Expand Down Expand Up @@ -317,7 +317,7 @@ public Map<String, Object> createVpWithRequiredScopes(SignedJWT innerJWT) {

holdersCredentials.forEach(c -> verifiableCredentials.add(c.getData()));

return buildVP(false, jwtClaimsSet.getAudience().get(0), callerWallet.getBpn(),
return buildVP(asJwt, jwtClaimsSet.getAudience().get(0), callerWallet.getBpn(),
callerWallet, verifiableCredentials);
}

Expand Down

0 comments on commit 9dc628b

Please sign in to comment.