@openid4vc/oauth2 0.3.0-alpha-20251021082313 → 0.3.0-alpha-20251029093110
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/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1427,6 +1427,7 @@ declare const zAuthorizationChallengeRequest: z$1.ZodObject<{
|
|
|
1427
1427
|
scope: z$1.ZodOptional<z$1.ZodString>;
|
|
1428
1428
|
redirect_uri: z$1.ZodOptional<z$1.ZodURL>;
|
|
1429
1429
|
resource: z$1.ZodOptional<z$1.ZodString>;
|
|
1430
|
+
state: z$1.ZodOptional<z$1.ZodString>;
|
|
1430
1431
|
issuer_state: z$1.ZodOptional<z$1.ZodString>;
|
|
1431
1432
|
dpop_jkt: z$1.ZodOptional<z$1.ZodBase64URL>;
|
|
1432
1433
|
code_challenge: z$1.ZodOptional<z$1.ZodString>;
|
|
@@ -1565,6 +1566,10 @@ interface CreateAuthorizationRequestUrlOptions {
|
|
|
1565
1566
|
* Scope to request for the authorization request
|
|
1566
1567
|
*/
|
|
1567
1568
|
scope?: string;
|
|
1569
|
+
/**
|
|
1570
|
+
* State for the authorization request
|
|
1571
|
+
*/
|
|
1572
|
+
state?: string;
|
|
1568
1573
|
/**
|
|
1569
1574
|
* The resource to which access is being requested. This can help the authorization
|
|
1570
1575
|
* server in determining the resource server to handle the authorization request for
|
|
@@ -1629,6 +1634,7 @@ declare const zAuthorizationRequest: z$1.ZodObject<{
|
|
|
1629
1634
|
redirect_uri: z$1.ZodOptional<z$1.ZodURL>;
|
|
1630
1635
|
resource: z$1.ZodOptional<z$1.ZodString>;
|
|
1631
1636
|
scope: z$1.ZodOptional<z$1.ZodString>;
|
|
1637
|
+
state: z$1.ZodOptional<z$1.ZodString>;
|
|
1632
1638
|
dpop_jkt: z$1.ZodOptional<z$1.ZodBase64URL>;
|
|
1633
1639
|
code_challenge: z$1.ZodOptional<z$1.ZodString>;
|
|
1634
1640
|
code_challenge_method: z$1.ZodOptional<z$1.ZodString>;
|
|
@@ -2608,7 +2614,12 @@ interface SendAuthorizationChallengeRequestOptions {
|
|
|
2608
2614
|
*/
|
|
2609
2615
|
resource?: string;
|
|
2610
2616
|
/**
|
|
2611
|
-
*
|
|
2617
|
+
* Redirect uri to include in the authorization challenge request. Maybe be used by the
|
|
2618
|
+
* server when falling back to a PAR request.
|
|
2619
|
+
*/
|
|
2620
|
+
redirectUri?: string;
|
|
2621
|
+
/**
|
|
2622
|
+
* Presentation during issuance session if credentials were presented
|
|
2612
2623
|
* as part of an issuance session
|
|
2613
2624
|
*/
|
|
2614
2625
|
presentationDuringIssuanceSession?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1427,6 +1427,7 @@ declare const zAuthorizationChallengeRequest: z$1.ZodObject<{
|
|
|
1427
1427
|
scope: z$1.ZodOptional<z$1.ZodString>;
|
|
1428
1428
|
redirect_uri: z$1.ZodOptional<z$1.ZodURL>;
|
|
1429
1429
|
resource: z$1.ZodOptional<z$1.ZodString>;
|
|
1430
|
+
state: z$1.ZodOptional<z$1.ZodString>;
|
|
1430
1431
|
issuer_state: z$1.ZodOptional<z$1.ZodString>;
|
|
1431
1432
|
dpop_jkt: z$1.ZodOptional<z$1.ZodBase64URL>;
|
|
1432
1433
|
code_challenge: z$1.ZodOptional<z$1.ZodString>;
|
|
@@ -1565,6 +1566,10 @@ interface CreateAuthorizationRequestUrlOptions {
|
|
|
1565
1566
|
* Scope to request for the authorization request
|
|
1566
1567
|
*/
|
|
1567
1568
|
scope?: string;
|
|
1569
|
+
/**
|
|
1570
|
+
* State for the authorization request
|
|
1571
|
+
*/
|
|
1572
|
+
state?: string;
|
|
1568
1573
|
/**
|
|
1569
1574
|
* The resource to which access is being requested. This can help the authorization
|
|
1570
1575
|
* server in determining the resource server to handle the authorization request for
|
|
@@ -1629,6 +1634,7 @@ declare const zAuthorizationRequest: z$1.ZodObject<{
|
|
|
1629
1634
|
redirect_uri: z$1.ZodOptional<z$1.ZodURL>;
|
|
1630
1635
|
resource: z$1.ZodOptional<z$1.ZodString>;
|
|
1631
1636
|
scope: z$1.ZodOptional<z$1.ZodString>;
|
|
1637
|
+
state: z$1.ZodOptional<z$1.ZodString>;
|
|
1632
1638
|
dpop_jkt: z$1.ZodOptional<z$1.ZodBase64URL>;
|
|
1633
1639
|
code_challenge: z$1.ZodOptional<z$1.ZodString>;
|
|
1634
1640
|
code_challenge_method: z$1.ZodOptional<z$1.ZodString>;
|
|
@@ -2608,7 +2614,12 @@ interface SendAuthorizationChallengeRequestOptions {
|
|
|
2608
2614
|
*/
|
|
2609
2615
|
resource?: string;
|
|
2610
2616
|
/**
|
|
2611
|
-
*
|
|
2617
|
+
* Redirect uri to include in the authorization challenge request. Maybe be used by the
|
|
2618
|
+
* server when falling back to a PAR request.
|
|
2619
|
+
*/
|
|
2620
|
+
redirectUri?: string;
|
|
2621
|
+
/**
|
|
2622
|
+
* Presentation during issuance session if credentials were presented
|
|
2612
2623
|
* as part of an issuance session
|
|
2613
2624
|
*/
|
|
2614
2625
|
presentationDuringIssuanceSession?: string;
|
package/dist/index.js
CHANGED
|
@@ -43,7 +43,7 @@ let HashAlgorithm = /* @__PURE__ */ function(HashAlgorithm$1) {
|
|
|
43
43
|
//#region src/error/Oauth2Error.ts
|
|
44
44
|
var Oauth2Error = class extends Error {
|
|
45
45
|
constructor(message, options) {
|
|
46
|
-
const errorMessage = message ?? "Unknown error
|
|
46
|
+
const errorMessage = message ?? "Unknown error occurred.";
|
|
47
47
|
const causeMessage = options?.cause instanceof Error ? ` ${options.cause.message}` : options?.cause ? ` ${options?.cause}` : "";
|
|
48
48
|
super(`${errorMessage}${causeMessage}`);
|
|
49
49
|
this.cause = options?.cause;
|
|
@@ -288,7 +288,7 @@ function jwtSignerFromJwt({ header, payload, allowedSignerMethods }) {
|
|
|
288
288
|
if (header.kid?.startsWith("did:") || payload.iss?.startsWith("did:")) if (payload.iss && header.kid?.startsWith("did:") && !header.kid.startsWith(payload.iss)) found.push({
|
|
289
289
|
method: "did",
|
|
290
290
|
valid: false,
|
|
291
|
-
error: `kid in header
|
|
291
|
+
error: `kid in header starts with did that is different from did value in 'iss'`
|
|
292
292
|
});
|
|
293
293
|
else if (!header.kid?.startsWith("did:") && !header.kid?.startsWith("#")) found.push({
|
|
294
294
|
method: "did",
|
|
@@ -1411,6 +1411,7 @@ const zAuthorizationRequest = zod.default.object({
|
|
|
1411
1411
|
redirect_uri: zod.default.url().optional(),
|
|
1412
1412
|
resource: zod.default.optional(__openid4vc_utils.zHttpsUrl),
|
|
1413
1413
|
scope: zod.default.optional(zod.default.string()),
|
|
1414
|
+
state: zod.default.optional(zod.default.string()),
|
|
1414
1415
|
dpop_jkt: zod.default.optional(zod.default.base64url()),
|
|
1415
1416
|
code_challenge: zod.default.optional(zod.default.string()),
|
|
1416
1417
|
code_challenge_method: zod.default.optional(zod.default.string())
|
|
@@ -1449,7 +1450,7 @@ const zAuthorizationChallengeErrorResponse = zod.default.object({
|
|
|
1449
1450
|
/**
|
|
1450
1451
|
* Create an authorization challenge response
|
|
1451
1452
|
*
|
|
1452
|
-
* @throws {ValidationError} if an error
|
|
1453
|
+
* @throws {ValidationError} if an error occurred during verification of the {@link AuthorizationChallengeResponse}
|
|
1453
1454
|
*/
|
|
1454
1455
|
function createAuthorizationChallengeResponse(options) {
|
|
1455
1456
|
return { authorizationChallengeResponse: (0, __openid4vc_utils.parseWithErrorHandling)(zAuthorizationChallengeResponse, {
|
|
@@ -1460,7 +1461,7 @@ function createAuthorizationChallengeResponse(options) {
|
|
|
1460
1461
|
/**
|
|
1461
1462
|
* Create an authorization challenge error response
|
|
1462
1463
|
*
|
|
1463
|
-
* @throws {ValidationError} if an error
|
|
1464
|
+
* @throws {ValidationError} if an error occurred during validation of the {@link AuthorizationChallengeErrorResponse}
|
|
1464
1465
|
*/
|
|
1465
1466
|
function createAuthorizationChallengeErrorResponse(options) {
|
|
1466
1467
|
return (0, __openid4vc_utils.parseWithErrorHandling)(zAuthorizationChallengeErrorResponse, {
|
|
@@ -1616,7 +1617,7 @@ async function verifyAuthorizationChallengeRequest(options) {
|
|
|
1616
1617
|
/**
|
|
1617
1618
|
* Create an pushed authorization response
|
|
1618
1619
|
*
|
|
1619
|
-
* @throws {ValidationError} if an error
|
|
1620
|
+
* @throws {ValidationError} if an error occurred during verification of the {@link PushedAuthorizationResponse}
|
|
1620
1621
|
*/
|
|
1621
1622
|
function createPushedAuthorizationResponse(options) {
|
|
1622
1623
|
return { pushedAuthorizationResponse: (0, __openid4vc_utils.parseWithErrorHandling)(zPushedAuthorizationResponse, {
|
|
@@ -1628,7 +1629,7 @@ function createPushedAuthorizationResponse(options) {
|
|
|
1628
1629
|
/**
|
|
1629
1630
|
* Create a pushed authorization error response
|
|
1630
1631
|
*
|
|
1631
|
-
* @throws {ValidationError} if an error
|
|
1632
|
+
* @throws {ValidationError} if an error occurred during validation of the {@link PushedAuthorizationErrorResponse}
|
|
1632
1633
|
*/
|
|
1633
1634
|
function createPushedAuthorizationErrorResponse(options) {
|
|
1634
1635
|
return (0, __openid4vc_utils.parseWithErrorHandling)(zAccessTokenErrorResponse, {
|
|
@@ -1649,7 +1650,7 @@ function parsePushedAuthorizationRequest(options) {
|
|
|
1649
1650
|
const parsedAuthorizationRequest = zAuthorizationRequest.safeParse(options.authorizationRequest);
|
|
1650
1651
|
if (!parsedAuthorizationRequest.success) throw new Oauth2ServerErrorResponseError({
|
|
1651
1652
|
error: Oauth2ErrorCodes.InvalidRequest,
|
|
1652
|
-
error_description: `Error
|
|
1653
|
+
error_description: `Error occurred during validation of pushed authorization request.\n${(0, __openid4vc_utils.formatZodError)(parsedAuthorizationRequest.error)}`
|
|
1653
1654
|
});
|
|
1654
1655
|
const authorizationRequest = parsedAuthorizationRequest.data;
|
|
1655
1656
|
const { clientAttestation, dpop } = parseAuthorizationRequest({
|
|
@@ -1960,13 +1961,13 @@ async function retrieveAccessToken(options) {
|
|
|
1960
1961
|
*
|
|
1961
1962
|
* @throws {Oauth2ClientAuthorizationChallengeError} if the request failed and a {@link AuthorizationChallengeErrorResponse} is returned
|
|
1962
1963
|
* @throws {InvalidFetchResponseError} if the request failed but no error response could be parsed
|
|
1963
|
-
* @throws {ValidationError} if a successful response was received but an error
|
|
1964
|
+
* @throws {ValidationError} if a successful response was received but an error occurred during verification of the {@link AuthorizationChallengeResponse}
|
|
1964
1965
|
*/
|
|
1965
1966
|
async function sendAuthorizationChallengeRequest(options) {
|
|
1966
1967
|
const fetchWithZod = (0, __openid4vc_utils.createZodFetcher)(options.callbacks.fetch);
|
|
1967
1968
|
const authorizationServerMetadata = options.authorizationServerMetadata;
|
|
1968
1969
|
const authorizationChallengeEndpoint = authorizationServerMetadata.authorization_challenge_endpoint;
|
|
1969
|
-
if (!authorizationChallengeEndpoint) throw new Oauth2Error(`Unable to send authorization
|
|
1970
|
+
if (!authorizationChallengeEndpoint) throw new Oauth2Error(`Unable to send authorization challenge. Authorization server '${authorizationServerMetadata.issuer}' has no 'authorization_challenge_endpoint'`);
|
|
1970
1971
|
const pkce = authorizationServerMetadata.code_challenge_methods_supported && !options.authSession ? await createPkce({
|
|
1971
1972
|
allowedCodeChallengeMethods: authorizationServerMetadata.code_challenge_methods_supported,
|
|
1972
1973
|
callbacks: options.callbacks,
|
|
@@ -1976,6 +1977,7 @@ async function sendAuthorizationChallengeRequest(options) {
|
|
|
1976
1977
|
...options.additionalRequestPayload,
|
|
1977
1978
|
auth_session: options.authSession,
|
|
1978
1979
|
scope: options.scope,
|
|
1980
|
+
redirect_uri: options.redirectUri,
|
|
1979
1981
|
resource: options.resource,
|
|
1980
1982
|
code_challenge: pkce?.codeChallenge,
|
|
1981
1983
|
code_challenge_method: pkce?.codeChallengeMethod,
|
|
@@ -2053,6 +2055,7 @@ async function createAuthorizationRequestUrl(options) {
|
|
|
2053
2055
|
redirect_uri: options.redirectUri,
|
|
2054
2056
|
resource: options.resource,
|
|
2055
2057
|
scope: options.scope,
|
|
2058
|
+
state: options.state,
|
|
2056
2059
|
code_challenge: pkce?.codeChallenge,
|
|
2057
2060
|
code_challenge_method: pkce?.codeChallengeMethod
|
|
2058
2061
|
};
|
|
@@ -2102,7 +2105,7 @@ async function createAuthorizationRequestUrl(options) {
|
|
|
2102
2105
|
}
|
|
2103
2106
|
async function pushAuthorizationRequest(options) {
|
|
2104
2107
|
const fetchWithZod = (0, __openid4vc_utils.createZodFetcher)(options.callbacks.fetch);
|
|
2105
|
-
if (options.authorizationRequest.request_uri) throw new Oauth2Error(`Authorization request contains 'request_uri' parameter. This is not allowed for pushed authorization
|
|
2108
|
+
if (options.authorizationRequest.request_uri) throw new Oauth2Error(`Authorization request contains 'request_uri' parameter. This is not allowed for pushed authorization requests.`);
|
|
2106
2109
|
const headers = new __openid4vc_utils.Headers({
|
|
2107
2110
|
...options.headers,
|
|
2108
2111
|
"Content-Type": __openid4vc_utils.ContentType.XWwwFormUrlencoded
|
|
@@ -2226,6 +2229,7 @@ var Oauth2Client = class {
|
|
|
2226
2229
|
authorizationServerMetadata: options.authorizationServerMetadata,
|
|
2227
2230
|
additionalRequestPayload: options.additionalRequestPayload,
|
|
2228
2231
|
pkceCodeVerifier: pkce?.codeVerifier,
|
|
2232
|
+
redirectUri: options.redirectUri,
|
|
2229
2233
|
scope: options.scope,
|
|
2230
2234
|
resource: options.resource,
|
|
2231
2235
|
dpop: options.dpop
|
|
@@ -2456,7 +2460,7 @@ async function verifyResourceRequest(options) {
|
|
|
2456
2460
|
})).header.jwk;
|
|
2457
2461
|
} catch (error) {
|
|
2458
2462
|
const errorMessage = error instanceof Oauth2Error ? error.message : "Error verifying DPoP jwt";
|
|
2459
|
-
throw new Oauth2ResourceUnauthorizedError(`Error
|
|
2463
|
+
throw new Oauth2ResourceUnauthorizedError(`Error occurred during verification of jwt profile access token: ${error instanceof Error ? error.message : error}`, {
|
|
2460
2464
|
scheme,
|
|
2461
2465
|
error: Oauth2ErrorCodes.InvalidDpopProof,
|
|
2462
2466
|
error_description: errorMessage
|