@sphereon/jarm 0.16.1-unstable.105
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/LICENSE +201 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/jarm-auth-response/c-jarm-auth-response.d.ts +55 -0
- package/dist/jarm-auth-response/c-jarm-auth-response.d.ts.map +1 -0
- package/dist/jarm-auth-response/c-jarm-auth-response.js +45 -0
- package/dist/jarm-auth-response/c-jarm-auth-response.js.map +1 -0
- package/dist/jarm-auth-response/index.d.ts +5 -0
- package/dist/jarm-auth-response/index.d.ts.map +1 -0
- package/dist/jarm-auth-response/index.js +21 -0
- package/dist/jarm-auth-response/index.js.map +1 -0
- package/dist/jarm-auth-response/jarm-auth-response.d.ts +48 -0
- package/dist/jarm-auth-response/jarm-auth-response.d.ts.map +1 -0
- package/dist/jarm-auth-response/jarm-auth-response.js +113 -0
- package/dist/jarm-auth-response/jarm-auth-response.js.map +1 -0
- package/dist/jarm-auth-response/v-jarm-auth-response-params.d.ts +31 -0
- package/dist/jarm-auth-response/v-jarm-auth-response-params.d.ts.map +1 -0
- package/dist/jarm-auth-response/v-jarm-auth-response-params.js +67 -0
- package/dist/jarm-auth-response/v-jarm-auth-response-params.js.map +1 -0
- package/dist/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.d.ts +18 -0
- package/dist/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.d.ts.map +1 -0
- package/dist/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.js +38 -0
- package/dist/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.js.map +1 -0
- package/dist/jarm-auth-response-send/index.d.ts +2 -0
- package/dist/jarm-auth-response-send/index.d.ts.map +1 -0
- package/dist/jarm-auth-response-send/index.js +18 -0
- package/dist/jarm-auth-response-send/index.js.map +1 -0
- package/dist/jarm-auth-response-send/jarm-auth-response-send.d.ts +16 -0
- package/dist/jarm-auth-response-send/jarm-auth-response-send.d.ts.map +1 -0
- package/dist/jarm-auth-response-send/jarm-auth-response-send.js +67 -0
- package/dist/jarm-auth-response-send/jarm-auth-response-send.js.map +1 -0
- package/dist/metadata/index.d.ts +4 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +20 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/jarm-validate-metadata.d.ts +70 -0
- package/dist/metadata/jarm-validate-metadata.d.ts.map +1 -0
- package/dist/metadata/jarm-validate-metadata.js +98 -0
- package/dist/metadata/jarm-validate-metadata.js.map +1 -0
- package/dist/metadata/v-jarm-client-metadata.d.ts +34 -0
- package/dist/metadata/v-jarm-client-metadata.d.ts.map +1 -0
- package/dist/metadata/v-jarm-client-metadata.js +44 -0
- package/dist/metadata/v-jarm-client-metadata.js.map +1 -0
- package/dist/metadata/v-jarm-server-metadata.d.ts +11 -0
- package/dist/metadata/v-jarm-server-metadata.d.ts.map +1 -0
- package/dist/metadata/v-jarm-server-metadata.js +36 -0
- package/dist/metadata/v-jarm-server-metadata.js.map +1 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +34 -0
- package/dist/utils.js.map +1 -0
- package/dist/v-response-mode-registry.d.ts +30 -0
- package/dist/v-response-mode-registry.d.ts.map +1 -0
- package/dist/v-response-mode-registry.js +90 -0
- package/dist/v-response-mode-registry.js.map +1 -0
- package/dist/v-response-type-registry.d.ts +9 -0
- package/dist/v-response-type-registry.d.ts.map +1 -0
- package/dist/v-response-type-registry.js +38 -0
- package/dist/v-response-type-registry.js.map +1 -0
- package/lib/index.ts +3 -0
- package/lib/jarm-auth-response/c-jarm-auth-response.ts +41 -0
- package/lib/jarm-auth-response/index.ts +4 -0
- package/lib/jarm-auth-response/jarm-auth-response.ts +106 -0
- package/lib/jarm-auth-response/v-jarm-auth-response-params.ts +62 -0
- package/lib/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.ts +26 -0
- package/lib/jarm-auth-response-send/index.ts +1 -0
- package/lib/jarm-auth-response-send/jarm-auth-response-send.ts +76 -0
- package/lib/metadata/index.ts +3 -0
- package/lib/metadata/jarm-validate-metadata.ts +80 -0
- package/lib/metadata/v-jarm-client-metadata.ts +42 -0
- package/lib/metadata/v-jarm-server-metadata.ts +29 -0
- package/lib/utils.ts +42 -0
- package/lib/v-response-mode-registry.ts +81 -0
- package/lib/v-response-type-registry.ts +23 -0
- package/package.json +44 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.vJarmServerMetadata = void 0;
|
|
27
|
+
const v = __importStar(require("valibot"));
|
|
28
|
+
/**
|
|
29
|
+
* Authorization servers SHOULD publish the supported algorithms for signing and encrypting the JWT of an authorization response by utilizing OAuth 2.0 Authorization Server Metadata [RFC8414] parameters.
|
|
30
|
+
*/
|
|
31
|
+
exports.vJarmServerMetadata = v.object({
|
|
32
|
+
authorization_signing_alg_values_supported: v.pipe(v.array(v.string()), v.description('JSON array containing a list of the JWS [RFC7515] signing algorithms (alg values) JWA [RFC7518] supported by the authorization endpoint to sign the response.')),
|
|
33
|
+
authorization_encryption_alg_values_supported: v.pipe(v.array(v.string()), v.description('JSON array containing a list of the JWE [RFC7516] encryption algorithms (alg values) JWA [RFC7518] supported by the authorization endpoint to encrypt the response.')),
|
|
34
|
+
authorization_encryption_enc_values_supported: v.pipe(v.array(v.string()), v.description('JSON array containing a list of the JWE [RFC7516] encryption algorithms (enc values) JWA [RFC7518] supported by the authorization endpoint to encrypt the response.')),
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=v-jarm-server-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v-jarm-server-metadata.js","sourceRoot":"","sources":["../../lib/metadata/v-jarm-server-metadata.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAE7B;;GAEG;AACU,QAAA,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,0CAA0C,EAAE,CAAC,CAAC,IAAI,CAChD,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EACnB,CAAC,CAAC,WAAW,CACX,+JAA+J,CAChK,CACF;IAED,6CAA6C,EAAE,CAAC,CAAC,IAAI,CACnD,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EACnB,CAAC,CAAC,WAAW,CACX,qKAAqK,CACtK,CACF;IAED,6CAA6C,EAAE,CAAC,CAAC,IAAI,CACnD,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,EACnB,CAAC,CAAC,WAAW,CACX,qKAAqK,CACtK,CACF;CACF,CAAC,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare function appendQueryParams(input: {
|
|
2
|
+
url: URL;
|
|
3
|
+
params: Record<string, string | number | boolean>;
|
|
4
|
+
}): URL;
|
|
5
|
+
export declare function appendFragmentParams(input: {
|
|
6
|
+
url: URL;
|
|
7
|
+
fragments: Record<string, string | number | boolean>;
|
|
8
|
+
}): URL;
|
|
9
|
+
interface AssertValueSupported<T> {
|
|
10
|
+
supported: T[];
|
|
11
|
+
actual: T;
|
|
12
|
+
error: Error;
|
|
13
|
+
required: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function assertValueSupported<T>(input: AssertValueSupported<T>): T | undefined;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;CAAE,OASvG;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE;IAAE,GAAG,EAAE,GAAG,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;CAAE,OAe7G;AAED,UAAU,oBAAoB,CAAC,CAAC;IAC9B,SAAS,EAAE,CAAC,EAAE,CAAC;IACf,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAMrF"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertValueSupported = exports.appendFragmentParams = exports.appendQueryParams = void 0;
|
|
4
|
+
function appendQueryParams(input) {
|
|
5
|
+
const { url, params } = input;
|
|
6
|
+
// Append the new query parameters from the params object
|
|
7
|
+
for (const [key, value] of Object.entries(params)) {
|
|
8
|
+
url.searchParams.append(key, encodeURIComponent(value));
|
|
9
|
+
}
|
|
10
|
+
return url;
|
|
11
|
+
}
|
|
12
|
+
exports.appendQueryParams = appendQueryParams;
|
|
13
|
+
function appendFragmentParams(input) {
|
|
14
|
+
const { url, fragments } = input;
|
|
15
|
+
// Convert existing fragment to an object and remove the leading '#'
|
|
16
|
+
const fragmentParams = new URLSearchParams(url.hash.slice(1)); // Remove the leading '#' from the fragment
|
|
17
|
+
// Append the new fragments from the fragments object
|
|
18
|
+
for (const [key, value] of Object.entries(fragments)) {
|
|
19
|
+
fragmentParams.append(key, encodeURIComponent(value));
|
|
20
|
+
}
|
|
21
|
+
// Rebuild the fragment string and assign it to the URL
|
|
22
|
+
url.hash = fragmentParams.toString();
|
|
23
|
+
return url;
|
|
24
|
+
}
|
|
25
|
+
exports.appendFragmentParams = appendFragmentParams;
|
|
26
|
+
function assertValueSupported(input) {
|
|
27
|
+
const { required, error, supported, actual } = input;
|
|
28
|
+
const intersection = supported.find((value) => value === actual);
|
|
29
|
+
if (required && !intersection)
|
|
30
|
+
throw error;
|
|
31
|
+
return intersection;
|
|
32
|
+
}
|
|
33
|
+
exports.assertValueSupported = assertValueSupported;
|
|
34
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,iBAAiB,CAAC,KAAsE;IACtG,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IAE9B,yDAAyD;IACzD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AATD,8CASC;AAED,SAAgB,oBAAoB,CAAC,KAAyE;IAC5G,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAEjC,oEAAoE;IACpE,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,2CAA2C;IAE1G,qDAAqD;IACrD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACrD,cAAc,CAAC,MAAM,CAAC,GAAG,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,uDAAuD;IACvD,GAAG,CAAC,IAAI,GAAG,cAAc,CAAC,QAAQ,EAAE,CAAC;IAErC,OAAO,GAAG,CAAC;AACb,CAAC;AAfD,oDAeC;AASD,SAAgB,oBAAoB,CAAI,KAA8B;IACpE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACrD,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;IAEjE,IAAI,QAAQ,IAAI,CAAC,YAAY;QAAE,MAAM,KAAK,CAAC;IAC3C,OAAO,YAAY,CAAC;AACtB,CAAC;AAND,oDAMC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
import type { ResponseTypeOut } from './v-response-type-registry.js';
|
|
3
|
+
export declare const vJarmResponseMode: v.PicklistSchema<["jwt", "query.jwt", "fragment.jwt", "form_post.jwt"], undefined>;
|
|
4
|
+
export type JarmResponseMode = v.InferInput<typeof vJarmResponseMode>;
|
|
5
|
+
export declare const vOpenid4vpResponseMode: v.PicklistSchema<["direct_post"], undefined>;
|
|
6
|
+
export type Openid4vpResponseMode = v.InferInput<typeof vOpenid4vpResponseMode>;
|
|
7
|
+
/**
|
|
8
|
+
* * 'direct_post.jwt' The response is send as HTTP POST request using the application/x-www-form-urlencoded content type. The body contains a single parameter response which is the JWT encoded Response as defined in JARM 4.1
|
|
9
|
+
*/
|
|
10
|
+
export declare const vOpenid4vpJarmResponseMode: v.PicklistSchema<["direct_post.jwt"], undefined>;
|
|
11
|
+
export type Openid4vpJarmResponseMode = v.InferInput<typeof vOpenid4vpJarmResponseMode>;
|
|
12
|
+
/**
|
|
13
|
+
* The use of this parameter is NOT RECOMMENDED when the Response Mode that would be requested is the default mode specified for the Response Type.
|
|
14
|
+
* * 'query' In this mode, Authorization Response parameters are encoded in the query string added to the redirect_uri when redirecting back to the Client.
|
|
15
|
+
* * 'fragment' In this mode, Authorization Response parameters are encoded in the fragment added to the redirect_uri when redirecting back to the Client.
|
|
16
|
+
* * 'direct_post' the Authorization Response is send to an endpoint controlled by the Verifier via an HTTP POST request.
|
|
17
|
+
*/
|
|
18
|
+
export declare const vResponseMode: v.SchemaWithPipe<[v.PicklistSchema<["query", "fragment", "direct_post", "jwt", "query.jwt", "fragment.jwt", "form_post.jwt", "direct_post.jwt"], undefined>, v.DescriptionAction<"jwt" | "query.jwt" | "fragment.jwt" | "form_post.jwt" | "direct_post" | "direct_post.jwt" | "query" | "fragment", "Informs the Authorization Server of the mechanism to be used for returning parameters from the Authorization Endpoint.">]>;
|
|
19
|
+
export type ResponseMode = v.InferInput<typeof vResponseMode>;
|
|
20
|
+
export declare const getDefaultResponseMode: (input: {
|
|
21
|
+
response_type: ResponseTypeOut;
|
|
22
|
+
}) => 'query' | 'fragment';
|
|
23
|
+
export declare const getJarmDefaultResponseMode: (input: {
|
|
24
|
+
response_type: ResponseTypeOut;
|
|
25
|
+
}) => 'query.jwt' | 'fragment.jwt';
|
|
26
|
+
export declare const validateResponseMode: (input: {
|
|
27
|
+
response_type: ResponseTypeOut;
|
|
28
|
+
response_mode: ResponseMode;
|
|
29
|
+
}) => void;
|
|
30
|
+
//# sourceMappingURL=v-response-mode-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v-response-mode-registry.d.ts","sourceRoot":"","sources":["../lib/v-response-mode-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,eAAO,MAAM,iBAAiB,oFAAoE,CAAC;AACnG,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEtE,eAAO,MAAM,sBAAsB,8CAA8B,CAAC;AAClE,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,0BAA0B,kDAAkC,CAAC;AAC1E,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAExF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,iaAGzB,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AAkB9D,eAAO,MAAM,sBAAsB,UAAW;IAAE,aAAa,EAAE,eAAe,CAAA;CAAE,KAAG,OAAO,GAAG,UAiB5F,CAAC;AAEF,eAAO,MAAM,0BAA0B,UAAW;IAAE,aAAa,EAAE,eAAe,CAAA;CAAE,KAAG,WAAW,GAAG,cASpG,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW;IAAE,aAAa,EAAE,eAAe,CAAC;IAAC,aAAa,EAAE,YAAY,CAAA;CAAE,SAM1G,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.validateResponseMode = exports.getJarmDefaultResponseMode = exports.getDefaultResponseMode = exports.vResponseMode = exports.vOpenid4vpJarmResponseMode = exports.vOpenid4vpResponseMode = exports.vJarmResponseMode = void 0;
|
|
27
|
+
const v = __importStar(require("valibot"));
|
|
28
|
+
exports.vJarmResponseMode = v.picklist(['jwt', 'query.jwt', 'fragment.jwt', 'form_post.jwt']);
|
|
29
|
+
exports.vOpenid4vpResponseMode = v.picklist(['direct_post']);
|
|
30
|
+
/**
|
|
31
|
+
* * 'direct_post.jwt' The response is send as HTTP POST request using the application/x-www-form-urlencoded content type. The body contains a single parameter response which is the JWT encoded Response as defined in JARM 4.1
|
|
32
|
+
*/
|
|
33
|
+
exports.vOpenid4vpJarmResponseMode = v.picklist(['direct_post.jwt']);
|
|
34
|
+
/**
|
|
35
|
+
* The use of this parameter is NOT RECOMMENDED when the Response Mode that would be requested is the default mode specified for the Response Type.
|
|
36
|
+
* * 'query' In this mode, Authorization Response parameters are encoded in the query string added to the redirect_uri when redirecting back to the Client.
|
|
37
|
+
* * 'fragment' In this mode, Authorization Response parameters are encoded in the fragment added to the redirect_uri when redirecting back to the Client.
|
|
38
|
+
* * 'direct_post' the Authorization Response is send to an endpoint controlled by the Verifier via an HTTP POST request.
|
|
39
|
+
*/
|
|
40
|
+
exports.vResponseMode = v.pipe(v.picklist(['query', 'fragment', ...exports.vOpenid4vpResponseMode.options, ...exports.vJarmResponseMode.options, ...exports.vOpenid4vpJarmResponseMode.options]), v.description('Informs the Authorization Server of the mechanism to be used for returning parameters from the Authorization Endpoint.'));
|
|
41
|
+
const getDisAllowedResponseModes = (input) => {
|
|
42
|
+
const { response_type } = input;
|
|
43
|
+
switch (response_type) {
|
|
44
|
+
case 'code token':
|
|
45
|
+
return ['query'];
|
|
46
|
+
case 'code id_token':
|
|
47
|
+
return ['query'];
|
|
48
|
+
case 'id_token token':
|
|
49
|
+
return ['query'];
|
|
50
|
+
case 'code id_token token':
|
|
51
|
+
return ['query'];
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
};
|
|
55
|
+
const getDefaultResponseMode = (input) => {
|
|
56
|
+
const { response_type } = input;
|
|
57
|
+
switch (response_type) {
|
|
58
|
+
case 'code':
|
|
59
|
+
case 'none':
|
|
60
|
+
return 'query';
|
|
61
|
+
case 'token':
|
|
62
|
+
case 'id_token':
|
|
63
|
+
case 'code token':
|
|
64
|
+
case 'code id_token':
|
|
65
|
+
case 'id_token token':
|
|
66
|
+
case 'code id_token token':
|
|
67
|
+
case 'vp_token':
|
|
68
|
+
case 'id_token vp_token':
|
|
69
|
+
return 'fragment';
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
exports.getDefaultResponseMode = getDefaultResponseMode;
|
|
73
|
+
const getJarmDefaultResponseMode = (input) => {
|
|
74
|
+
const responseMode = (0, exports.getDefaultResponseMode)(input);
|
|
75
|
+
switch (responseMode) {
|
|
76
|
+
case 'query':
|
|
77
|
+
return 'query.jwt';
|
|
78
|
+
case 'fragment':
|
|
79
|
+
return 'fragment.jwt';
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.getJarmDefaultResponseMode = getJarmDefaultResponseMode;
|
|
83
|
+
const validateResponseMode = (input) => {
|
|
84
|
+
const disallowedResponseModes = getDisAllowedResponseModes(input);
|
|
85
|
+
if (disallowedResponseModes === null || disallowedResponseModes === void 0 ? void 0 : disallowedResponseModes.includes(input.response_mode)) {
|
|
86
|
+
throw new Error(`Response_type '${input.response_type}' is not compatible with response_mode '${input.response_mode}'.`);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
exports.validateResponseMode = validateResponseMode;
|
|
90
|
+
//# sourceMappingURL=v-response-mode-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v-response-mode-registry.js","sourceRoot":"","sources":["../lib/v-response-mode-registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAIhB,QAAA,iBAAiB,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC,CAAC;AAGtF,QAAA,sBAAsB,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;AAGlE;;GAEG;AACU,QAAA,0BAA0B,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAG1E;;;;;GAKG;AACU,QAAA,aAAa,GAAG,CAAC,CAAC,IAAI,CACjC,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,8BAAsB,CAAC,OAAO,EAAE,GAAG,yBAAiB,CAAC,OAAO,EAAE,GAAG,kCAA0B,CAAC,OAAO,CAAC,CAAC,EACzI,CAAC,CAAC,WAAW,CAAC,wHAAwH,CAAC,CACxI,CAAC;AAGF,MAAM,0BAA0B,GAAG,CAAC,KAAyC,EAAiD,EAAE;IAC9H,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IAEhC,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,YAAY;YACf,OAAO,CAAC,OAAO,CAAC,CAAC;QACnB,KAAK,eAAe;YAClB,OAAO,CAAC,OAAO,CAAC,CAAC;QACnB,KAAK,gBAAgB;YACnB,OAAO,CAAC,OAAO,CAAC,CAAC;QACnB,KAAK,qBAAqB;YACxB,OAAO,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEK,MAAM,sBAAsB,GAAG,CAAC,KAAyC,EAAwB,EAAE;IACxG,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IAEhC,QAAQ,aAAa,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,OAAO,CAAC;QACjB,KAAK,OAAO,CAAC;QACb,KAAK,UAAU,CAAC;QAChB,KAAK,YAAY,CAAC;QAClB,KAAK,eAAe,CAAC;QACrB,KAAK,gBAAgB,CAAC;QACtB,KAAK,qBAAqB,CAAC;QAC3B,KAAK,UAAU,CAAC;QAChB,KAAK,mBAAmB;YACtB,OAAO,UAAU,CAAC;IACtB,CAAC;AACH,CAAC,CAAC;AAjBW,QAAA,sBAAsB,0BAiBjC;AAEK,MAAM,0BAA0B,GAAG,CAAC,KAAyC,EAAgC,EAAE;IACpH,MAAM,YAAY,GAAG,IAAA,8BAAsB,EAAC,KAAK,CAAC,CAAC;IAEnD,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,OAAO;YACV,OAAO,WAAW,CAAC;QACrB,KAAK,UAAU;YACb,OAAO,cAAc,CAAC;IAC1B,CAAC;AACH,CAAC,CAAC;AATW,QAAA,0BAA0B,8BASrC;AAEK,MAAM,oBAAoB,GAAG,CAAC,KAAsE,EAAE,EAAE;IAC7G,MAAM,uBAAuB,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;IAElE,IAAI,uBAAuB,aAAvB,uBAAuB,uBAAvB,uBAAuB,CAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,kBAAkB,KAAK,CAAC,aAAa,2CAA2C,KAAK,CAAC,aAAa,IAAI,CAAC,CAAC;IAC3H,CAAC;AACH,CAAC,CAAC;AANW,QAAA,oBAAoB,wBAM/B"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
export declare const oAuthResponseTypes: v.PicklistSchema<["code", "token"], undefined>;
|
|
3
|
+
export declare const oAuthMRTEPResponseTypes: v.PicklistSchema<["none", "id_token", "code token", "code id_token", "id_token token", "code id_token token"], undefined>;
|
|
4
|
+
export declare const openid4vpResponseTypes: v.PicklistSchema<["vp_token", "id_token vp_token"], undefined>;
|
|
5
|
+
export declare const vTransformedResponseTypes: v.PicklistSchema<["vp_token", "id_token vp_token", "code", "token", "none", "id_token", "code token", "code id_token", "id_token token", "code id_token token"], undefined>;
|
|
6
|
+
export declare const vResponseType: v.SchemaWithPipe<[v.StringSchema<undefined>, v.TransformAction<string, string>, v.PicklistSchema<["vp_token", "id_token vp_token", "code", "token", "none", "id_token", "code token", "code id_token", "id_token token", "code id_token token"], undefined>]>;
|
|
7
|
+
export type ResponseType = v.InferInput<typeof vTransformedResponseTypes>;
|
|
8
|
+
export type ResponseTypeOut = v.InferOutput<typeof vTransformedResponseTypes>;
|
|
9
|
+
//# sourceMappingURL=v-response-type-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v-response-type-registry.d.ts","sourceRoot":"","sources":["../lib/v-response-type-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,eAAO,MAAM,kBAAkB,gDAAgC,CAAC;AAGhE,eAAO,MAAM,uBAAuB,2HAA2G,CAAC;AAEhJ,eAAO,MAAM,sBAAsB,gEAAgD,CAAC;AAEpF,eAAO,MAAM,yBAAyB,6KAIpC,CAAC;AAEH,eAAO,MAAM,aAAa,+PAIzB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC1E,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,yBAAyB,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.vResponseType = exports.vTransformedResponseTypes = exports.openid4vpResponseTypes = exports.oAuthMRTEPResponseTypes = exports.oAuthResponseTypes = void 0;
|
|
27
|
+
const v = __importStar(require("valibot"));
|
|
28
|
+
exports.oAuthResponseTypes = v.picklist(['code', 'token']);
|
|
29
|
+
// NOTE: MAKE SURE THAT THE RESPONSE TYPES ARE SORTED CORRECTLY
|
|
30
|
+
exports.oAuthMRTEPResponseTypes = v.picklist(['none', 'id_token', 'code token', 'code id_token', 'id_token token', 'code id_token token']);
|
|
31
|
+
exports.openid4vpResponseTypes = v.picklist(['vp_token', 'id_token vp_token']);
|
|
32
|
+
exports.vTransformedResponseTypes = v.picklist([
|
|
33
|
+
...exports.openid4vpResponseTypes.options,
|
|
34
|
+
...exports.oAuthResponseTypes.options,
|
|
35
|
+
...exports.oAuthMRTEPResponseTypes.options,
|
|
36
|
+
]);
|
|
37
|
+
exports.vResponseType = v.pipe(v.string(), v.transform((val) => val.split(' ').sort().join(' ')), exports.vTransformedResponseTypes);
|
|
38
|
+
//# sourceMappingURL=v-response-type-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v-response-type-registry.js","sourceRoot":"","sources":["../lib/v-response-type-registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAEhB,QAAA,kBAAkB,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhE,+DAA+D;AAClD,QAAA,uBAAuB,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAEnI,QAAA,sBAAsB,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAEvE,QAAA,yBAAyB,GAAG,CAAC,CAAC,QAAQ,CAAC;IAClD,GAAG,8BAAsB,CAAC,OAAO;IACjC,GAAG,0BAAkB,CAAC,OAAO;IAC7B,GAAG,+BAAuB,CAAC,OAAO;CACnC,CAAC,CAAC;AAEU,QAAA,aAAa,GAAG,CAAC,CAAC,IAAI,CACjC,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACrD,iCAAyB,CAC1B,CAAC"}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
|
|
3
|
+
import { vJarmResponseMode, vOpenid4vpJarmResponseMode } from '../v-response-mode-registry.js';
|
|
4
|
+
import { vResponseType } from '../v-response-type-registry.js';
|
|
5
|
+
|
|
6
|
+
import type { JarmAuthResponseParams } from './v-jarm-auth-response-params.js';
|
|
7
|
+
import type { JarmDirectPostJwtResponseParams } from './v-jarm-direct-post-jwt-auth-response-params.js';
|
|
8
|
+
|
|
9
|
+
export const vAuthRequestParams = v.looseObject({
|
|
10
|
+
state: v.optional(v.string()),
|
|
11
|
+
response_mode: v.optional(v.union([vJarmResponseMode, vOpenid4vpJarmResponseMode])),
|
|
12
|
+
client_id: v.string(),
|
|
13
|
+
response_type: vResponseType,
|
|
14
|
+
client_metadata: v.looseObject({
|
|
15
|
+
jwks: v.optional(
|
|
16
|
+
v.object({
|
|
17
|
+
keys: v.array(v.looseObject({ kid: v.optional(v.string()), kty: v.string() })),
|
|
18
|
+
}),
|
|
19
|
+
),
|
|
20
|
+
jwks_uri: v.optional(v.string()),
|
|
21
|
+
}),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type AuthRequestParams = v.InferInput<typeof vAuthRequestParams>;
|
|
25
|
+
|
|
26
|
+
export const vOAuthAuthRequestGetParamsOut = v.object({
|
|
27
|
+
authRequestParams: vAuthRequestParams,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export type OAuthAuthRequestGetParamsOut = v.InferOutput<typeof vOAuthAuthRequestGetParamsOut>;
|
|
31
|
+
|
|
32
|
+
export interface JarmDirectPostJwtAuthResponseValidationContext {
|
|
33
|
+
openid4vp: {
|
|
34
|
+
authRequest: {
|
|
35
|
+
getParams: (input: JarmAuthResponseParams | JarmDirectPostJwtResponseParams) => Promise<OAuthAuthRequestGetParamsOut>;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
jwe: {
|
|
39
|
+
decryptCompact: (input: { jwe: string; jwk: { kid: string } }) => Promise<{ plaintext: string }>;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { decodeProtectedHeader, isJwe, isJws } from '@sphereon/oid4vc-common';
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
|
|
4
|
+
import type { JarmDirectPostJwtResponseParams } from '../index.js';
|
|
5
|
+
|
|
6
|
+
import type { AuthRequestParams, JarmDirectPostJwtAuthResponseValidationContext } from './c-jarm-auth-response.js';
|
|
7
|
+
import { vJarmAuthResponseErrorParams } from './v-jarm-auth-response-params.js';
|
|
8
|
+
import { jarmAuthResponseDirectPostValidateParams, vJarmDirectPostJwtParams } from './v-jarm-direct-post-jwt-auth-response-params.js';
|
|
9
|
+
|
|
10
|
+
export interface JarmDirectPostJwtAuthResponseValidation {
|
|
11
|
+
/**
|
|
12
|
+
* The JARM response parameter conveyed either as url query param, fragment param, or application/x-www-form-urlencoded in the body of a post request
|
|
13
|
+
*/
|
|
14
|
+
response: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parseJarmAuthResponseParams = <Schema extends v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>>(
|
|
18
|
+
schema: Schema,
|
|
19
|
+
responseParams: unknown,
|
|
20
|
+
) => {
|
|
21
|
+
if (v.is(vJarmAuthResponseErrorParams, responseParams)) {
|
|
22
|
+
const errorResponseJson = JSON.stringify(responseParams, undefined, 2);
|
|
23
|
+
throw new Error(`Received error response from authorization server. '${errorResponseJson}'`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return v.parse(schema, responseParams);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const decryptJarmAuthResponse = async (input: { response: string }, ctx: JarmDirectPostJwtAuthResponseValidationContext) => {
|
|
30
|
+
const { response } = input;
|
|
31
|
+
|
|
32
|
+
const responseProtectedHeader = decodeProtectedHeader(response);
|
|
33
|
+
if (!responseProtectedHeader.kid) {
|
|
34
|
+
throw new Error(`Jarm JWE is missing the protected header field 'kid'.`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { plaintext } = await ctx.jwe.decryptCompact({
|
|
38
|
+
jwe: response,
|
|
39
|
+
jwk: { kid: responseProtectedHeader.kid },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return plaintext;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Validate a JARM direct_post.jwt compliant authentication response
|
|
47
|
+
* * The decryption key should be resolvable using the the protected header's 'kid' field
|
|
48
|
+
* * The signature verification jwk should be resolvable using the jws protected header's 'kid' field and the payload's 'iss' field.
|
|
49
|
+
*/
|
|
50
|
+
export const jarmAuthResponseDirectPostJwtValidate = async (
|
|
51
|
+
input: JarmDirectPostJwtAuthResponseValidation,
|
|
52
|
+
ctx: JarmDirectPostJwtAuthResponseValidationContext,
|
|
53
|
+
) => {
|
|
54
|
+
const { response } = input;
|
|
55
|
+
|
|
56
|
+
const responseIsEncrypted = isJwe(response);
|
|
57
|
+
const decryptedResponse = responseIsEncrypted ? await decryptJarmAuthResponse(input, ctx) : response;
|
|
58
|
+
|
|
59
|
+
const responseIsSigned = isJws(decryptedResponse);
|
|
60
|
+
if (!responseIsEncrypted && !responseIsSigned) {
|
|
61
|
+
throw new Error('Jarm Auth Response must be either encrypted, signed, or signed and encrypted.');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let authResponseParams: JarmDirectPostJwtResponseParams;
|
|
65
|
+
let authRequestParams: AuthRequestParams;
|
|
66
|
+
|
|
67
|
+
if (responseIsSigned) {
|
|
68
|
+
throw new Error('Signed JARM responses are not supported.');
|
|
69
|
+
//const jwsProtectedHeader = decodeProtectedHeader(decryptedResponse);
|
|
70
|
+
//const jwsPayload = decodeJwt(decryptedResponse);
|
|
71
|
+
|
|
72
|
+
//const schema = v.required(vJarmDirectPostJwtParams, ['iss', 'aud', 'exp']);
|
|
73
|
+
//const responseParams = parseJarmAuthResponseParams(schema, jwsPayload);
|
|
74
|
+
//({ authRequestParams } = await ctx.openid4vp.authRequest.getParams(responseParams));
|
|
75
|
+
|
|
76
|
+
//if (!jwsProtectedHeader.kid) {
|
|
77
|
+
//throw new Error(`Jarm JWS is missing the protected header field 'kid'.`);
|
|
78
|
+
//}
|
|
79
|
+
|
|
80
|
+
//await ctx.jose.jws.verifyJwt({
|
|
81
|
+
//jws: decryptedResponse,
|
|
82
|
+
//jwk: { kid: jwsProtectedHeader.kid, kty: 'auto' },
|
|
83
|
+
//});
|
|
84
|
+
//authResponseParams = responseParams;
|
|
85
|
+
} else {
|
|
86
|
+
const jsonResponse: unknown = JSON.parse(decryptedResponse);
|
|
87
|
+
authResponseParams = parseJarmAuthResponseParams(vJarmDirectPostJwtParams, jsonResponse);
|
|
88
|
+
({ authRequestParams } = await ctx.openid4vp.authRequest.getParams(authResponseParams));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
jarmAuthResponseDirectPostValidateParams({
|
|
92
|
+
authRequestParams,
|
|
93
|
+
authResponseParams,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
let type: 'signed encrypted' | 'encrypted' | 'signed';
|
|
97
|
+
if (responseIsSigned && responseIsEncrypted) type = 'signed encrypted';
|
|
98
|
+
else if (responseIsEncrypted) type = 'encrypted';
|
|
99
|
+
else type = 'signed';
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
authRequestParams,
|
|
103
|
+
authResponseParams,
|
|
104
|
+
type,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { checkExp } from '@sphereon/oid4vc-common';
|
|
2
|
+
import * as v from 'valibot';
|
|
3
|
+
|
|
4
|
+
export const vJarmAuthResponseErrorParams = v.looseObject({
|
|
5
|
+
error: v.string(),
|
|
6
|
+
state: v.optional(v.string()),
|
|
7
|
+
|
|
8
|
+
error_description: v.pipe(
|
|
9
|
+
v.optional(v.string()),
|
|
10
|
+
v.description('Text providing additional information, used to assist the client developer in understanding the error that occurred.'),
|
|
11
|
+
),
|
|
12
|
+
|
|
13
|
+
error_uri: v.pipe(
|
|
14
|
+
v.optional(v.pipe(v.string(), v.url())),
|
|
15
|
+
v.description(
|
|
16
|
+
'A URI identifying a human-readable web page with information about the error, used to provide the client developer with additional information about the error',
|
|
17
|
+
),
|
|
18
|
+
),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const vJarmAuthResponseParams = v.looseObject({
|
|
22
|
+
state: v.optional(v.string()),
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The issuer URL of the authorization server that created the response
|
|
26
|
+
*/
|
|
27
|
+
iss: v.string(),
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The client_id of the client the response is intended for
|
|
31
|
+
*/
|
|
32
|
+
exp: v.number(),
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Expiration of the JWT
|
|
36
|
+
*/
|
|
37
|
+
aud: v.string(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
export type JarmAuthResponseParams = v.InferInput<typeof vJarmAuthResponseParams>;
|
|
41
|
+
|
|
42
|
+
export const validateJarmAuthResponseParams = (input: {
|
|
43
|
+
authRequestParams: { client_id: string; state?: string };
|
|
44
|
+
authResponseParams: JarmAuthResponseParams;
|
|
45
|
+
}) => {
|
|
46
|
+
const { authRequestParams, authResponseParams } = input;
|
|
47
|
+
// 2. The client obtains the state parameter from the JWT and checks its binding to the user agent. If the check fails, the client MUST abort processing and refuse the response.
|
|
48
|
+
if (authRequestParams.state !== authResponseParams.state) {
|
|
49
|
+
throw new Error(`State missmatch in jarm-auth-response. Expected '${authRequestParams.state}' received '${authRequestParams.state}'.`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 4. The client obtains the aud element from the JWT and checks whether it matches the client id the client used to identify itself in the corresponding authorization request. If the check fails, the client MUST abort processing and refuse the response.
|
|
53
|
+
if (authRequestParams.client_id !== authResponseParams.client_id) {
|
|
54
|
+
throw new Error(`Invalid audience in jarm-auth-response. Expected '${authRequestParams.client_id}' received '${authResponseParams.aud}'.`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 5. The client checks the JWT's exp element to determine if the JWT is still valid. If the check fails, the client MUST abort processing and refuse the response.
|
|
58
|
+
// 120 seconds clock skew
|
|
59
|
+
if (checkExp({ exp: authResponseParams.exp })) {
|
|
60
|
+
throw new Error(`The '${authRequestParams.state}' and the jarm-auth-response.`);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
|
|
3
|
+
import { vJarmAuthResponseParams } from './v-jarm-auth-response-params.js';
|
|
4
|
+
|
|
5
|
+
export const vJarmDirectPostJwtParams = v.looseObject({
|
|
6
|
+
...v.omit(vJarmAuthResponseParams, ['iss', 'aud', 'exp']).entries,
|
|
7
|
+
...v.partial(v.pick(vJarmAuthResponseParams, ['iss', 'aud', 'exp'])).entries,
|
|
8
|
+
|
|
9
|
+
vp_token: v.string(),
|
|
10
|
+
presentation_submission: v.unknown(),
|
|
11
|
+
nonce: v.optional(v.string()),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type JarmDirectPostJwtResponseParams = v.InferInput<typeof vJarmDirectPostJwtParams>;
|
|
15
|
+
|
|
16
|
+
export const jarmAuthResponseDirectPostValidateParams = (input: {
|
|
17
|
+
authRequestParams: { state?: string };
|
|
18
|
+
authResponseParams: JarmDirectPostJwtResponseParams;
|
|
19
|
+
}) => {
|
|
20
|
+
const { authRequestParams, authResponseParams } = input;
|
|
21
|
+
|
|
22
|
+
// 2. The client obtains the state parameter from the JWT and checks its binding to the user agent. If the check fails, the client MUST abort processing and refuse the response.
|
|
23
|
+
if (authRequestParams.state !== authResponseParams.state) {
|
|
24
|
+
throw new Error(`State missmatch between auth request '${authRequestParams.state}' and the jarm-auth-response.`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './jarm-auth-response-send.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { appendFragmentParams, appendQueryParams } from '../utils.js';
|
|
2
|
+
import type { JarmResponseMode, Openid4vpJarmResponseMode } from '../v-response-mode-registry.js';
|
|
3
|
+
import { getJarmDefaultResponseMode, validateResponseMode } from '../v-response-mode-registry.js';
|
|
4
|
+
import type { ResponseTypeOut } from '../v-response-type-registry.js';
|
|
5
|
+
|
|
6
|
+
interface JarmAuthResponseSendInput {
|
|
7
|
+
authRequestParams: {
|
|
8
|
+
response_mode?: JarmResponseMode | Openid4vpJarmResponseMode;
|
|
9
|
+
response_type: ResponseTypeOut;
|
|
10
|
+
} & (
|
|
11
|
+
| {
|
|
12
|
+
response_uri: string;
|
|
13
|
+
}
|
|
14
|
+
| {
|
|
15
|
+
redirect_uri: string;
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
authResponse: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const jarmAuthResponseSend = async (input: JarmAuthResponseSendInput): Promise<Response> => {
|
|
23
|
+
const { authRequestParams, authResponse } = input;
|
|
24
|
+
|
|
25
|
+
const responseEndpoint = 'response_uri' in authRequestParams ? new URL(authRequestParams.response_uri) : new URL(authRequestParams.redirect_uri);
|
|
26
|
+
|
|
27
|
+
const responseMode =
|
|
28
|
+
authRequestParams.response_mode && authRequestParams.response_mode !== 'jwt'
|
|
29
|
+
? authRequestParams.response_mode
|
|
30
|
+
: getJarmDefaultResponseMode(authRequestParams);
|
|
31
|
+
|
|
32
|
+
validateResponseMode({
|
|
33
|
+
response_type: authRequestParams.response_type,
|
|
34
|
+
response_mode: responseMode,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
switch (responseMode) {
|
|
38
|
+
case 'direct_post.jwt':
|
|
39
|
+
return handleDirectPostJwt(responseEndpoint, authResponse);
|
|
40
|
+
case 'query.jwt':
|
|
41
|
+
return handleQueryJwt(responseEndpoint, authResponse);
|
|
42
|
+
case 'fragment.jwt':
|
|
43
|
+
return handleFragmentJwt(responseEndpoint, authResponse);
|
|
44
|
+
case 'form_post.jwt':
|
|
45
|
+
throw new Error('Not implemented');
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
async function handleDirectPostJwt(responseEndpoint: URL, responseJwt: string) {
|
|
50
|
+
const response = await fetch(responseEndpoint, {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
53
|
+
body: `response=${responseJwt}`,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function handleQueryJwt(responseEndpoint: URL, responseJwt: string) {
|
|
60
|
+
const responseUrl = appendQueryParams({
|
|
61
|
+
url: responseEndpoint,
|
|
62
|
+
params: { response: responseJwt },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const response = await fetch(responseUrl, { method: 'POST' });
|
|
66
|
+
return response;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function handleFragmentJwt(responseEndpoint: URL, responseJwt: string) {
|
|
70
|
+
const responseUrl = appendFragmentParams({
|
|
71
|
+
url: responseEndpoint,
|
|
72
|
+
fragments: { response: responseJwt },
|
|
73
|
+
});
|
|
74
|
+
const response = await fetch(responseUrl, { method: 'POST' });
|
|
75
|
+
return response;
|
|
76
|
+
}
|