@openid4vc/oauth2 0.3.0-alpha-20251031085020 → 0.3.0-alpha-20251031102233
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 +46 -1
- package/dist/index.d.ts +46 -1
- package/dist/index.js +249 -196
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -197
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -693,6 +693,248 @@ async function verifyClientAttestation({ authorizationServer, clientAttestationJ
|
|
|
693
693
|
}
|
|
694
694
|
}
|
|
695
695
|
|
|
696
|
+
//#endregion
|
|
697
|
+
//#region src/dpop/z-dpop.ts
|
|
698
|
+
const zDpopJwtPayload = z$1.object({
|
|
699
|
+
...zJwtPayload.shape,
|
|
700
|
+
iat: zInteger,
|
|
701
|
+
htu: zHttpsUrl,
|
|
702
|
+
htm: zHttpMethod,
|
|
703
|
+
jti: z$1.string(),
|
|
704
|
+
ath: z$1.optional(z$1.string())
|
|
705
|
+
}).loose();
|
|
706
|
+
const zDpopJwtHeader = z$1.object({
|
|
707
|
+
...zJwtHeader.shape,
|
|
708
|
+
typ: z$1.literal("dpop+jwt"),
|
|
709
|
+
jwk: zJwk
|
|
710
|
+
}).loose();
|
|
711
|
+
|
|
712
|
+
//#endregion
|
|
713
|
+
//#region src/dpop/dpop.ts
|
|
714
|
+
async function createDpopHeadersForRequest(options) {
|
|
715
|
+
return { DPoP: await createDpopJwt(options) };
|
|
716
|
+
}
|
|
717
|
+
async function createDpopJwt(options) {
|
|
718
|
+
let ath;
|
|
719
|
+
if (options.accessToken) ath = encodeToBase64Url(await options.callbacks.hash(decodeUtf8String(options.accessToken), HashAlgorithm.Sha256));
|
|
720
|
+
const header = parseWithErrorHandling(zDpopJwtHeader, {
|
|
721
|
+
typ: "dpop+jwt",
|
|
722
|
+
jwk: options.signer.publicJwk,
|
|
723
|
+
alg: options.signer.alg
|
|
724
|
+
});
|
|
725
|
+
const payload = parseWithErrorHandling(zDpopJwtPayload, {
|
|
726
|
+
htu: htuFromRequestUrl(options.request.url),
|
|
727
|
+
iat: dateToSeconds(options.issuedAt),
|
|
728
|
+
htm: options.request.method,
|
|
729
|
+
jti: encodeToBase64Url(await options.callbacks.generateRandom(32)),
|
|
730
|
+
ath,
|
|
731
|
+
nonce: options.nonce,
|
|
732
|
+
...options.additionalPayload
|
|
733
|
+
});
|
|
734
|
+
const { jwt } = await options.callbacks.signJwt(options.signer, {
|
|
735
|
+
header,
|
|
736
|
+
payload
|
|
737
|
+
});
|
|
738
|
+
return jwt;
|
|
739
|
+
}
|
|
740
|
+
async function verifyDpopJwt(options) {
|
|
741
|
+
try {
|
|
742
|
+
const { header, payload } = decodeJwt({
|
|
743
|
+
jwt: options.dpopJwt,
|
|
744
|
+
headerSchema: zDpopJwtHeader,
|
|
745
|
+
payloadSchema: zDpopJwtPayload
|
|
746
|
+
});
|
|
747
|
+
if (options.allowedSigningAlgs && !options.allowedSigningAlgs.includes(header.alg)) throw new Oauth2Error(`dpop jwt uses alg value '${header.alg}' but allowed dpop signging alg values are ${options.allowedSigningAlgs.join(", ")}.`);
|
|
748
|
+
if (options.expectedNonce) {
|
|
749
|
+
if (!payload.nonce) throw new Oauth2Error(`Dpop jwt does not have a nonce value, but expected nonce value '${options.expectedNonce}'`);
|
|
750
|
+
if (payload.nonce !== options.expectedNonce) throw new Oauth2Error(`Dpop jwt contains nonce value '${payload.nonce}', but expected nonce value '${options.expectedNonce}'`);
|
|
751
|
+
}
|
|
752
|
+
if (options.request.method !== payload.htm) throw new Oauth2Error(`Dpop jwt contains htm value '${payload.htm}', but expected htm value '${options.request.method}'`);
|
|
753
|
+
const expectedHtu = htuFromRequestUrl(options.request.url);
|
|
754
|
+
if (expectedHtu !== payload.htu) throw new Oauth2Error(`Dpop jwt contains htu value '${payload.htu}', but expected htu value '${expectedHtu}'.`);
|
|
755
|
+
if (options.accessToken) {
|
|
756
|
+
const expectedAth = encodeToBase64Url(await options.callbacks.hash(decodeUtf8String(options.accessToken), HashAlgorithm.Sha256));
|
|
757
|
+
if (!payload.ath) throw new Oauth2Error(`Dpop jwt does not have a ath value, but expected ath value '${expectedAth}'.`);
|
|
758
|
+
if (payload.ath !== expectedAth) throw new Oauth2Error(`Dpop jwt contains ath value '${payload.ath}', but expected ath value '${expectedAth}'.`);
|
|
759
|
+
}
|
|
760
|
+
const jwkThumbprint = await calculateJwkThumbprint({
|
|
761
|
+
hashAlgorithm: HashAlgorithm.Sha256,
|
|
762
|
+
hashCallback: options.callbacks.hash,
|
|
763
|
+
jwk: header.jwk
|
|
764
|
+
});
|
|
765
|
+
if (options.expectedJwkThumbprint && options.expectedJwkThumbprint !== jwkThumbprint) throw new Oauth2Error(`Dpop is signed with jwk with thumbprint value '${jwkThumbprint}', but expect jwk thumbprint value '${options.expectedJwkThumbprint}'`);
|
|
766
|
+
await verifyJwt({
|
|
767
|
+
signer: {
|
|
768
|
+
alg: header.alg,
|
|
769
|
+
method: "jwk",
|
|
770
|
+
publicJwk: header.jwk
|
|
771
|
+
},
|
|
772
|
+
now: options.now,
|
|
773
|
+
header,
|
|
774
|
+
payload,
|
|
775
|
+
compact: options.dpopJwt,
|
|
776
|
+
verifyJwtCallback: options.callbacks.verifyJwt,
|
|
777
|
+
errorMessage: "dpop jwt verification failed"
|
|
778
|
+
});
|
|
779
|
+
return {
|
|
780
|
+
header,
|
|
781
|
+
payload,
|
|
782
|
+
jwkThumbprint
|
|
783
|
+
};
|
|
784
|
+
} catch (error) {
|
|
785
|
+
if (error instanceof Oauth2Error) throw new Oauth2ServerErrorResponseError({
|
|
786
|
+
error: Oauth2ErrorCodes.InvalidDpopProof,
|
|
787
|
+
error_description: error.message
|
|
788
|
+
});
|
|
789
|
+
throw error;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
function htuFromRequestUrl(requestUrl) {
|
|
793
|
+
const htu = new URL(requestUrl);
|
|
794
|
+
htu.search = "";
|
|
795
|
+
htu.hash = "";
|
|
796
|
+
return htu.toString();
|
|
797
|
+
}
|
|
798
|
+
function extractDpopNonceFromHeaders(headers) {
|
|
799
|
+
return headers.get("DPoP-Nonce");
|
|
800
|
+
}
|
|
801
|
+
function extractDpopJwtFromHeaders(headers) {
|
|
802
|
+
const dpopJwt = headers.get("DPoP");
|
|
803
|
+
if (!dpopJwt) return { valid: true };
|
|
804
|
+
if (!zCompactJwt.safeParse(dpopJwt).success) return { valid: false };
|
|
805
|
+
return {
|
|
806
|
+
valid: true,
|
|
807
|
+
dpopJwt
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/authorization-request/parse-authorization-request.ts
|
|
813
|
+
/**
|
|
814
|
+
* Parse an authorization request.
|
|
815
|
+
*
|
|
816
|
+
* @throws {Oauth2ServerErrorResponseError}
|
|
817
|
+
*/
|
|
818
|
+
function parseAuthorizationRequest(options) {
|
|
819
|
+
const extractedDpopJwt = extractDpopJwtFromHeaders(options.request.headers);
|
|
820
|
+
if (!extractedDpopJwt.valid) throw new Oauth2ServerErrorResponseError({
|
|
821
|
+
error: Oauth2ErrorCodes.InvalidDpopProof,
|
|
822
|
+
error_description: `Request contains a 'DPoP' header, but the value is not a valid DPoP jwt`
|
|
823
|
+
});
|
|
824
|
+
const extractedClientAttestationJwts = extractClientAttestationJwtsFromHeaders(options.request.headers);
|
|
825
|
+
if (!extractedClientAttestationJwts.valid) throw new Oauth2ServerErrorResponseError({
|
|
826
|
+
error: Oauth2ErrorCodes.InvalidClient,
|
|
827
|
+
error_description: "Request contains client attestation header, but the values are not valid client attestation and client attestation PoP header."
|
|
828
|
+
});
|
|
829
|
+
return {
|
|
830
|
+
dpop: extractedDpopJwt.dpopJwt ? {
|
|
831
|
+
jwt: extractedDpopJwt.dpopJwt,
|
|
832
|
+
jwkThumbprint: options.authorizationRequest.dpop_jkt
|
|
833
|
+
} : options.authorizationRequest.dpop_jkt ? {
|
|
834
|
+
jwt: extractedDpopJwt.dpopJwt,
|
|
835
|
+
jwkThumbprint: options.authorizationRequest.dpop_jkt
|
|
836
|
+
} : void 0,
|
|
837
|
+
clientAttestation: extractedClientAttestationJwts.clientAttestationHeader ? {
|
|
838
|
+
clientAttestationJwt: extractedClientAttestationJwts.clientAttestationHeader,
|
|
839
|
+
clientAttestationPopJwt: extractedClientAttestationJwts.clientAttestationPopHeader
|
|
840
|
+
} : void 0
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region src/authorization-request/z-authorization-request.ts
|
|
846
|
+
const zPushedAuthorizationRequestUriPrefix = z$1.literal("urn:ietf:params:oauth:request_uri:");
|
|
847
|
+
const pushedAuthorizationRequestUriPrefix = zPushedAuthorizationRequestUriPrefix.value;
|
|
848
|
+
const zAuthorizationRequest = z$1.object({
|
|
849
|
+
response_type: z$1.string(),
|
|
850
|
+
client_id: z$1.string(),
|
|
851
|
+
issuer_state: z$1.optional(z$1.string()),
|
|
852
|
+
redirect_uri: z$1.url().optional(),
|
|
853
|
+
resource: z$1.optional(zHttpsUrl),
|
|
854
|
+
scope: z$1.optional(z$1.string()),
|
|
855
|
+
state: z$1.optional(z$1.string()),
|
|
856
|
+
dpop_jkt: z$1.optional(z$1.base64url()),
|
|
857
|
+
code_challenge: z$1.optional(z$1.string()),
|
|
858
|
+
code_challenge_method: z$1.optional(z$1.string())
|
|
859
|
+
}).loose();
|
|
860
|
+
const zPushedAuthorizationRequest = z$1.object({
|
|
861
|
+
request_uri: z$1.string(),
|
|
862
|
+
client_id: z$1.string()
|
|
863
|
+
}).loose();
|
|
864
|
+
const zPushedAuthorizationResponse = z$1.object({
|
|
865
|
+
request_uri: z$1.string(),
|
|
866
|
+
expires_in: z$1.number().int()
|
|
867
|
+
}).loose();
|
|
868
|
+
|
|
869
|
+
//#endregion
|
|
870
|
+
//#region src/authorization-request/parse-pushed-authorization-request.ts
|
|
871
|
+
/**
|
|
872
|
+
* Parse an pushed authorization request.
|
|
873
|
+
*
|
|
874
|
+
* @throws {Oauth2ServerErrorResponseError}
|
|
875
|
+
*/
|
|
876
|
+
function parsePushedAuthorizationRequest(options) {
|
|
877
|
+
const parsedAuthorizationRequest = zAuthorizationRequest.safeParse(options.authorizationRequest);
|
|
878
|
+
if (!parsedAuthorizationRequest.success) throw new Oauth2ServerErrorResponseError({
|
|
879
|
+
error: Oauth2ErrorCodes.InvalidRequest,
|
|
880
|
+
error_description: `Error occurred during validation of pushed authorization request.\n${formatZodError(parsedAuthorizationRequest.error)}`
|
|
881
|
+
});
|
|
882
|
+
const authorizationRequest = parsedAuthorizationRequest.data;
|
|
883
|
+
const { clientAttestation, dpop } = parseAuthorizationRequest({
|
|
884
|
+
authorizationRequest,
|
|
885
|
+
request: options.request
|
|
886
|
+
});
|
|
887
|
+
return {
|
|
888
|
+
authorizationRequest,
|
|
889
|
+
dpop,
|
|
890
|
+
clientAttestation
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Parse a pushed authorization request URI prefixed with `urn:ietf:params:oauth:request_uri:`
|
|
895
|
+
* and returns the identifier, without the prefix.
|
|
896
|
+
*
|
|
897
|
+
* @throws {Oauth2ServerErrorResponseError}
|
|
898
|
+
*/
|
|
899
|
+
function parsePushedAuthorizationRequestUri(options) {
|
|
900
|
+
if (!options.uri.startsWith(pushedAuthorizationRequestUriPrefix)) throw new Oauth2ServerErrorResponseError({
|
|
901
|
+
error: Oauth2ErrorCodes.InvalidRequest,
|
|
902
|
+
error_description: `The 'request_uri' must start with the prefix "${pushedAuthorizationRequestUriPrefix}".`
|
|
903
|
+
});
|
|
904
|
+
return options.uri.substring(pushedAuthorizationRequestUriPrefix.length);
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
//#endregion
|
|
908
|
+
//#region src/authorization-response/z-authorization-response.ts
|
|
909
|
+
const zAuthorizationResponse = z$1.object({
|
|
910
|
+
state: z$1.string().optional(),
|
|
911
|
+
code: z$1.string().nonempty(),
|
|
912
|
+
error: z$1.optional(z$1.never())
|
|
913
|
+
}).loose();
|
|
914
|
+
const zAuthorizationResponseFromUriParams = z$1.url().transform((url) => Object.fromEntries(new URL(url).searchParams)).pipe(zAuthorizationResponse);
|
|
915
|
+
const zAuthorizationErrorResponse = z$1.object({
|
|
916
|
+
...zOauth2ErrorResponse.shape,
|
|
917
|
+
state: z$1.string().optional(),
|
|
918
|
+
code: z$1.optional(z$1.never())
|
|
919
|
+
}).loose();
|
|
920
|
+
|
|
921
|
+
//#endregion
|
|
922
|
+
//#region src/authorization-response/parse-authorization-response.ts
|
|
923
|
+
/**
|
|
924
|
+
* Parse an authorization response redirect URL.
|
|
925
|
+
*
|
|
926
|
+
* @throws {Oauth2ServerErrorResponseError}
|
|
927
|
+
*/
|
|
928
|
+
function parseAuthorizationResponseRedirectUrl(options) {
|
|
929
|
+
const searchParams = Object.fromEntries(new URL(options.url).searchParams);
|
|
930
|
+
const parsedAuthorizationResponse = z$1.union([zAuthorizationErrorResponse, zAuthorizationResponse]).safeParse(searchParams);
|
|
931
|
+
if (!parsedAuthorizationResponse.success) throw new Oauth2ServerErrorResponseError({
|
|
932
|
+
error: Oauth2ErrorCodes.InvalidRequest,
|
|
933
|
+
error_description: `Error occurred during validation of authorization response redirect URL.\n${formatZodError(parsedAuthorizationResponse.error)}`
|
|
934
|
+
});
|
|
935
|
+
return parsedAuthorizationResponse.data;
|
|
936
|
+
}
|
|
937
|
+
|
|
696
938
|
//#endregion
|
|
697
939
|
//#region src/z-grant-type.ts
|
|
698
940
|
const zPreAuthorizedCodeGrantIdentifier = z$1.literal("urn:ietf:params:oauth:grant-type:pre-authorized_code");
|
|
@@ -1095,121 +1337,6 @@ async function createAccessTokenResponse(options) {
|
|
|
1095
1337
|
});
|
|
1096
1338
|
}
|
|
1097
1339
|
|
|
1098
|
-
//#endregion
|
|
1099
|
-
//#region src/dpop/z-dpop.ts
|
|
1100
|
-
const zDpopJwtPayload = z$1.object({
|
|
1101
|
-
...zJwtPayload.shape,
|
|
1102
|
-
iat: zInteger,
|
|
1103
|
-
htu: zHttpsUrl,
|
|
1104
|
-
htm: zHttpMethod,
|
|
1105
|
-
jti: z$1.string(),
|
|
1106
|
-
ath: z$1.optional(z$1.string())
|
|
1107
|
-
}).loose();
|
|
1108
|
-
const zDpopJwtHeader = z$1.object({
|
|
1109
|
-
...zJwtHeader.shape,
|
|
1110
|
-
typ: z$1.literal("dpop+jwt"),
|
|
1111
|
-
jwk: zJwk
|
|
1112
|
-
}).loose();
|
|
1113
|
-
|
|
1114
|
-
//#endregion
|
|
1115
|
-
//#region src/dpop/dpop.ts
|
|
1116
|
-
async function createDpopHeadersForRequest(options) {
|
|
1117
|
-
return { DPoP: await createDpopJwt(options) };
|
|
1118
|
-
}
|
|
1119
|
-
async function createDpopJwt(options) {
|
|
1120
|
-
let ath;
|
|
1121
|
-
if (options.accessToken) ath = encodeToBase64Url(await options.callbacks.hash(decodeUtf8String(options.accessToken), HashAlgorithm.Sha256));
|
|
1122
|
-
const header = parseWithErrorHandling(zDpopJwtHeader, {
|
|
1123
|
-
typ: "dpop+jwt",
|
|
1124
|
-
jwk: options.signer.publicJwk,
|
|
1125
|
-
alg: options.signer.alg
|
|
1126
|
-
});
|
|
1127
|
-
const payload = parseWithErrorHandling(zDpopJwtPayload, {
|
|
1128
|
-
htu: htuFromRequestUrl(options.request.url),
|
|
1129
|
-
iat: dateToSeconds(options.issuedAt),
|
|
1130
|
-
htm: options.request.method,
|
|
1131
|
-
jti: encodeToBase64Url(await options.callbacks.generateRandom(32)),
|
|
1132
|
-
ath,
|
|
1133
|
-
nonce: options.nonce,
|
|
1134
|
-
...options.additionalPayload
|
|
1135
|
-
});
|
|
1136
|
-
const { jwt } = await options.callbacks.signJwt(options.signer, {
|
|
1137
|
-
header,
|
|
1138
|
-
payload
|
|
1139
|
-
});
|
|
1140
|
-
return jwt;
|
|
1141
|
-
}
|
|
1142
|
-
async function verifyDpopJwt(options) {
|
|
1143
|
-
try {
|
|
1144
|
-
const { header, payload } = decodeJwt({
|
|
1145
|
-
jwt: options.dpopJwt,
|
|
1146
|
-
headerSchema: zDpopJwtHeader,
|
|
1147
|
-
payloadSchema: zDpopJwtPayload
|
|
1148
|
-
});
|
|
1149
|
-
if (options.allowedSigningAlgs && !options.allowedSigningAlgs.includes(header.alg)) throw new Oauth2Error(`dpop jwt uses alg value '${header.alg}' but allowed dpop signging alg values are ${options.allowedSigningAlgs.join(", ")}.`);
|
|
1150
|
-
if (options.expectedNonce) {
|
|
1151
|
-
if (!payload.nonce) throw new Oauth2Error(`Dpop jwt does not have a nonce value, but expected nonce value '${options.expectedNonce}'`);
|
|
1152
|
-
if (payload.nonce !== options.expectedNonce) throw new Oauth2Error(`Dpop jwt contains nonce value '${payload.nonce}', but expected nonce value '${options.expectedNonce}'`);
|
|
1153
|
-
}
|
|
1154
|
-
if (options.request.method !== payload.htm) throw new Oauth2Error(`Dpop jwt contains htm value '${payload.htm}', but expected htm value '${options.request.method}'`);
|
|
1155
|
-
const expectedHtu = htuFromRequestUrl(options.request.url);
|
|
1156
|
-
if (expectedHtu !== payload.htu) throw new Oauth2Error(`Dpop jwt contains htu value '${payload.htu}', but expected htu value '${expectedHtu}'.`);
|
|
1157
|
-
if (options.accessToken) {
|
|
1158
|
-
const expectedAth = encodeToBase64Url(await options.callbacks.hash(decodeUtf8String(options.accessToken), HashAlgorithm.Sha256));
|
|
1159
|
-
if (!payload.ath) throw new Oauth2Error(`Dpop jwt does not have a ath value, but expected ath value '${expectedAth}'.`);
|
|
1160
|
-
if (payload.ath !== expectedAth) throw new Oauth2Error(`Dpop jwt contains ath value '${payload.ath}', but expected ath value '${expectedAth}'.`);
|
|
1161
|
-
}
|
|
1162
|
-
const jwkThumbprint = await calculateJwkThumbprint({
|
|
1163
|
-
hashAlgorithm: HashAlgorithm.Sha256,
|
|
1164
|
-
hashCallback: options.callbacks.hash,
|
|
1165
|
-
jwk: header.jwk
|
|
1166
|
-
});
|
|
1167
|
-
if (options.expectedJwkThumbprint && options.expectedJwkThumbprint !== jwkThumbprint) throw new Oauth2Error(`Dpop is signed with jwk with thumbprint value '${jwkThumbprint}', but expect jwk thumbprint value '${options.expectedJwkThumbprint}'`);
|
|
1168
|
-
await verifyJwt({
|
|
1169
|
-
signer: {
|
|
1170
|
-
alg: header.alg,
|
|
1171
|
-
method: "jwk",
|
|
1172
|
-
publicJwk: header.jwk
|
|
1173
|
-
},
|
|
1174
|
-
now: options.now,
|
|
1175
|
-
header,
|
|
1176
|
-
payload,
|
|
1177
|
-
compact: options.dpopJwt,
|
|
1178
|
-
verifyJwtCallback: options.callbacks.verifyJwt,
|
|
1179
|
-
errorMessage: "dpop jwt verification failed"
|
|
1180
|
-
});
|
|
1181
|
-
return {
|
|
1182
|
-
header,
|
|
1183
|
-
payload,
|
|
1184
|
-
jwkThumbprint
|
|
1185
|
-
};
|
|
1186
|
-
} catch (error) {
|
|
1187
|
-
if (error instanceof Oauth2Error) throw new Oauth2ServerErrorResponseError({
|
|
1188
|
-
error: Oauth2ErrorCodes.InvalidDpopProof,
|
|
1189
|
-
error_description: error.message
|
|
1190
|
-
});
|
|
1191
|
-
throw error;
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
function htuFromRequestUrl(requestUrl) {
|
|
1195
|
-
const htu = new URL(requestUrl);
|
|
1196
|
-
htu.search = "";
|
|
1197
|
-
htu.hash = "";
|
|
1198
|
-
return htu.toString();
|
|
1199
|
-
}
|
|
1200
|
-
function extractDpopNonceFromHeaders(headers) {
|
|
1201
|
-
return headers.get("DPoP-Nonce");
|
|
1202
|
-
}
|
|
1203
|
-
function extractDpopJwtFromHeaders(headers) {
|
|
1204
|
-
const dpopJwt = headers.get("DPoP");
|
|
1205
|
-
if (!dpopJwt) return { valid: true };
|
|
1206
|
-
if (!zCompactJwt.safeParse(dpopJwt).success) return { valid: false };
|
|
1207
|
-
return {
|
|
1208
|
-
valid: true,
|
|
1209
|
-
dpopJwt
|
|
1210
|
-
};
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
1340
|
//#endregion
|
|
1214
1341
|
//#region src/access-token/parse-access-token-request.ts
|
|
1215
1342
|
/**
|
|
@@ -1465,29 +1592,6 @@ async function verifyAccessTokenRequestPkce(options, callbacks) {
|
|
|
1465
1592
|
}
|
|
1466
1593
|
}
|
|
1467
1594
|
|
|
1468
|
-
//#endregion
|
|
1469
|
-
//#region src/authorization-request/z-authorization-request.ts
|
|
1470
|
-
const zAuthorizationRequest = z$1.object({
|
|
1471
|
-
response_type: z$1.string(),
|
|
1472
|
-
client_id: z$1.string(),
|
|
1473
|
-
issuer_state: z$1.optional(z$1.string()),
|
|
1474
|
-
redirect_uri: z$1.url().optional(),
|
|
1475
|
-
resource: z$1.optional(zHttpsUrl),
|
|
1476
|
-
scope: z$1.optional(z$1.string()),
|
|
1477
|
-
state: z$1.optional(z$1.string()),
|
|
1478
|
-
dpop_jkt: z$1.optional(z$1.base64url()),
|
|
1479
|
-
code_challenge: z$1.optional(z$1.string()),
|
|
1480
|
-
code_challenge_method: z$1.optional(z$1.string())
|
|
1481
|
-
}).loose();
|
|
1482
|
-
const zPushedAuthorizationRequest = z$1.object({
|
|
1483
|
-
request_uri: z$1.string(),
|
|
1484
|
-
client_id: z$1.string()
|
|
1485
|
-
}).loose();
|
|
1486
|
-
const zPushedAuthorizationResponse = z$1.object({
|
|
1487
|
-
request_uri: z$1.string(),
|
|
1488
|
-
expires_in: z$1.number().int()
|
|
1489
|
-
}).loose();
|
|
1490
|
-
|
|
1491
1595
|
//#endregion
|
|
1492
1596
|
//#region src/authorization-challenge/z-authorization-challenge.ts
|
|
1493
1597
|
const zAuthorizationChallengeRequest = z$1.object({
|
|
@@ -1538,39 +1642,6 @@ function createAuthorizationChallengeErrorResponse(options) {
|
|
|
1538
1642
|
});
|
|
1539
1643
|
}
|
|
1540
1644
|
|
|
1541
|
-
//#endregion
|
|
1542
|
-
//#region src/authorization-request/parse-authorization-request.ts
|
|
1543
|
-
/**
|
|
1544
|
-
* Parse an authorization request.
|
|
1545
|
-
*
|
|
1546
|
-
* @throws {Oauth2ServerErrorResponseError}
|
|
1547
|
-
*/
|
|
1548
|
-
function parseAuthorizationRequest(options) {
|
|
1549
|
-
const extractedDpopJwt = extractDpopJwtFromHeaders(options.request.headers);
|
|
1550
|
-
if (!extractedDpopJwt.valid) throw new Oauth2ServerErrorResponseError({
|
|
1551
|
-
error: Oauth2ErrorCodes.InvalidDpopProof,
|
|
1552
|
-
error_description: `Request contains a 'DPoP' header, but the value is not a valid DPoP jwt`
|
|
1553
|
-
});
|
|
1554
|
-
const extractedClientAttestationJwts = extractClientAttestationJwtsFromHeaders(options.request.headers);
|
|
1555
|
-
if (!extractedClientAttestationJwts.valid) throw new Oauth2ServerErrorResponseError({
|
|
1556
|
-
error: Oauth2ErrorCodes.InvalidClient,
|
|
1557
|
-
error_description: "Request contains client attestation header, but the values are not valid client attestation and client attestation PoP header."
|
|
1558
|
-
});
|
|
1559
|
-
return {
|
|
1560
|
-
dpop: extractedDpopJwt.dpopJwt ? {
|
|
1561
|
-
jwt: extractedDpopJwt.dpopJwt,
|
|
1562
|
-
jwkThumbprint: options.authorizationRequest.dpop_jkt
|
|
1563
|
-
} : options.authorizationRequest.dpop_jkt ? {
|
|
1564
|
-
jwt: extractedDpopJwt.dpopJwt,
|
|
1565
|
-
jwkThumbprint: options.authorizationRequest.dpop_jkt
|
|
1566
|
-
} : void 0,
|
|
1567
|
-
clientAttestation: extractedClientAttestationJwts.clientAttestationHeader ? {
|
|
1568
|
-
clientAttestationJwt: extractedClientAttestationJwts.clientAttestationHeader,
|
|
1569
|
-
clientAttestationPopJwt: extractedClientAttestationJwts.clientAttestationPopHeader
|
|
1570
|
-
} : void 0
|
|
1571
|
-
};
|
|
1572
|
-
}
|
|
1573
|
-
|
|
1574
1645
|
//#endregion
|
|
1575
1646
|
//#region src/authorization-challenge/parse-authorization-challenge-request.ts
|
|
1576
1647
|
/**
|
|
@@ -1702,31 +1773,6 @@ function createPushedAuthorizationErrorResponse(options) {
|
|
|
1702
1773
|
});
|
|
1703
1774
|
}
|
|
1704
1775
|
|
|
1705
|
-
//#endregion
|
|
1706
|
-
//#region src/authorization-request/parse-pushed-authorization-request.ts
|
|
1707
|
-
/**
|
|
1708
|
-
* Parse an pushed authorization request.
|
|
1709
|
-
*
|
|
1710
|
-
* @throws {Oauth2ServerErrorResponseError}
|
|
1711
|
-
*/
|
|
1712
|
-
function parsePushedAuthorizationRequest(options) {
|
|
1713
|
-
const parsedAuthorizationRequest = zAuthorizationRequest.safeParse(options.authorizationRequest);
|
|
1714
|
-
if (!parsedAuthorizationRequest.success) throw new Oauth2ServerErrorResponseError({
|
|
1715
|
-
error: Oauth2ErrorCodes.InvalidRequest,
|
|
1716
|
-
error_description: `Error occurred during validation of pushed authorization request.\n${formatZodError(parsedAuthorizationRequest.error)}`
|
|
1717
|
-
});
|
|
1718
|
-
const authorizationRequest = parsedAuthorizationRequest.data;
|
|
1719
|
-
const { clientAttestation, dpop } = parseAuthorizationRequest({
|
|
1720
|
-
authorizationRequest,
|
|
1721
|
-
request: options.request
|
|
1722
|
-
});
|
|
1723
|
-
return {
|
|
1724
|
-
authorizationRequest,
|
|
1725
|
-
dpop,
|
|
1726
|
-
clientAttestation
|
|
1727
|
-
};
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
1776
|
//#endregion
|
|
1731
1777
|
//#region src/authorization-request/verify-pushed-authorization-request.ts
|
|
1732
1778
|
async function verifyPushedAuthorizationRequest(options) {
|
|
@@ -2544,5 +2590,5 @@ async function verifyResourceRequest(options) {
|
|
|
2544
2590
|
}
|
|
2545
2591
|
|
|
2546
2592
|
//#endregion
|
|
2547
|
-
export { HashAlgorithm, InvalidFetchResponseError, Oauth2AuthorizationServer, Oauth2Client, Oauth2ClientAuthorizationChallengeError, Oauth2ClientErrorResponseError, Oauth2Error, Oauth2ErrorCodes, Oauth2JwtParseError, Oauth2JwtVerificationError, Oauth2ResourceServer, Oauth2ResourceUnauthorizedError, Oauth2ServerErrorResponseError, PkceCodeChallengeMethod, SupportedAuthenticationScheme, SupportedClientAuthenticationMethod, authorizationCodeGrantIdentifier, calculateJwkThumbprint, clientAuthenticationAnonymous, clientAuthenticationClientAttestationJwt, clientAuthenticationClientSecretBasic, clientAuthenticationClientSecretPost, clientAuthenticationDynamic, clientAuthenticationNone, createClientAttestationJwt, decodeJwt, decodeJwtHeader, fetchAuthorizationServerMetadata, fetchJwks, fetchWellKnownMetadata, getAuthorizationServerMetadataFromList, getGlobalConfig, isJwkInSet, jwtHeaderFromJwtSigner, jwtSignerFromJwt, preAuthorizedCodeGrantIdentifier, refreshTokenGrantIdentifier, resourceRequest, setGlobalConfig, verifyClientAttestationJwt, verifyIdTokenJwt, verifyJwt, verifyResourceRequest, zAlgValueNotNone, zAuthorizationCodeGrantIdentifier, zAuthorizationServerMetadata, zCompactJwe, zCompactJwt, zIdTokenJwtHeader, zIdTokenJwtPayload, zJwk, zJwkSet, zJwtHeader, zJwtPayload, zOauth2ErrorResponse, zPreAuthorizedCodeGrantIdentifier, zRefreshTokenGrantIdentifier };
|
|
2593
|
+
export { HashAlgorithm, InvalidFetchResponseError, Oauth2AuthorizationServer, Oauth2Client, Oauth2ClientAuthorizationChallengeError, Oauth2ClientErrorResponseError, Oauth2Error, Oauth2ErrorCodes, Oauth2JwtParseError, Oauth2JwtVerificationError, Oauth2ResourceServer, Oauth2ResourceUnauthorizedError, Oauth2ServerErrorResponseError, PkceCodeChallengeMethod, SupportedAuthenticationScheme, SupportedClientAuthenticationMethod, authorizationCodeGrantIdentifier, calculateJwkThumbprint, clientAuthenticationAnonymous, clientAuthenticationClientAttestationJwt, clientAuthenticationClientSecretBasic, clientAuthenticationClientSecretPost, clientAuthenticationDynamic, clientAuthenticationNone, createClientAttestationJwt, decodeJwt, decodeJwtHeader, fetchAuthorizationServerMetadata, fetchJwks, fetchWellKnownMetadata, getAuthorizationServerMetadataFromList, getGlobalConfig, isJwkInSet, jwtHeaderFromJwtSigner, jwtSignerFromJwt, parseAuthorizationResponseRedirectUrl, parsePushedAuthorizationRequestUri, preAuthorizedCodeGrantIdentifier, pushedAuthorizationRequestUriPrefix, refreshTokenGrantIdentifier, resourceRequest, setGlobalConfig, verifyClientAttestationJwt, verifyIdTokenJwt, verifyJwt, verifyResourceRequest, zAlgValueNotNone, zAuthorizationCodeGrantIdentifier, zAuthorizationErrorResponse, zAuthorizationResponse, zAuthorizationResponseFromUriParams, zAuthorizationServerMetadata, zCompactJwe, zCompactJwt, zIdTokenJwtHeader, zIdTokenJwtPayload, zJwk, zJwkSet, zJwtHeader, zJwtPayload, zOauth2ErrorResponse, zPreAuthorizedCodeGrantIdentifier, zPushedAuthorizationRequestUriPrefix, zRefreshTokenGrantIdentifier };
|
|
2548
2594
|
//# sourceMappingURL=index.mjs.map
|