@bedrock/vc-delivery 5.3.4 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/oid4/http.js +37 -23
- package/package.json +1 -1
package/lib/oid4/http.js
CHANGED
|
@@ -62,8 +62,17 @@ export async function createRoutes({
|
|
|
62
62
|
authorizationResponse: `${openIdRoute}/client/authorization/response`
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
// urlencoded body parser
|
|
66
|
-
const
|
|
65
|
+
// urlencoded body parser
|
|
66
|
+
const urlencodedSmall = bodyParser.urlencoded({
|
|
67
|
+
// (extended=true for rich JSON-like representation)
|
|
68
|
+
extended: true
|
|
69
|
+
});
|
|
70
|
+
const urlencodedLarge = bodyParser.urlencoded({
|
|
71
|
+
// (extended=true for rich JSON-like representation)
|
|
72
|
+
extended: true,
|
|
73
|
+
// allow larger payloads
|
|
74
|
+
limit: '10MB'
|
|
75
|
+
});
|
|
67
76
|
|
|
68
77
|
/* Note: The well-known metadata paths for the OID4VCI spec have been
|
|
69
78
|
specified in at least two different ways over time, including
|
|
@@ -142,7 +151,7 @@ export async function createRoutes({
|
|
|
142
151
|
app.post(
|
|
143
152
|
routes.token,
|
|
144
153
|
cors(),
|
|
145
|
-
|
|
154
|
+
urlencodedSmall,
|
|
146
155
|
validate({bodySchema: openIdTokenBody}),
|
|
147
156
|
getConfigMiddleware,
|
|
148
157
|
getExchange,
|
|
@@ -194,28 +203,33 @@ export async function createRoutes({
|
|
|
194
203
|
return;
|
|
195
204
|
}
|
|
196
205
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
// send VC(s)
|
|
207
|
+
const {
|
|
208
|
+
response: {verifiablePresentation: {verifiableCredential}},
|
|
209
|
+
format
|
|
210
|
+
} = result;
|
|
211
|
+
// FIXME: "format" doesn't seem to be in the spec anymore (draft 14+)...
|
|
212
|
+
const credentials = verifiableCredential.map(vc => {
|
|
213
|
+
// parse any enveloped VC
|
|
214
|
+
let credential;
|
|
215
|
+
if(vc.type === 'EnvelopedVerifiableCredential' &&
|
|
216
|
+
vc.id?.startsWith('data:application/jwt,')) {
|
|
217
|
+
credential = vc.id.slice('data:application/jwt,'.length);
|
|
218
|
+
} else {
|
|
219
|
+
credential = vc;
|
|
220
|
+
}
|
|
221
|
+
return credential;
|
|
222
|
+
});
|
|
203
223
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
credential = vc.id.slice('data:application/jwt,'.length);
|
|
209
|
-
} else {
|
|
210
|
-
credential = vc;
|
|
211
|
-
}
|
|
224
|
+
/* Note: The `/credential` route only supports sending VCs of the same
|
|
225
|
+
type, but there can be more than one of them. The above `isBatchRequest`
|
|
226
|
+
check will ensure that the workflow used here only allows a single
|
|
227
|
+
credential request, indicating a single type. */
|
|
212
228
|
|
|
213
229
|
// send OID4VCI response
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
credential
|
|
218
|
-
});
|
|
230
|
+
const response = credentials.length === 1 ?
|
|
231
|
+
{format, credential: credentials[0]} : {format, credentials};
|
|
232
|
+
res.json(response);
|
|
219
233
|
}));
|
|
220
234
|
|
|
221
235
|
// a credential delivery server endpoint
|
|
@@ -316,7 +330,7 @@ export async function createRoutes({
|
|
|
316
330
|
app.post(
|
|
317
331
|
routes.authorizationResponse,
|
|
318
332
|
cors(),
|
|
319
|
-
|
|
333
|
+
urlencodedLarge,
|
|
320
334
|
validate({bodySchema: openIdAuthorizationResponseBody()}),
|
|
321
335
|
getConfigMiddleware,
|
|
322
336
|
getExchange,
|