@absolutejs/auth 0.55.0 → 0.55.1
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/README.md +7 -0
- package/dist/agents/index.js +43 -36
- package/dist/agents/index.js.map +3 -3
- package/dist/agents/routes.d.ts +32 -0
- package/dist/apikeys/routes.d.ts +2 -2
- package/dist/authInstance.d.ts +12 -0
- package/dist/authorization/protectPermission.d.ts +2 -2
- package/dist/credentials/login.d.ts +4 -4
- package/dist/credentials/routes.d.ts +4 -4
- package/dist/index.d.ts +3 -303
- package/dist/index.js +154 -143
- package/dist/index.js.map +5 -5
- package/dist/mfa/routes.d.ts +2 -2
- package/dist/mfa/sms.d.ts +2 -2
- package/dist/oidc/routes.d.ts +14 -14
- package/dist/organizations/routes.d.ts +1 -1
- package/dist/portal/routes.d.ts +3 -3
- package/dist/roles/routes.d.ts +1 -1
- package/dist/routes/protectRoute.d.ts +2 -2
- package/dist/routes/refresh.d.ts +1 -1
- package/dist/routes/revoke.d.ts +1 -1
- package/dist/routes/sessions.d.ts +3 -3
- package/dist/server.d.ts +18 -0
- package/dist/server.js +29362 -0
- package/dist/server.js.map +287 -0
- package/dist/sso/discoveryRoute.d.ts +1 -1
- package/dist/sso/oidcRoutes.d.ts +2 -2
- package/dist/sso/samlRoutes.d.ts +4 -4
- package/dist/utils.d.ts +1 -1
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -3780,10 +3780,16 @@ var revokeAgentIdentityRegistration = async (config, registrationId, now = Date.
|
|
|
3780
3780
|
};
|
|
3781
3781
|
|
|
3782
3782
|
// src/agents/routes.ts
|
|
3783
|
+
var DELETE_CODE_POINT = 127;
|
|
3784
|
+
var HTTP_BAD_REQUEST2 = 400;
|
|
3785
|
+
var HTTP_FORBIDDEN = 403;
|
|
3786
|
+
var HTTP_OK2 = 200;
|
|
3787
|
+
var HTTP_UNAUTHORIZED2 = 401;
|
|
3788
|
+
var MINIMUM_PRINTABLE_CODE_POINT = 32;
|
|
3783
3789
|
var quoteHeaderValue = (value) => {
|
|
3784
3790
|
const printable = [...value].filter((character) => {
|
|
3785
3791
|
const codePoint = character.codePointAt(0) ?? 0;
|
|
3786
|
-
return codePoint >=
|
|
3792
|
+
return codePoint >= MINIMUM_PRINTABLE_CODE_POINT && codePoint !== DELETE_CODE_POINT;
|
|
3787
3793
|
}).join("");
|
|
3788
3794
|
return `"${printable.replace(/[\\"]/g, "\\$&")}"`;
|
|
3789
3795
|
};
|
|
@@ -3816,9 +3822,9 @@ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.str
|
|
|
3816
3822
|
requiredScopes
|
|
3817
3823
|
})
|
|
3818
3824
|
},
|
|
3819
|
-
status: failure.code === "Forbidden" ?
|
|
3825
|
+
status: failure.code === "Forbidden" ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED2
|
|
3820
3826
|
});
|
|
3821
|
-
var json = (value, status =
|
|
3827
|
+
var json = (value, status = HTTP_OK2) => new Response(JSON.stringify(value), {
|
|
3822
3828
|
headers: {
|
|
3823
3829
|
"cache-control": "no-store",
|
|
3824
3830
|
"content-type": "application/json"
|
|
@@ -3852,7 +3858,7 @@ var registrationResponse = (result) => {
|
|
|
3852
3858
|
...body,
|
|
3853
3859
|
error: "interaction_required",
|
|
3854
3860
|
error_description: "Authenticate at the service and confirm the account link."
|
|
3855
|
-
},
|
|
3861
|
+
}, HTTP_UNAUTHORIZED2);
|
|
3856
3862
|
}
|
|
3857
3863
|
return json(body);
|
|
3858
3864
|
};
|
|
@@ -3879,34 +3885,35 @@ var parseRegistrationInput = (value) => {
|
|
|
3879
3885
|
return input;
|
|
3880
3886
|
};
|
|
3881
3887
|
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
3882
|
-
var
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: 401 });
|
|
3891
|
-
}
|
|
3892
|
-
const principal = await resolveAgentPrincipal(request, config);
|
|
3893
|
-
if (principal === undefined) {
|
|
3894
|
-
const failure = {
|
|
3895
|
-
code: "Unauthorized",
|
|
3896
|
-
message: "Agent is not authenticated"
|
|
3897
|
-
};
|
|
3898
|
-
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
3899
|
-
}
|
|
3900
|
-
if (!agentHasScopes(principal, requiredScopes)) {
|
|
3901
|
-
const failure = {
|
|
3902
|
-
code: "Forbidden",
|
|
3903
|
-
message: "Insufficient agent scopes"
|
|
3904
|
-
};
|
|
3905
|
-
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
3906
|
-
}
|
|
3907
|
-
return handleAuth(principal);
|
|
3888
|
+
var agentAuthContextPlugin = (config) => new Elysia2().derive(({ request }) => ({
|
|
3889
|
+
protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
|
|
3890
|
+
if (config === undefined) {
|
|
3891
|
+
const failure = {
|
|
3892
|
+
code: "Unauthorized",
|
|
3893
|
+
message: "Agent is not authenticated"
|
|
3894
|
+
};
|
|
3895
|
+
return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: 401 });
|
|
3908
3896
|
}
|
|
3909
|
-
|
|
3897
|
+
const principal = await resolveAgentPrincipal(request, config);
|
|
3898
|
+
if (principal === undefined) {
|
|
3899
|
+
const failure = {
|
|
3900
|
+
code: "Unauthorized",
|
|
3901
|
+
message: "Agent is not authenticated"
|
|
3902
|
+
};
|
|
3903
|
+
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
3904
|
+
}
|
|
3905
|
+
if (!agentHasScopes(principal, requiredScopes)) {
|
|
3906
|
+
const failure = {
|
|
3907
|
+
code: "Forbidden",
|
|
3908
|
+
message: "Insufficient agent scopes"
|
|
3909
|
+
};
|
|
3910
|
+
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
3911
|
+
}
|
|
3912
|
+
return handleAuth(principal);
|
|
3913
|
+
}
|
|
3914
|
+
}));
|
|
3915
|
+
var agentAuthPlugin = (config) => {
|
|
3916
|
+
const plugin = agentAuthContextPlugin(config);
|
|
3910
3917
|
if (config === undefined)
|
|
3911
3918
|
return plugin.as("global");
|
|
3912
3919
|
if (config.agentRegistration === undefined) {
|
|
@@ -3937,11 +3944,11 @@ var agentAuthPlugin = (config) => {
|
|
|
3937
3944
|
}).post(identityRoute, async ({ body }) => {
|
|
3938
3945
|
const value = recordBody(body);
|
|
3939
3946
|
if (value === undefined || typeof value.type !== "string") {
|
|
3940
|
-
return json({ error: "invalid_request" },
|
|
3947
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST2);
|
|
3941
3948
|
}
|
|
3942
3949
|
const input = parseRegistrationInput(value);
|
|
3943
3950
|
if (input === undefined)
|
|
3944
|
-
return json({ error: "invalid_request" },
|
|
3951
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST2);
|
|
3945
3952
|
const result = await startAgentRegistration(config, input);
|
|
3946
3953
|
if ("error" in result) {
|
|
3947
3954
|
return json({
|
|
@@ -3953,7 +3960,7 @@ var agentAuthPlugin = (config) => {
|
|
|
3953
3960
|
}).post(claimRoute, async ({ body }) => {
|
|
3954
3961
|
const value = recordBody(body);
|
|
3955
3962
|
if (value === undefined || typeof value.claim_token !== "string" || typeof value.email !== "string") {
|
|
3956
|
-
return json({ error: "invalid_request" },
|
|
3963
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST2);
|
|
3957
3964
|
}
|
|
3958
3965
|
const result = await beginAgentClaim(config, {
|
|
3959
3966
|
claimToken: value.claim_token,
|
|
@@ -3968,7 +3975,7 @@ var agentAuthPlugin = (config) => {
|
|
|
3968
3975
|
value = Object.fromEntries(new URLSearchParams(body));
|
|
3969
3976
|
}
|
|
3970
3977
|
if (value === undefined || typeof value.claim_attempt_token !== "string" || typeof value.user_code !== "string") {
|
|
3971
|
-
return json({ error: "invalid_request" },
|
|
3978
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST2);
|
|
3972
3979
|
}
|
|
3973
3980
|
const result = await completeAgentClaim(config, {
|
|
3974
3981
|
attemptToken: value.claim_attempt_token,
|
|
@@ -4281,6 +4288,11 @@ import { Elysia as Elysia5, t as t4 } from "elysia";
|
|
|
4281
4288
|
|
|
4282
4289
|
// src/utils.ts
|
|
4283
4290
|
init_constants();
|
|
4291
|
+
var MILLISECONDS_IN_A_SECOND2 = 1000;
|
|
4292
|
+
var readOptionalString = (value, property) => {
|
|
4293
|
+
const candidate = Reflect.get(value, property);
|
|
4294
|
+
return typeof candidate === "string" ? candidate : undefined;
|
|
4295
|
+
};
|
|
4284
4296
|
var defineAuthConfig = (configuration) => configuration;
|
|
4285
4297
|
var defineAuthHtmxConfig = (htmxConfig) => htmxConfig;
|
|
4286
4298
|
var defineAuthSettings = (settings) => settings;
|
|
@@ -4376,14 +4388,10 @@ var resolveOAuthAuthorization = async ({
|
|
|
4376
4388
|
let userIdentity;
|
|
4377
4389
|
let accessToken = tokenResponse.access_token;
|
|
4378
4390
|
let refreshToken = tokenResponse.refresh_token;
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
if (typeof nestedAccessToken === "string") {
|
|
4384
|
-
accessToken = nestedAccessToken;
|
|
4385
|
-
}
|
|
4386
|
-
}
|
|
4391
|
+
const withingsBody = Reflect.get(tokenResponse, "body");
|
|
4392
|
+
const withingsAccessToken = authProvider === "withings" && withingsBody !== null && typeof withingsBody === "object" ? readOptionalString(withingsBody, "access_token") : undefined;
|
|
4393
|
+
if (!accessToken && withingsAccessToken !== undefined) {
|
|
4394
|
+
accessToken = withingsAccessToken;
|
|
4387
4395
|
}
|
|
4388
4396
|
if (typeof accessToken !== "string" || accessToken.length === 0) {
|
|
4389
4397
|
throw new Error("OAuth authorization response contains no access_token");
|
|
@@ -4401,9 +4409,12 @@ var resolveOAuthAuthorization = async ({
|
|
|
4401
4409
|
source: "tokenResponse"
|
|
4402
4410
|
});
|
|
4403
4411
|
} else if (authProvider === "withings") {
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4412
|
+
if (withingsBody === null || typeof withingsBody !== "object") {
|
|
4413
|
+
throw new Error("Withings OAuth response contains no body");
|
|
4414
|
+
}
|
|
4415
|
+
userIdentity = { userid: Reflect.get(withingsBody, "userid") };
|
|
4416
|
+
accessToken = readOptionalString(withingsBody, "access_token") ?? accessToken;
|
|
4417
|
+
refreshToken = readOptionalString(withingsBody, "refresh_token") ?? refreshToken;
|
|
4407
4418
|
} else {
|
|
4408
4419
|
userIdentity = normalizeProviderIdentity({
|
|
4409
4420
|
identity: await providerInstance.fetchUserProfile(accessToken),
|
|
@@ -4435,7 +4446,7 @@ var resolveOAuthTokenExpiresAt = (tokenResponse, now = Date.now()) => {
|
|
|
4435
4446
|
if (!Number.isFinite(expiresInSeconds) || expiresInSeconds <= 0) {
|
|
4436
4447
|
return;
|
|
4437
4448
|
}
|
|
4438
|
-
return now + expiresInSeconds *
|
|
4449
|
+
return now + expiresInSeconds * MILLISECONDS_IN_A_SECOND2;
|
|
4439
4450
|
};
|
|
4440
4451
|
var validateSession = ({
|
|
4441
4452
|
user_session_id,
|
|
@@ -7445,11 +7456,11 @@ var updateRegisteredClient = async ({
|
|
|
7445
7456
|
};
|
|
7446
7457
|
|
|
7447
7458
|
// src/oidc/routes.ts
|
|
7448
|
-
var
|
|
7459
|
+
var HTTP_OK3 = 200;
|
|
7449
7460
|
var HTTP_NO_CONTENT = 204;
|
|
7450
7461
|
var HTTP_FOUND = 302;
|
|
7451
|
-
var
|
|
7452
|
-
var
|
|
7462
|
+
var HTTP_BAD_REQUEST3 = 400;
|
|
7463
|
+
var HTTP_UNAUTHORIZED3 = 401;
|
|
7453
7464
|
var HTTP_NOT_IMPLEMENTED = 501;
|
|
7454
7465
|
var CODE_TTL_MINUTES = 10;
|
|
7455
7466
|
var CODE_TTL_MS = MILLISECONDS_IN_A_MINUTE * CODE_TTL_MINUTES;
|
|
@@ -7463,7 +7474,7 @@ var jsonResponse = (value, status) => new Response(JSON.stringify(value), {
|
|
|
7463
7474
|
status
|
|
7464
7475
|
});
|
|
7465
7476
|
var oauthError2 = (status, error) => jsonResponse({ error }, status);
|
|
7466
|
-
var tokenResponse = (tokens) => jsonResponse(tokens,
|
|
7477
|
+
var tokenResponse = (tokens) => jsonResponse(tokens, HTTP_OK3);
|
|
7467
7478
|
var canonicalizeRequestUrl = (requestUrl, issuer) => {
|
|
7468
7479
|
try {
|
|
7469
7480
|
const url = new URL(requestUrl);
|
|
@@ -7485,7 +7496,7 @@ var formPostResponse = (redirectUri, params) => {
|
|
|
7485
7496
|
"cache-control": "no-store",
|
|
7486
7497
|
"content-type": "text/html;charset=UTF-8"
|
|
7487
7498
|
},
|
|
7488
|
-
status:
|
|
7499
|
+
status: HTTP_OK3
|
|
7489
7500
|
});
|
|
7490
7501
|
};
|
|
7491
7502
|
var respondToClient = (redirectUri, responseMode, params) => {
|
|
@@ -7623,7 +7634,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7623
7634
|
"dpop-nonce": fresh,
|
|
7624
7635
|
"www-authenticate": 'DPoP error="use_dpop_nonce"'
|
|
7625
7636
|
},
|
|
7626
|
-
status:
|
|
7637
|
+
status: HTTP_UNAUTHORIZED3
|
|
7627
7638
|
});
|
|
7628
7639
|
};
|
|
7629
7640
|
const grantAuthorizationCode = async (client, body, dpop, clientCertThumbprint) => {
|
|
@@ -7633,11 +7644,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
7633
7644
|
redirect_uri: redirectUri
|
|
7634
7645
|
} = body;
|
|
7635
7646
|
if (code === undefined || codeVerifier === undefined || redirectUri === undefined) {
|
|
7636
|
-
return oauthError2(
|
|
7647
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7637
7648
|
}
|
|
7638
7649
|
const record = await authorizationCodeStore.consumeCode(await hashToken(code));
|
|
7639
7650
|
if (record === undefined || record.expiresAt < Date.now() || record.clientId !== client.clientId || record.redirectUri !== redirectUri || !await verifyPkce(codeVerifier, record.codeChallenge)) {
|
|
7640
|
-
return oauthError2(
|
|
7651
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_grant");
|
|
7641
7652
|
}
|
|
7642
7653
|
const dpopResult = dpop === undefined ? undefined : await verifyDpopProof({
|
|
7643
7654
|
htm: "POST",
|
|
@@ -7645,7 +7656,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7645
7656
|
proof: dpop
|
|
7646
7657
|
});
|
|
7647
7658
|
if (dpop !== undefined && dpopResult === undefined) {
|
|
7648
|
-
return oauthError2(
|
|
7659
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7649
7660
|
}
|
|
7650
7661
|
return tokenResponse(await issueTokenSet({
|
|
7651
7662
|
acr: record.acr,
|
|
@@ -7662,11 +7673,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
7662
7673
|
const grantRefreshToken = async (client, body, dpop, clientCertThumbprint) => {
|
|
7663
7674
|
const presented = body.refresh_token;
|
|
7664
7675
|
if (presented === undefined) {
|
|
7665
|
-
return oauthError2(
|
|
7676
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7666
7677
|
}
|
|
7667
7678
|
const record = await refreshTokenStore.consumeToken(await hashToken(presented));
|
|
7668
7679
|
if (record === undefined || record.expiresAt < Date.now() || record.clientId !== client.clientId) {
|
|
7669
|
-
return oauthError2(
|
|
7680
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_grant");
|
|
7670
7681
|
}
|
|
7671
7682
|
if (record.dpopJkt !== undefined) {
|
|
7672
7683
|
const proof = await verifyDpopProof({
|
|
@@ -7675,7 +7686,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7675
7686
|
proof: dpop
|
|
7676
7687
|
});
|
|
7677
7688
|
if (proof === undefined || proof.jkt !== record.dpopJkt) {
|
|
7678
|
-
return oauthError2(
|
|
7689
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7679
7690
|
}
|
|
7680
7691
|
}
|
|
7681
7692
|
return tokenResponse(await issueTokenSet({
|
|
@@ -7691,7 +7702,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7691
7702
|
};
|
|
7692
7703
|
const grantTokenExchange = async (client, body, dpop) => {
|
|
7693
7704
|
if (body.subject_token === undefined) {
|
|
7694
|
-
return oauthError2(
|
|
7705
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7695
7706
|
}
|
|
7696
7707
|
const dpopResult = dpop === undefined ? undefined : await verifyDpopProof({
|
|
7697
7708
|
htm: "POST",
|
|
@@ -7699,7 +7710,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7699
7710
|
proof: dpop
|
|
7700
7711
|
});
|
|
7701
7712
|
if (dpop !== undefined && dpopResult === undefined) {
|
|
7702
|
-
return oauthError2(
|
|
7713
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7703
7714
|
}
|
|
7704
7715
|
const result = await exchangeToken({
|
|
7705
7716
|
actorClientId: client.clientId,
|
|
@@ -7710,21 +7721,21 @@ var oidcProviderRoutes = (config) => {
|
|
|
7710
7721
|
subjectToken: body.subject_token
|
|
7711
7722
|
});
|
|
7712
7723
|
if (!result.ok)
|
|
7713
|
-
return oauthError2(
|
|
7724
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
7714
7725
|
return jsonResponse({
|
|
7715
7726
|
access_token: result.accessToken,
|
|
7716
7727
|
expires_in: result.expiresIn,
|
|
7717
7728
|
issued_token_type: "urn:ietf:params:oauth:token-type:access_token",
|
|
7718
7729
|
scope: result.scope,
|
|
7719
7730
|
token_type: dpopResult === undefined ? "Bearer" : "DPoP"
|
|
7720
|
-
},
|
|
7731
|
+
}, HTTP_OK3);
|
|
7721
7732
|
};
|
|
7722
7733
|
const grantBackchannel = async (client, body, dpop, clientCertThumbprint) => {
|
|
7723
7734
|
if (config.backchannelAuthStore === undefined) {
|
|
7724
|
-
return oauthError2(
|
|
7735
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
7725
7736
|
}
|
|
7726
7737
|
if (body.auth_req_id === undefined) {
|
|
7727
|
-
return oauthError2(
|
|
7738
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7728
7739
|
}
|
|
7729
7740
|
const dpopResult = dpop === undefined ? undefined : await verifyDpopProof({
|
|
7730
7741
|
htm: "POST",
|
|
@@ -7732,7 +7743,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7732
7743
|
proof: dpop
|
|
7733
7744
|
});
|
|
7734
7745
|
if (dpop !== undefined && dpopResult === undefined) {
|
|
7735
|
-
return oauthError2(
|
|
7746
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7736
7747
|
}
|
|
7737
7748
|
const result = await exchangeBackchannelAuth({
|
|
7738
7749
|
authReqId: body.auth_req_id,
|
|
@@ -7742,7 +7753,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7742
7753
|
dpopJkt: dpopResult?.jkt
|
|
7743
7754
|
});
|
|
7744
7755
|
if (!result.ok)
|
|
7745
|
-
return oauthError2(
|
|
7756
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
7746
7757
|
return jsonResponse({
|
|
7747
7758
|
access_token: result.access_token,
|
|
7748
7759
|
expires_in: result.expires_in,
|
|
@@ -7750,14 +7761,14 @@ var oidcProviderRoutes = (config) => {
|
|
|
7750
7761
|
refresh_token: result.refresh_token,
|
|
7751
7762
|
scope: result.scope,
|
|
7752
7763
|
token_type: dpopResult === undefined ? "Bearer" : "DPoP"
|
|
7753
|
-
},
|
|
7764
|
+
}, HTTP_OK3);
|
|
7754
7765
|
};
|
|
7755
7766
|
const grantDeviceCode = async (client, body, dpop) => {
|
|
7756
7767
|
if (config.deviceAuthorizationStore === undefined) {
|
|
7757
|
-
return oauthError2(
|
|
7768
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
7758
7769
|
}
|
|
7759
7770
|
if (body.device_code === undefined) {
|
|
7760
|
-
return oauthError2(
|
|
7771
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7761
7772
|
}
|
|
7762
7773
|
const dpopResult = dpop === undefined ? undefined : await verifyDpopProof({
|
|
7763
7774
|
htm: "POST",
|
|
@@ -7765,7 +7776,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7765
7776
|
proof: dpop
|
|
7766
7777
|
});
|
|
7767
7778
|
if (dpop !== undefined && dpopResult === undefined) {
|
|
7768
|
-
return oauthError2(
|
|
7779
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7769
7780
|
}
|
|
7770
7781
|
const result = await exchangeDeviceCode({
|
|
7771
7782
|
clientId: client.clientId,
|
|
@@ -7774,7 +7785,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7774
7785
|
dpopJkt: dpopResult?.jkt
|
|
7775
7786
|
});
|
|
7776
7787
|
if (!result.ok)
|
|
7777
|
-
return oauthError2(
|
|
7788
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
7778
7789
|
return jsonResponse({
|
|
7779
7790
|
access_token: result.access_token,
|
|
7780
7791
|
expires_in: result.expires_in,
|
|
@@ -7782,7 +7793,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7782
7793
|
refresh_token: result.refresh_token,
|
|
7783
7794
|
scope: result.scope,
|
|
7784
7795
|
token_type: dpopResult === undefined ? "Bearer" : "DPoP"
|
|
7785
|
-
},
|
|
7796
|
+
}, HTTP_OK3);
|
|
7786
7797
|
};
|
|
7787
7798
|
const grantTypes = [
|
|
7788
7799
|
"authorization_code",
|
|
@@ -7895,7 +7906,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7895
7906
|
requestedUri: query.post_logout_redirect_uri
|
|
7896
7907
|
});
|
|
7897
7908
|
if (redirectUri === undefined) {
|
|
7898
|
-
return jsonResponse({ ok: true },
|
|
7909
|
+
return jsonResponse({ ok: true }, HTTP_OK3);
|
|
7899
7910
|
}
|
|
7900
7911
|
const url = new URL(redirectUri);
|
|
7901
7912
|
if (query.state !== undefined)
|
|
@@ -7916,11 +7927,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
7916
7927
|
store: config.pushedAuthorizationRequestStore
|
|
7917
7928
|
});
|
|
7918
7929
|
if (pushed === undefined) {
|
|
7919
|
-
return jsonResponse({ error: "invalid_request_uri" },
|
|
7930
|
+
return jsonResponse({ error: "invalid_request_uri" }, HTTP_BAD_REQUEST3);
|
|
7920
7931
|
}
|
|
7921
7932
|
effectiveQuery = pushed;
|
|
7922
7933
|
} else if (query.request_uri !== undefined && query.request_uri.startsWith(REQUEST_URI_PREFIX)) {
|
|
7923
|
-
return jsonResponse({ error: "invalid_request_uri" },
|
|
7934
|
+
return jsonResponse({ error: "invalid_request_uri" }, HTTP_BAD_REQUEST3);
|
|
7924
7935
|
}
|
|
7925
7936
|
const initialClientId = effectiveQuery.client_id;
|
|
7926
7937
|
const initialClient = initialClientId === undefined ? undefined : await resolveClient(initialClientId);
|
|
@@ -7931,7 +7942,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7931
7942
|
jwt: effectiveQuery.request
|
|
7932
7943
|
});
|
|
7933
7944
|
if (!parsed.ok) {
|
|
7934
|
-
return jsonResponse({ error: parsed.error },
|
|
7945
|
+
return jsonResponse({ error: parsed.error }, HTTP_BAD_REQUEST3);
|
|
7935
7946
|
}
|
|
7936
7947
|
effectiveQuery = {
|
|
7937
7948
|
...parsed.params,
|
|
@@ -7951,11 +7962,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
7951
7962
|
} = effectiveQuery;
|
|
7952
7963
|
const client = initialClient;
|
|
7953
7964
|
if (client === undefined || clientId !== client.clientId || redirectUri === undefined || !client.redirectUris.includes(redirectUri)) {
|
|
7954
|
-
return jsonResponse({ error: "invalid_client" },
|
|
7965
|
+
return jsonResponse({ error: "invalid_client" }, HTTP_BAD_REQUEST3);
|
|
7955
7966
|
}
|
|
7956
7967
|
const responseMode = requestedResponseMode === "form_post" ? "form_post" : "query";
|
|
7957
7968
|
if (requestedResponseMode !== undefined && requestedResponseMode !== "query" && requestedResponseMode !== "form_post") {
|
|
7958
|
-
return jsonResponse({ error: "unsupported_response_mode" },
|
|
7969
|
+
return jsonResponse({ error: "unsupported_response_mode" }, HTTP_BAD_REQUEST3);
|
|
7959
7970
|
}
|
|
7960
7971
|
const errorRedirect = (error) => {
|
|
7961
7972
|
const params2 = {
|
|
@@ -7999,7 +8010,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7999
8010
|
if (wantsSilent) {
|
|
8000
8011
|
return errorRedirect(userSession === undefined ? "login_required" : "interaction_required");
|
|
8001
8012
|
}
|
|
8002
|
-
return loginUrl === undefined ? jsonResponse({ error: "login_required" },
|
|
8013
|
+
return loginUrl === undefined ? jsonResponse({ error: "login_required" }, HTTP_UNAUTHORIZED3) : redirectTo(`${loginUrl}?return_to=${encodeURIComponent(canonicalizeRequestUrl(request.url, issuer))}`);
|
|
8003
8014
|
}
|
|
8004
8015
|
const requested = scope === undefined || scope.length === 0 ? client.scopes : scope.split(" ").filter((entry) => client.scopes.includes(entry));
|
|
8005
8016
|
if (config.consentUrl !== undefined && await config.needsConsent?.({
|
|
@@ -8082,7 +8093,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8082
8093
|
if (body.grant_type === PRE_AUTHORIZED_CODE_GRANT && config.vciConfig !== undefined) {
|
|
8083
8094
|
const preAuthorizedCode = body["pre-authorized_code"];
|
|
8084
8095
|
if (typeof preAuthorizedCode !== "string") {
|
|
8085
|
-
return oauthError2(
|
|
8096
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
8086
8097
|
}
|
|
8087
8098
|
const result = await exchangePreAuthorizedCode({
|
|
8088
8099
|
config: config.vciConfig,
|
|
@@ -8091,14 +8102,14 @@ var oidcProviderRoutes = (config) => {
|
|
|
8091
8102
|
signingKey: config.vciConfig.signingKey ?? config.signingKey
|
|
8092
8103
|
});
|
|
8093
8104
|
if (!result.ok)
|
|
8094
|
-
return oauthError2(
|
|
8105
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
8095
8106
|
return jsonResponse({
|
|
8096
8107
|
access_token: result.access_token,
|
|
8097
8108
|
c_nonce: result.c_nonce,
|
|
8098
8109
|
c_nonce_expires_in: result.c_nonce_expires_in,
|
|
8099
8110
|
expires_in: result.expires_in,
|
|
8100
8111
|
token_type: result.token_type
|
|
8101
|
-
},
|
|
8112
|
+
}, HTTP_OK3);
|
|
8102
8113
|
}
|
|
8103
8114
|
if (typeof body.grant_type === "string" && config.publicTokenGrantTypes?.includes(body.grant_type) === true && config.handlePublicTokenGrant !== undefined) {
|
|
8104
8115
|
const result = await config.handlePublicTokenGrant({
|
|
@@ -8120,7 +8131,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8120
8131
|
requestHeaders: request.headers
|
|
8121
8132
|
});
|
|
8122
8133
|
if (auth === undefined) {
|
|
8123
|
-
return oauthError2(
|
|
8134
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8124
8135
|
}
|
|
8125
8136
|
const { client, clientCertThumbprint } = auth;
|
|
8126
8137
|
const nonceChallenge = await dpopNonceChallenge(headers.dpop);
|
|
@@ -8141,7 +8152,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8141
8152
|
if (body.grant_type === CIBA_GRANT_TYPE) {
|
|
8142
8153
|
return grantBackchannel(client, body, headers.dpop, clientCertThumbprint);
|
|
8143
8154
|
}
|
|
8144
|
-
return oauthError2(
|
|
8155
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
8145
8156
|
}, {
|
|
8146
8157
|
body: t14.Object({
|
|
8147
8158
|
assertion: t14.Optional(t14.String()),
|
|
@@ -8179,7 +8190,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8179
8190
|
requestHeaders: request.headers
|
|
8180
8191
|
});
|
|
8181
8192
|
if (auth === undefined) {
|
|
8182
|
-
return oauthError2(
|
|
8193
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8183
8194
|
}
|
|
8184
8195
|
const { client } = auth;
|
|
8185
8196
|
const isAuthField = (key) => key === "client_assertion" || key === "client_assertion_type" || key === "client_secret";
|
|
@@ -8190,7 +8201,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8190
8201
|
store: config.pushedAuthorizationRequestStore,
|
|
8191
8202
|
ttlMs: config.pushedAuthorizationRequestTtlMs
|
|
8192
8203
|
});
|
|
8193
|
-
return jsonResponse(result.body, result.ok ?
|
|
8204
|
+
return jsonResponse(result.body, result.ok ? HTTP_OK3 : result.status);
|
|
8194
8205
|
}, {
|
|
8195
8206
|
body: t14.Object({
|
|
8196
8207
|
acr_values: t14.Optional(t14.String()),
|
|
@@ -8217,11 +8228,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
8217
8228
|
const clientId = body.client_id ?? basic.clientId;
|
|
8218
8229
|
const clientSecret = body.client_secret ?? basic.clientSecret;
|
|
8219
8230
|
if (clientId === undefined) {
|
|
8220
|
-
return oauthError2(
|
|
8231
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8221
8232
|
}
|
|
8222
8233
|
const client = await authenticateClient(clientId, clientSecret);
|
|
8223
8234
|
if (client === undefined) {
|
|
8224
|
-
return oauthError2(
|
|
8235
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8225
8236
|
}
|
|
8226
8237
|
const result = await introspectToken({
|
|
8227
8238
|
config,
|
|
@@ -8229,7 +8240,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8229
8240
|
now: Date.now(),
|
|
8230
8241
|
token: body.token
|
|
8231
8242
|
});
|
|
8232
|
-
return jsonResponse(result,
|
|
8243
|
+
return jsonResponse(result, HTTP_OK3);
|
|
8233
8244
|
}, {
|
|
8234
8245
|
body: t14.Object({
|
|
8235
8246
|
client_id: t14.Optional(t14.String()),
|
|
@@ -8245,16 +8256,16 @@ var oidcProviderRoutes = (config) => {
|
|
|
8245
8256
|
const clientId = body.client_id ?? basic.clientId;
|
|
8246
8257
|
const clientSecret = body.client_secret ?? basic.clientSecret;
|
|
8247
8258
|
if (clientId === undefined) {
|
|
8248
|
-
return oauthError2(
|
|
8259
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8249
8260
|
}
|
|
8250
8261
|
const client = await authenticateClient(clientId, clientSecret);
|
|
8251
8262
|
if (client === undefined) {
|
|
8252
|
-
return oauthError2(
|
|
8263
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8253
8264
|
}
|
|
8254
8265
|
if (body.token_type_hint !== "access_token") {
|
|
8255
8266
|
await revokeRefreshToken(config, body.token);
|
|
8256
8267
|
}
|
|
8257
|
-
return new Response(null, { status:
|
|
8268
|
+
return new Response(null, { status: HTTP_OK3 });
|
|
8258
8269
|
}, {
|
|
8259
8270
|
body: t14.Object({
|
|
8260
8271
|
client_id: t14.Optional(t14.String()),
|
|
@@ -8267,20 +8278,20 @@ var oidcProviderRoutes = (config) => {
|
|
|
8267
8278
|
})
|
|
8268
8279
|
}).post(backchannelAuthorizationRoute, async ({ body, headers }) => {
|
|
8269
8280
|
if (config.backchannelAuthStore === undefined) {
|
|
8270
|
-
return oauthError2(
|
|
8281
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
8271
8282
|
}
|
|
8272
8283
|
const basic = readBasicAuth2(headers.authorization);
|
|
8273
8284
|
const clientId = body.client_id ?? basic.clientId;
|
|
8274
8285
|
const clientSecret = body.client_secret ?? basic.clientSecret;
|
|
8275
8286
|
if (clientId === undefined) {
|
|
8276
|
-
return oauthError2(
|
|
8287
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8277
8288
|
}
|
|
8278
8289
|
const client = await authenticateClient(clientId, clientSecret);
|
|
8279
8290
|
if (client === undefined) {
|
|
8280
|
-
return oauthError2(
|
|
8291
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8281
8292
|
}
|
|
8282
8293
|
if (body.login_hint === undefined) {
|
|
8283
|
-
return oauthError2(
|
|
8294
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
8284
8295
|
}
|
|
8285
8296
|
const requested = body.scope === undefined || body.scope.length === 0 ? client.scopes : body.scope.split(" ").filter((entry) => client.scopes.includes(entry));
|
|
8286
8297
|
const result = await issueBackchannelAuth({
|
|
@@ -8292,12 +8303,12 @@ var oidcProviderRoutes = (config) => {
|
|
|
8292
8303
|
requestedScopes: requested
|
|
8293
8304
|
});
|
|
8294
8305
|
if (!result.ok)
|
|
8295
|
-
return oauthError2(
|
|
8306
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
8296
8307
|
return jsonResponse({
|
|
8297
8308
|
auth_req_id: result.auth_req_id,
|
|
8298
8309
|
expires_in: result.expires_in,
|
|
8299
8310
|
interval: result.interval
|
|
8300
|
-
},
|
|
8311
|
+
}, HTTP_OK3);
|
|
8301
8312
|
}, {
|
|
8302
8313
|
body: t14.Object({
|
|
8303
8314
|
binding_message: t14.Optional(t14.String()),
|
|
@@ -8311,17 +8322,17 @@ var oidcProviderRoutes = (config) => {
|
|
|
8311
8322
|
})
|
|
8312
8323
|
}).post(deviceAuthorizationRoute, async ({ body, headers }) => {
|
|
8313
8324
|
if (config.deviceAuthorizationStore === undefined) {
|
|
8314
|
-
return oauthError2(
|
|
8325
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
8315
8326
|
}
|
|
8316
8327
|
const basic = readBasicAuth2(headers.authorization);
|
|
8317
8328
|
const clientId = body.client_id ?? basic.clientId;
|
|
8318
8329
|
const clientSecret = body.client_secret ?? basic.clientSecret;
|
|
8319
8330
|
if (clientId === undefined) {
|
|
8320
|
-
return oauthError2(
|
|
8331
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8321
8332
|
}
|
|
8322
8333
|
const client = await authenticateClient(clientId, clientSecret);
|
|
8323
8334
|
if (client === undefined) {
|
|
8324
|
-
return oauthError2(
|
|
8335
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "invalid_client");
|
|
8325
8336
|
}
|
|
8326
8337
|
const requested = body.scope === undefined || body.scope.length === 0 ? client.scopes : body.scope.split(" ").filter((entry) => client.scopes.includes(entry));
|
|
8327
8338
|
const response = await issueDeviceAuthorization({
|
|
@@ -8330,7 +8341,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8330
8341
|
now: Date.now(),
|
|
8331
8342
|
requestedScopes: requested
|
|
8332
8343
|
});
|
|
8333
|
-
return jsonResponse(response,
|
|
8344
|
+
return jsonResponse(response, HTTP_OK3);
|
|
8334
8345
|
}, {
|
|
8335
8346
|
body: t14.Object({
|
|
8336
8347
|
client_id: t14.Optional(t14.String()),
|
|
@@ -8342,7 +8353,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8342
8353
|
})
|
|
8343
8354
|
}).post(deviceApproveRoute, async ({ body, cookie: { user_session_id }, store }) => {
|
|
8344
8355
|
if (config.deviceAuthorizationStore === undefined) {
|
|
8345
|
-
return oauthError2(
|
|
8356
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
8346
8357
|
}
|
|
8347
8358
|
const userSession = await loadSessionFromSource({
|
|
8348
8359
|
authSessionStore,
|
|
@@ -8350,7 +8361,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8350
8361
|
userSessionId: user_session_id.value
|
|
8351
8362
|
});
|
|
8352
8363
|
if (userSession === undefined) {
|
|
8353
|
-
return oauthError2(
|
|
8364
|
+
return oauthError2(HTTP_UNAUTHORIZED3, "login_required");
|
|
8354
8365
|
}
|
|
8355
8366
|
const result = body.action === "deny" ? await denyDeviceAuthorization({
|
|
8356
8367
|
config,
|
|
@@ -8361,8 +8372,8 @@ var oidcProviderRoutes = (config) => {
|
|
|
8361
8372
|
userSub: getUserId(userSession.user)
|
|
8362
8373
|
});
|
|
8363
8374
|
if (!result.ok)
|
|
8364
|
-
return oauthError2(
|
|
8365
|
-
return jsonResponse({ ok: true },
|
|
8375
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
8376
|
+
return jsonResponse({ ok: true }, HTTP_OK3);
|
|
8366
8377
|
}, {
|
|
8367
8378
|
body: t14.Object({
|
|
8368
8379
|
action: t14.Optional(t14.Union([t14.Literal("approve"), t14.Literal("deny")])),
|
|
@@ -8414,7 +8425,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8414
8425
|
registrationBaseUrl,
|
|
8415
8426
|
registrationTokenStore: config.clientRegistrationTokenStore
|
|
8416
8427
|
});
|
|
8417
|
-
return jsonResponse(result.body, result.ok ?
|
|
8428
|
+
return jsonResponse(result.body, result.ok ? HTTP_OK3 : result.status);
|
|
8418
8429
|
}, {
|
|
8419
8430
|
body: t14.Object({
|
|
8420
8431
|
backchannel_logout_uri: t14.Optional(t14.String()),
|
|
@@ -8501,10 +8512,10 @@ var oidcProviderRoutes = (config) => {
|
|
|
8501
8512
|
"content-type": "application/json",
|
|
8502
8513
|
"www-authenticate": userInfoChallengeHeader(result.error)
|
|
8503
8514
|
},
|
|
8504
|
-
status:
|
|
8515
|
+
status: HTTP_UNAUTHORIZED3
|
|
8505
8516
|
});
|
|
8506
8517
|
}
|
|
8507
|
-
return jsonResponse(result.body,
|
|
8518
|
+
return jsonResponse(result.body, HTTP_OK3);
|
|
8508
8519
|
}, {
|
|
8509
8520
|
headers: t14.Object({
|
|
8510
8521
|
authorization: t14.Optional(t14.String())
|
|
@@ -8518,10 +8529,10 @@ var oidcProviderRoutes = (config) => {
|
|
|
8518
8529
|
"content-type": "application/json",
|
|
8519
8530
|
"www-authenticate": userInfoChallengeHeader(result.error)
|
|
8520
8531
|
},
|
|
8521
|
-
status:
|
|
8532
|
+
status: HTTP_UNAUTHORIZED3
|
|
8522
8533
|
});
|
|
8523
8534
|
}
|
|
8524
|
-
return jsonResponse(result.body,
|
|
8535
|
+
return jsonResponse(result.body, HTTP_OK3);
|
|
8525
8536
|
}, {
|
|
8526
8537
|
body: t14.Object({
|
|
8527
8538
|
access_token: t14.Optional(t14.String())
|
|
@@ -25039,9 +25050,9 @@ var createInMemoryCredentialOfferStore = () => {
|
|
|
25039
25050
|
};
|
|
25040
25051
|
// src/oidc/vciRoutes.ts
|
|
25041
25052
|
import { Elysia as Elysia38, t as t33 } from "elysia";
|
|
25042
|
-
var
|
|
25043
|
-
var
|
|
25044
|
-
var
|
|
25053
|
+
var HTTP_OK4 = 200;
|
|
25054
|
+
var HTTP_BAD_REQUEST4 = 400;
|
|
25055
|
+
var HTTP_UNAUTHORIZED4 = 401;
|
|
25045
25056
|
var BEARER_PREFIX5 = "Bearer ";
|
|
25046
25057
|
var errorBody = (error, status) => new Response(JSON.stringify({ error }), {
|
|
25047
25058
|
headers: { "content-type": "application/json" },
|
|
@@ -25070,7 +25081,7 @@ var vciRoutes = ({
|
|
|
25070
25081
|
}))).post(credentialRoute, async ({ body, headers }) => {
|
|
25071
25082
|
const accessToken = extractBearer(headers.authorization);
|
|
25072
25083
|
if (accessToken === undefined) {
|
|
25073
|
-
return errorBody("invalid_token",
|
|
25084
|
+
return errorBody("invalid_token", HTTP_UNAUTHORIZED4);
|
|
25074
25085
|
}
|
|
25075
25086
|
const result = await issueCredential({
|
|
25076
25087
|
config: vciConfig,
|
|
@@ -25083,8 +25094,8 @@ var vciRoutes = ({
|
|
|
25083
25094
|
signingKey: vciSigningKey
|
|
25084
25095
|
});
|
|
25085
25096
|
if (!result.ok)
|
|
25086
|
-
return errorBody(result.error,
|
|
25087
|
-
return Response.json({ credential: result.credential, format: result.format }, { status:
|
|
25097
|
+
return errorBody(result.error, HTTP_BAD_REQUEST4);
|
|
25098
|
+
return Response.json({ credential: result.credential, format: result.format }, { status: HTTP_OK4 });
|
|
25088
25099
|
}, {
|
|
25089
25100
|
body: t33.Object({
|
|
25090
25101
|
format: t33.Optional(t33.Union([t33.Literal("vc+sd-jwt")])),
|
|
@@ -25095,7 +25106,7 @@ var vciRoutes = ({
|
|
|
25095
25106
|
})
|
|
25096
25107
|
}).post(nonceRoute, async () => {
|
|
25097
25108
|
if (vciConfig.credentialNonceStore === undefined) {
|
|
25098
|
-
return errorBody("not_supported",
|
|
25109
|
+
return errorBody("not_supported", HTTP_BAD_REQUEST4);
|
|
25099
25110
|
}
|
|
25100
25111
|
const { generateSecureToken: generateSecureToken2, hashToken: hashToken2 } = await Promise.resolve().then(() => (init_crypto(), exports_crypto));
|
|
25101
25112
|
const nonceBytes = 16;
|
|
@@ -25109,7 +25120,7 @@ var vciRoutes = ({
|
|
|
25109
25120
|
return Response.json({
|
|
25110
25121
|
c_nonce: nonce,
|
|
25111
25122
|
c_nonce_expires_in: Math.floor(ttlMs / msPerSecond)
|
|
25112
|
-
}, { status:
|
|
25123
|
+
}, { status: HTTP_OK4 });
|
|
25113
25124
|
});
|
|
25114
25125
|
};
|
|
25115
25126
|
// src/vc/statusList.ts
|
|
@@ -25213,7 +25224,7 @@ var verifyStatusListJwt = async ({
|
|
|
25213
25224
|
};
|
|
25214
25225
|
// src/vc/statusListRoutes.ts
|
|
25215
25226
|
import { Elysia as Elysia39, t as t34 } from "elysia";
|
|
25216
|
-
var
|
|
25227
|
+
var HTTP_OK5 = 200;
|
|
25217
25228
|
var HTTP_NOT_FOUND = 404;
|
|
25218
25229
|
var DEFAULT_STATUS_ROUTE = "/vc/status";
|
|
25219
25230
|
var statusListRoutes = ({
|
|
@@ -25238,7 +25249,7 @@ var statusListRoutes = ({
|
|
|
25238
25249
|
});
|
|
25239
25250
|
return new Response(jwt, {
|
|
25240
25251
|
headers: { "content-type": STATUS_LIST_SUB_TYP },
|
|
25241
|
-
status:
|
|
25252
|
+
status: HTTP_OK5
|
|
25242
25253
|
});
|
|
25243
25254
|
}, { params: t34.Object({ listId: t34.String() }) });
|
|
25244
25255
|
};
|
|
@@ -25446,8 +25457,8 @@ var createInMemoryPresentationRequestStore = () => {
|
|
|
25446
25457
|
};
|
|
25447
25458
|
// src/vc/vpRoutes.ts
|
|
25448
25459
|
import { Elysia as Elysia40, t as t35 } from "elysia";
|
|
25449
|
-
var
|
|
25450
|
-
var
|
|
25460
|
+
var HTTP_OK6 = 200;
|
|
25461
|
+
var HTTP_BAD_REQUEST5 = 400;
|
|
25451
25462
|
var HTTP_NOT_FOUND2 = 404;
|
|
25452
25463
|
var errorBody2 = (error, status) => new Response(JSON.stringify({ error }), {
|
|
25453
25464
|
headers: { "content-type": "application/json" },
|
|
@@ -25480,7 +25491,7 @@ var vpRoutes = ({
|
|
|
25480
25491
|
nonce: result.nonce,
|
|
25481
25492
|
request_uri: result.requestUri,
|
|
25482
25493
|
requestId: result.request.requestId
|
|
25483
|
-
}, { status:
|
|
25494
|
+
}, { status: HTTP_OK6 });
|
|
25484
25495
|
}, {
|
|
25485
25496
|
body: t35.Object({
|
|
25486
25497
|
client_id: t35.Optional(t35.String()),
|
|
@@ -25509,19 +25520,19 @@ var vpRoutes = ({
|
|
|
25509
25520
|
headers: {
|
|
25510
25521
|
"content-type": "application/oauth-authz-req+jwt"
|
|
25511
25522
|
},
|
|
25512
|
-
status:
|
|
25523
|
+
status: HTTP_OK6
|
|
25513
25524
|
});
|
|
25514
25525
|
}, { params: t35.Object({ id: t35.String() }) }).post(responseRoute, async ({ body }) => {
|
|
25515
25526
|
const requestId = body.state;
|
|
25516
25527
|
if (requestId === undefined) {
|
|
25517
|
-
return errorBody2("missing_state",
|
|
25528
|
+
return errorBody2("missing_state", HTTP_BAD_REQUEST5);
|
|
25518
25529
|
}
|
|
25519
25530
|
const result = await verifyPresentationResponse({
|
|
25520
25531
|
config: vpConfig,
|
|
25521
25532
|
input: { requestId, vpToken: body.vp_token }
|
|
25522
25533
|
});
|
|
25523
25534
|
if (!result.ok)
|
|
25524
|
-
return errorBody2(result.error,
|
|
25535
|
+
return errorBody2(result.error, HTTP_BAD_REQUEST5);
|
|
25525
25536
|
if (onVerifiedPresentation !== undefined) {
|
|
25526
25537
|
await onVerifiedPresentation({ verified: result.verified });
|
|
25527
25538
|
}
|
|
@@ -25530,7 +25541,7 @@ var vpRoutes = ({
|
|
|
25530
25541
|
holder_jwk: result.verified.holderJwk,
|
|
25531
25542
|
protected_claims: result.verified.protectedClaims,
|
|
25532
25543
|
verified: true
|
|
25533
|
-
}, { status:
|
|
25544
|
+
}, { status: HTTP_OK6 });
|
|
25534
25545
|
}, {
|
|
25535
25546
|
body: t35.Object({
|
|
25536
25547
|
presentation_submission: t35.Optional(t35.Unknown()),
|
|
@@ -28640,17 +28651,17 @@ var blockMigrations = {
|
|
|
28640
28651
|
};
|
|
28641
28652
|
// src/sso/samlIdpRoutes.ts
|
|
28642
28653
|
import { Elysia as Elysia41, t as t36 } from "elysia";
|
|
28643
|
-
var
|
|
28644
|
-
var
|
|
28654
|
+
var HTTP_BAD_REQUEST6 = 400;
|
|
28655
|
+
var HTTP_UNAUTHORIZED5 = 401;
|
|
28645
28656
|
var HTTP_FOUND2 = 302;
|
|
28646
|
-
var
|
|
28657
|
+
var HTTP_OK7 = 200;
|
|
28647
28658
|
var xmlResponse = (body) => new Response(body, {
|
|
28648
28659
|
headers: { "content-type": "application/samlmetadata+xml" },
|
|
28649
|
-
status:
|
|
28660
|
+
status: HTTP_OK7
|
|
28650
28661
|
});
|
|
28651
28662
|
var htmlResponse = (body) => new Response(body, {
|
|
28652
28663
|
headers: { "content-type": "text/html; charset=utf-8" },
|
|
28653
|
-
status:
|
|
28664
|
+
status: HTTP_OK7
|
|
28654
28665
|
});
|
|
28655
28666
|
var redirectTo2 = (url) => new Response(null, { headers: { location: url }, status: HTTP_FOUND2 });
|
|
28656
28667
|
var errorJson = (status, error) => new Response(JSON.stringify({ error }), {
|
|
@@ -28702,7 +28713,7 @@ var samlIdpRoutes = ({
|
|
|
28702
28713
|
userSessionIdValue
|
|
28703
28714
|
}) => {
|
|
28704
28715
|
if (body.SAMLRequest === undefined) {
|
|
28705
|
-
return errorJson(
|
|
28716
|
+
return errorJson(HTTP_BAD_REQUEST6, "missing_saml_request");
|
|
28706
28717
|
}
|
|
28707
28718
|
let firstPass;
|
|
28708
28719
|
try {
|
|
@@ -28711,11 +28722,11 @@ var samlIdpRoutes = ({
|
|
|
28711
28722
|
samlRequest: body.SAMLRequest
|
|
28712
28723
|
});
|
|
28713
28724
|
} catch {
|
|
28714
|
-
return errorJson(
|
|
28725
|
+
return errorJson(HTTP_BAD_REQUEST6, "invalid_authn_request");
|
|
28715
28726
|
}
|
|
28716
28727
|
const serviceProvider = await samlServiceProviderStore.findServiceProvider(firstPass.issuer);
|
|
28717
28728
|
if (serviceProvider === undefined) {
|
|
28718
|
-
return errorJson(
|
|
28729
|
+
return errorJson(HTTP_BAD_REQUEST6, "unknown_service_provider");
|
|
28719
28730
|
}
|
|
28720
28731
|
let parsed;
|
|
28721
28732
|
try {
|
|
@@ -28728,7 +28739,7 @@ var samlIdpRoutes = ({
|
|
|
28728
28739
|
signedQueryString: binding === "Redirect" ? new URL(request.url).search.slice(1) : undefined
|
|
28729
28740
|
});
|
|
28730
28741
|
} catch {
|
|
28731
|
-
return errorJson(
|
|
28742
|
+
return errorJson(HTTP_BAD_REQUEST6, "invalid_authn_request");
|
|
28732
28743
|
}
|
|
28733
28744
|
const userSession = await loadSessionFromSource({
|
|
28734
28745
|
authSessionStore,
|
|
@@ -28737,7 +28748,7 @@ var samlIdpRoutes = ({
|
|
|
28737
28748
|
});
|
|
28738
28749
|
if (userSession === undefined || parsed.forceAuthn === true) {
|
|
28739
28750
|
if (loginUrl === undefined) {
|
|
28740
|
-
return errorJson(
|
|
28751
|
+
return errorJson(HTTP_UNAUTHORIZED5, "login_required");
|
|
28741
28752
|
}
|
|
28742
28753
|
return redirectTo2(`${loginUrl}?return_to=${encodeURIComponent(request.url)}`);
|
|
28743
28754
|
}
|
|
@@ -28786,11 +28797,11 @@ var samlIdpRoutes = ({
|
|
|
28786
28797
|
store
|
|
28787
28798
|
}) => {
|
|
28788
28799
|
if (serviceProviderEntityId === undefined) {
|
|
28789
|
-
return errorJson(
|
|
28800
|
+
return errorJson(HTTP_BAD_REQUEST6, "missing_sp");
|
|
28790
28801
|
}
|
|
28791
28802
|
const serviceProvider = await samlServiceProviderStore.findServiceProvider(serviceProviderEntityId);
|
|
28792
28803
|
if (serviceProvider === undefined) {
|
|
28793
|
-
return errorJson(
|
|
28804
|
+
return errorJson(HTTP_BAD_REQUEST6, "unknown_service_provider");
|
|
28794
28805
|
}
|
|
28795
28806
|
const userSession = authSessionStore === undefined ? await loadSessionFromSource({
|
|
28796
28807
|
session: store.session,
|
|
@@ -28802,7 +28813,7 @@ var samlIdpRoutes = ({
|
|
|
28802
28813
|
});
|
|
28803
28814
|
if (userSession === undefined) {
|
|
28804
28815
|
if (loginUrl === undefined) {
|
|
28805
|
-
return errorJson(
|
|
28816
|
+
return errorJson(HTTP_UNAUTHORIZED5, "login_required");
|
|
28806
28817
|
}
|
|
28807
28818
|
return redirectTo2(`${loginUrl}?return_to=${encodeURIComponent(request.url)}`);
|
|
28808
28819
|
}
|
|
@@ -29815,5 +29826,5 @@ export {
|
|
|
29815
29826
|
AGENT_CLAIM_GRANT_TYPE
|
|
29816
29827
|
};
|
|
29817
29828
|
|
|
29818
|
-
//# debugId=
|
|
29829
|
+
//# debugId=A2D2B9523667A9C564756E2164756E21
|
|
29819
29830
|
//# sourceMappingURL=index.js.map
|