Skip to content

Commit

Permalink
feat: implement authenticate for vc api (#215)
Browse files Browse the repository at this point in the history
<!--
  For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for
further details.
  
  For a timely review/response, please avoid force-pushing additional
  commits if your PR already received reviews or comments.
  
Before submitting a Pull Request, please ensure you've done the
following:
- 📖 Read the [Contributing
Guide](https://github.com/uncefact/project-vckit/blob/main/CONTRIBUTING.md).
- 📖 Read the [Code of
Conduct](https://github.com/uncefact/project-vckit/blob/main/CODE_OF_CONDUCT.md).
  - 👷‍♀️ Create small PRs. In most cases, this will be possible.
  - ✅ Provide tests for your changes.
- 📝 Use descriptive commit messages following [conventional
commits](https://www.conventionalcommits.org/en/v1.0.0/).
- 📗 Update any related documentation and include any relevant
screenshots.
-->

## What type of PR is this? (check all applicable)

- [x] 🍕 Feature
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 🎨 Style
- [ ] 🧑‍💻 Code Refactor
- [ ] 🔥 Performance Improvements
- [ ] ✅ Test
- [ ] 🤖 Build
- [ ] 🔁 CI
- [ ] 📦 Chore (Release)
- [ ] ⏩ Revert

## Description

<!-- 
Please do not leave this blank 
This PR [adds/removes/fixes/replaces] the [feature/bug/etc]. 
-->
This PR adds the authentication using API key for the APIs of vc-api
plugin
## Related Tickets & Documents
<!-- 
Please use this format link issue numbers: Fixes #123

https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->
https://github.com/gs-gs/fa-ag-trace/issues/621

## Mobile & Desktop Screenshots/Recordings

<!-- Visual changes require screenshots -->


## Added tests?

- [ ] 👍 yes
- [ ] 🙅 no, because they aren't needed
- [ ] 🙋 no, because I need help

## Added to documentation?

- [ ] 📜 README.md
- [ ] 📓 [vc-kit doc site](https://uncefact.github.io/vckit/)
- [ ] 📕 storybook
- [ ] 🙅 no documentation needed

## [optional] Are there any post-deployment tasks we need to perform?


<!-- note: PRs with deleted sections will be marked invalid -->

---------

Signed-off-by: Nam Hoang <hoangxuannam160493@gmail.com>
  • Loading branch information
namhoang1604 authored Sep 24, 2024
1 parent 0f2b1c9 commit 9b08b2c
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 91 deletions.
2 changes: 2 additions & 0 deletions packages/cli/default/agent.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,14 @@ server:
- $require: '@vckit/vc-api?t=function#V1VcRouter'
$args:
- basePath: :${PORT}
apiKey: ${API_KEY}

# VC API v2
- - /v2
- $require: '@vckit/vc-api?t=function#V2VcRouter'
$args:
- basePath: :${PORT}
apiKey: ${API_KEY}

# API base path
- - /messaging
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/default/default-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ server:
- $require: '@vckit/vc-api?t=function#V1VcRouter'
$args:
- basePath: :3332
apiKey: ${API_KEY}

# VC API v2
- - /v2
- $require: '@vckit/vc-api?t=function#V2VcRouter'
$args:
- basePath: :3332
apiKey: ${API_KEY}

# API base path
- - /messaging
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/default/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ server:
- $require: '@vckit/vc-api?t=function#V1VcRouter'
$args:
- basePath: :3332
apiKey: ${API_KEY}

# VC API v2
- - /v2
- $require: '@vckit/vc-api?t=function#V2VcRouter'
$args:
- basePath: :3332
apiKey: ${API_KEY}

# API base path
- - /messaging
Expand Down
2 changes: 2 additions & 0 deletions packages/vc-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ The router follows the `veramo` architecture, allowing you to configure it using
- $require: '@vckit/vc-api?t=function#V1VcRouter'
$args:
- basePath: :3332
apiKey: test123

# VC API v2
- - /v2
- $require: '@vckit/vc-api?t=function#V2VcRouter'
$args:
- basePath: :3332
apiKey: test123

## Test with test-suite

Expand Down
1 change: 1 addition & 0 deletions packages/vc-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@vckit/core-types": "workspace:^",
"@vckit/remote-server": "workspace:^",
"debug": "^4.3.4",
"did-resolver": "^4.1.0",
"express": "^4.18.2",
Expand Down
4 changes: 3 additions & 1 deletion packages/vc-api/src/v1-vc-api/v1-vc-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Router, json } from 'express';
import { VCApiSchemaRouter } from './vc-api-schema-router.js';
import { VCRouter } from './vc-router.js';
import { VCApiDocsRouter } from './vc-api-docs-router.js';
import { apiKeyAuth } from '@vckit/remote-server';

export function V1VcRouter(options: any): Router {
const router = Router();
router.use(VCRouter());
router.use(VCApiDocsRouter());
router.use(VCApiSchemaRouter(options));
router.use(apiKeyAuth(options.apiKey));
router.use(VCRouter());

return router;
}
4 changes: 3 additions & 1 deletion packages/vc-api/src/v2-vc-api/v2-vc-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Router, json } from 'express';
import { VCApiDocsRouter } from './vc-api-docs-router.js';
import { VCApiSchemaRouter } from './vc-api-schema-router.js';
import { VCRouter } from './vc-router.js';
import { apiKeyAuth } from '@vckit/remote-server';

export function V2VcRouter(options: any): Router {
const router = Router();
router.use(VCRouter());
router.use(VCApiDocsRouter());
router.use(VCApiSchemaRouter(options));
router.use(apiKeyAuth(options.apiKey));
router.use(VCRouter());

return router;
}
47 changes: 6 additions & 41 deletions packages/vc-api/src/vc-api-schemas/vc-api-v2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ paths:
get:
tags:
- holder_Credentials
security:
- oAuth2: []
summary: Gets a credential or verifiable credential by ID
operationId: getCredential
parameters:
Expand Down Expand Up @@ -63,8 +61,6 @@ paths:
delete:
tags:
- holder_Credentials
security:
- oAuth2: []
summary: Deletes a credential or verifiable credential by ID
operationId: deleteCredential
parameters:
Expand All @@ -90,8 +86,6 @@ paths:
get:
tags:
- holder_Credentials
security:
- oAuth2: []
summary: Gets list of credentials or verifiable credentials
operationId: getCredentials
parameters:
Expand Down Expand Up @@ -128,8 +122,6 @@ paths:
post:
tags:
- holder_Credentials
security:
- oAuth2: []
summary: Derives a credential and returns it in the response body.
operationId: deriveCredential
description: Derives a credential and returns it in the response body.
Expand Down Expand Up @@ -157,8 +149,6 @@ paths:
tags:
- holder_Presentations
summary: Gets a presentation or verifiable presentation by ID
security:
- oAuth2: []
operationId: getPresentation
parameters:
- $ref: '#/components/parameters/ObjectId'
Expand Down Expand Up @@ -187,8 +177,6 @@ paths:
tags:
- holder_Presentations
summary: Deletes a presentation or verifiable presentation by ID
security:
- oAuth2: []
operationId: deletePresentation
parameters:
- $ref: '#/components/parameters/ObjectId'
Expand All @@ -214,8 +202,6 @@ paths:
tags:
- holder_Presentations
summary: Gets list of presentations or verifiable presentations
security:
- oAuth2: []
operationId: getPresentations
parameters:
- in: query
Expand Down Expand Up @@ -252,8 +238,6 @@ paths:
summary: Proves a presentation and returns it in the response body.
tags:
- holder_Presentations
security:
- oAuth2: []
operationId: provePresentation
description: Proves a presentation and returns it in the response body.
requestBody:
Expand All @@ -280,8 +264,6 @@ paths:
endpoint.
tags:
- holder_Exchanges
security:
- oAuth2: []
operationId: discoverExchanges
description: >-
This endpoint returns an array of the exchange-ids (path endpoints)
Expand Down Expand Up @@ -367,8 +349,6 @@ paths:
summary: Initiates an exchange of information.
tags:
- holder_Exchanges
security:
- oAuth2: []
operationId: initiateExchange
description: >-
A client can use this endpoint to initiate an exchange of a particular
Expand Down Expand Up @@ -411,8 +391,6 @@ paths:
summary: Receives information related to an existing exchange.
tags:
- holder_Exchanges
security:
- oAuth2: []
operationId: receiveExchangeData
description: >-
A client can use this endpoint to continue the exchange of information
Expand Down Expand Up @@ -453,8 +431,6 @@ paths:
summary: Issues a credential and returns it in the response body.
tags:
- issuer_Credentials
security:
- oAuth2: []
operationId: issueCredential
description: Issues a credential and returns it in the response body.
requestBody:
Expand All @@ -479,10 +455,6 @@ paths:
summary: Updates the status of an issued credential
tags:
- issuer_Credentials
security:
- networkAuth: []
- oAuth2: []
- zCap: []
operationId: updateCredentialStatus
description: Updates the status of an issued credential.
requestBody:
Expand All @@ -507,10 +479,6 @@ paths:
response body.
tags:
- verifier_Credentials
security:
- networkAuth: []
- oAuth2: []
- zCap: []
operationId: verifyCredential
description: >-
Verifies a verifiableCredential and returns a verificationResult in the
Expand Down Expand Up @@ -539,10 +507,6 @@ paths:
verificationResult in the response body.
tags:
- verifier_Presentations
security:
- networkAuth: []
- oAuth2: []
- zCap: []
operationId: verifyPresentation
description: >-
Verifies a verifiablePresentation and returns a verificationResult in
Expand Down Expand Up @@ -575,11 +539,10 @@ paths:
'500':
description: Internal Server Error
components:
# securitySchemes:
# oAuth2:
# type: http
# scheme: bearer
# bearerFormat: VcapiOauth2
securitySchemes:
auth:
type: http
scheme: bearer
schemas:
DeriveCredentialRequest:
type: object
Expand Down Expand Up @@ -1130,6 +1093,8 @@ components:
pattern: z[1-9A-HJ-NP-Za-km-z]{21,22}
- type: string
pattern: u[a-zA-Z0-9_-]{22,23}
security:
- auth: []
x-tagGroups:
- name: holder
tags:
Expand Down
Loading

0 comments on commit 9b08b2c

Please sign in to comment.