@absolutejs/auth 0.55.0 → 0.55.2
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/context.d.ts +46 -0
- package/dist/agents/index.d.ts +2 -1
- package/dist/agents/index.js +47 -37
- package/dist/agents/index.js.map +5 -4
- package/dist/agents/routes.d.ts +29 -22
- 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 +196 -182
- package/dist/index.js.map +7 -6
- package/dist/mfa/routes.d.ts +2 -2
- package/dist/mfa/sms.d.ts +2 -2
- package/dist/oidc/routes.d.ts +13 -13
- 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 +29365 -0
- package/dist/server.js.map +288 -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
|
@@ -3044,9 +3044,6 @@ var apiKeysRoutes = ({
|
|
|
3044
3044
|
});
|
|
3045
3045
|
};
|
|
3046
3046
|
|
|
3047
|
-
// src/agents/routes.ts
|
|
3048
|
-
import { Elysia as Elysia2 } from "elysia";
|
|
3049
|
-
|
|
3050
3047
|
// src/agents/config.ts
|
|
3051
3048
|
var DEFAULT_AGENT_RESOURCE_METADATA_ROUTE = "/.well-known/oauth-protected-resource";
|
|
3052
3049
|
var agentProtectedResourceMetadata = (config) => ({
|
|
@@ -3058,6 +3055,9 @@ var agentProtectedResourceMetadata = (config) => ({
|
|
|
3058
3055
|
scopes_supported: config.scopes
|
|
3059
3056
|
});
|
|
3060
3057
|
|
|
3058
|
+
// src/agents/context.ts
|
|
3059
|
+
import { Elysia as Elysia2 } from "elysia";
|
|
3060
|
+
|
|
3061
3061
|
// src/agents/principal.ts
|
|
3062
3062
|
var intersectScopes = (...sets) => {
|
|
3063
3063
|
if (sets.length === 0)
|
|
@@ -3112,6 +3112,77 @@ var resolveAgentPrincipal = async (request, config) => {
|
|
|
3112
3112
|
};
|
|
3113
3113
|
};
|
|
3114
3114
|
|
|
3115
|
+
// src/agents/context.ts
|
|
3116
|
+
var DELETE_CODE_POINT = 127;
|
|
3117
|
+
var HTTP_FORBIDDEN = 403;
|
|
3118
|
+
var HTTP_UNAUTHORIZED2 = 401;
|
|
3119
|
+
var MINIMUM_PRINTABLE_CODE_POINT = 32;
|
|
3120
|
+
var quoteHeaderValue = (value) => {
|
|
3121
|
+
const printable = [...value].filter((character) => {
|
|
3122
|
+
const codePoint = character.codePointAt(0) ?? 0;
|
|
3123
|
+
return codePoint >= MINIMUM_PRINTABLE_CODE_POINT && codePoint !== DELETE_CODE_POINT;
|
|
3124
|
+
}).join("");
|
|
3125
|
+
return `"${printable.replace(/[\\"]/g, "\\$&")}"`;
|
|
3126
|
+
};
|
|
3127
|
+
var agentAuthChallenge = ({
|
|
3128
|
+
config,
|
|
3129
|
+
error,
|
|
3130
|
+
requiredScopes = []
|
|
3131
|
+
}) => {
|
|
3132
|
+
const parameters = [
|
|
3133
|
+
`resource_metadata=${quoteHeaderValue(agentResourceMetadataUrl(config))}`
|
|
3134
|
+
];
|
|
3135
|
+
if (requiredScopes.length > 0) {
|
|
3136
|
+
parameters.push(`scope=${quoteHeaderValue(requiredScopes.join(" "))}`);
|
|
3137
|
+
}
|
|
3138
|
+
if (error !== undefined) {
|
|
3139
|
+
parameters.push(`error=${quoteHeaderValue(error)}`);
|
|
3140
|
+
}
|
|
3141
|
+
return `Bearer ${parameters.join(", ")}`;
|
|
3142
|
+
};
|
|
3143
|
+
var agentResourceMetadataUrl = (config) => new URL(config.metadataRoute ?? DEFAULT_AGENT_RESOURCE_METADATA_ROUTE, config.resource).toString();
|
|
3144
|
+
var failureResponse = (config, failure, requiredScopes) => new Response(JSON.stringify({
|
|
3145
|
+
error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
|
|
3146
|
+
error_description: failure.message
|
|
3147
|
+
}), {
|
|
3148
|
+
headers: {
|
|
3149
|
+
"content-type": "application/json",
|
|
3150
|
+
"www-authenticate": agentAuthChallenge({
|
|
3151
|
+
config,
|
|
3152
|
+
error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
|
|
3153
|
+
requiredScopes
|
|
3154
|
+
})
|
|
3155
|
+
},
|
|
3156
|
+
status: failure.code === "Forbidden" ? HTTP_FORBIDDEN : HTTP_UNAUTHORIZED2
|
|
3157
|
+
});
|
|
3158
|
+
var agentAuthContextPlugin = (config) => new Elysia2().derive(({ request }) => ({
|
|
3159
|
+
protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
|
|
3160
|
+
if (config === undefined) {
|
|
3161
|
+
const failure = {
|
|
3162
|
+
code: "Unauthorized",
|
|
3163
|
+
message: "Agent is not authenticated"
|
|
3164
|
+
};
|
|
3165
|
+
return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: HTTP_UNAUTHORIZED2 });
|
|
3166
|
+
}
|
|
3167
|
+
const principal = await resolveAgentPrincipal(request, config);
|
|
3168
|
+
if (principal === undefined) {
|
|
3169
|
+
const failure = {
|
|
3170
|
+
code: "Unauthorized",
|
|
3171
|
+
message: "Agent is not authenticated"
|
|
3172
|
+
};
|
|
3173
|
+
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
3174
|
+
}
|
|
3175
|
+
if (!agentHasScopes(principal, requiredScopes)) {
|
|
3176
|
+
const failure = {
|
|
3177
|
+
code: "Forbidden",
|
|
3178
|
+
message: "Insufficient agent scopes"
|
|
3179
|
+
};
|
|
3180
|
+
return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
|
|
3181
|
+
}
|
|
3182
|
+
return handleAuth(principal);
|
|
3183
|
+
}
|
|
3184
|
+
}));
|
|
3185
|
+
|
|
3115
3186
|
// src/agents/registration.ts
|
|
3116
3187
|
init_constants();
|
|
3117
3188
|
init_crypto();
|
|
@@ -3780,45 +3851,10 @@ var revokeAgentIdentityRegistration = async (config, registrationId, now = Date.
|
|
|
3780
3851
|
};
|
|
3781
3852
|
|
|
3782
3853
|
// src/agents/routes.ts
|
|
3783
|
-
var
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
}).join("");
|
|
3788
|
-
return `"${printable.replace(/[\\"]/g, "\\$&")}"`;
|
|
3789
|
-
};
|
|
3790
|
-
var agentAuthChallenge = ({
|
|
3791
|
-
config,
|
|
3792
|
-
error,
|
|
3793
|
-
requiredScopes = []
|
|
3794
|
-
}) => {
|
|
3795
|
-
const parameters = [
|
|
3796
|
-
`resource_metadata=${quoteHeaderValue(agentResourceMetadataUrl(config))}`
|
|
3797
|
-
];
|
|
3798
|
-
if (requiredScopes.length > 0) {
|
|
3799
|
-
parameters.push(`scope=${quoteHeaderValue(requiredScopes.join(" "))}`);
|
|
3800
|
-
}
|
|
3801
|
-
if (error !== undefined) {
|
|
3802
|
-
parameters.push(`error=${quoteHeaderValue(error)}`);
|
|
3803
|
-
}
|
|
3804
|
-
return `Bearer ${parameters.join(", ")}`;
|
|
3805
|
-
};
|
|
3806
|
-
var agentResourceMetadataUrl = (config) => new URL(config.metadataRoute ?? DEFAULT_AGENT_RESOURCE_METADATA_ROUTE, config.resource).toString();
|
|
3807
|
-
var failureResponse = (config, failure, requiredScopes) => new Response(JSON.stringify({
|
|
3808
|
-
error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
|
|
3809
|
-
error_description: failure.message
|
|
3810
|
-
}), {
|
|
3811
|
-
headers: {
|
|
3812
|
-
"content-type": "application/json",
|
|
3813
|
-
"www-authenticate": agentAuthChallenge({
|
|
3814
|
-
config,
|
|
3815
|
-
error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
|
|
3816
|
-
requiredScopes
|
|
3817
|
-
})
|
|
3818
|
-
},
|
|
3819
|
-
status: failure.code === "Forbidden" ? 403 : 401
|
|
3820
|
-
});
|
|
3821
|
-
var json = (value, status = 200) => new Response(JSON.stringify(value), {
|
|
3854
|
+
var HTTP_BAD_REQUEST2 = 400;
|
|
3855
|
+
var HTTP_OK2 = 200;
|
|
3856
|
+
var HTTP_UNAUTHORIZED3 = 401;
|
|
3857
|
+
var json = (value, status = HTTP_OK2) => new Response(JSON.stringify(value), {
|
|
3822
3858
|
headers: {
|
|
3823
3859
|
"cache-control": "no-store",
|
|
3824
3860
|
"content-type": "application/json"
|
|
@@ -3852,7 +3888,7 @@ var registrationResponse = (result) => {
|
|
|
3852
3888
|
...body,
|
|
3853
3889
|
error: "interaction_required",
|
|
3854
3890
|
error_description: "Authenticate at the service and confirm the account link."
|
|
3855
|
-
},
|
|
3891
|
+
}, HTTP_UNAUTHORIZED3);
|
|
3856
3892
|
}
|
|
3857
3893
|
return json(body);
|
|
3858
3894
|
};
|
|
@@ -3880,33 +3916,7 @@ var parseRegistrationInput = (value) => {
|
|
|
3880
3916
|
};
|
|
3881
3917
|
var escapeHtml = (value) => value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """);
|
|
3882
3918
|
var agentAuthPlugin = (config) => {
|
|
3883
|
-
const plugin =
|
|
3884
|
-
protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
|
|
3885
|
-
if (config === undefined) {
|
|
3886
|
-
const failure = {
|
|
3887
|
-
code: "Unauthorized",
|
|
3888
|
-
message: "Agent is not authenticated"
|
|
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);
|
|
3908
|
-
}
|
|
3909
|
-
}));
|
|
3919
|
+
const plugin = agentAuthContextPlugin(config);
|
|
3910
3920
|
if (config === undefined)
|
|
3911
3921
|
return plugin.as("global");
|
|
3912
3922
|
if (config.agentRegistration === undefined) {
|
|
@@ -3937,11 +3947,11 @@ var agentAuthPlugin = (config) => {
|
|
|
3937
3947
|
}).post(identityRoute, async ({ body }) => {
|
|
3938
3948
|
const value = recordBody(body);
|
|
3939
3949
|
if (value === undefined || typeof value.type !== "string") {
|
|
3940
|
-
return json({ error: "invalid_request" },
|
|
3950
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST2);
|
|
3941
3951
|
}
|
|
3942
3952
|
const input = parseRegistrationInput(value);
|
|
3943
3953
|
if (input === undefined)
|
|
3944
|
-
return json({ error: "invalid_request" },
|
|
3954
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST2);
|
|
3945
3955
|
const result = await startAgentRegistration(config, input);
|
|
3946
3956
|
if ("error" in result) {
|
|
3947
3957
|
return json({
|
|
@@ -3953,7 +3963,7 @@ var agentAuthPlugin = (config) => {
|
|
|
3953
3963
|
}).post(claimRoute, async ({ body }) => {
|
|
3954
3964
|
const value = recordBody(body);
|
|
3955
3965
|
if (value === undefined || typeof value.claim_token !== "string" || typeof value.email !== "string") {
|
|
3956
|
-
return json({ error: "invalid_request" },
|
|
3966
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST2);
|
|
3957
3967
|
}
|
|
3958
3968
|
const result = await beginAgentClaim(config, {
|
|
3959
3969
|
claimToken: value.claim_token,
|
|
@@ -3968,7 +3978,7 @@ var agentAuthPlugin = (config) => {
|
|
|
3968
3978
|
value = Object.fromEntries(new URLSearchParams(body));
|
|
3969
3979
|
}
|
|
3970
3980
|
if (value === undefined || typeof value.claim_attempt_token !== "string" || typeof value.user_code !== "string") {
|
|
3971
|
-
return json({ error: "invalid_request" },
|
|
3981
|
+
return json({ error: "invalid_request" }, HTTP_BAD_REQUEST2);
|
|
3972
3982
|
}
|
|
3973
3983
|
const result = await completeAgentClaim(config, {
|
|
3974
3984
|
attemptToken: value.claim_attempt_token,
|
|
@@ -4281,6 +4291,11 @@ import { Elysia as Elysia5, t as t4 } from "elysia";
|
|
|
4281
4291
|
|
|
4282
4292
|
// src/utils.ts
|
|
4283
4293
|
init_constants();
|
|
4294
|
+
var MILLISECONDS_IN_A_SECOND2 = 1000;
|
|
4295
|
+
var readOptionalString = (value, property) => {
|
|
4296
|
+
const candidate = Reflect.get(value, property);
|
|
4297
|
+
return typeof candidate === "string" ? candidate : undefined;
|
|
4298
|
+
};
|
|
4284
4299
|
var defineAuthConfig = (configuration) => configuration;
|
|
4285
4300
|
var defineAuthHtmxConfig = (htmxConfig) => htmxConfig;
|
|
4286
4301
|
var defineAuthSettings = (settings) => settings;
|
|
@@ -4376,14 +4391,10 @@ var resolveOAuthAuthorization = async ({
|
|
|
4376
4391
|
let userIdentity;
|
|
4377
4392
|
let accessToken = tokenResponse.access_token;
|
|
4378
4393
|
let refreshToken = tokenResponse.refresh_token;
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
if (typeof nestedAccessToken === "string") {
|
|
4384
|
-
accessToken = nestedAccessToken;
|
|
4385
|
-
}
|
|
4386
|
-
}
|
|
4394
|
+
const withingsBody = Reflect.get(tokenResponse, "body");
|
|
4395
|
+
const withingsAccessToken = authProvider === "withings" && withingsBody !== null && typeof withingsBody === "object" ? readOptionalString(withingsBody, "access_token") : undefined;
|
|
4396
|
+
if (!accessToken && withingsAccessToken !== undefined) {
|
|
4397
|
+
accessToken = withingsAccessToken;
|
|
4387
4398
|
}
|
|
4388
4399
|
if (typeof accessToken !== "string" || accessToken.length === 0) {
|
|
4389
4400
|
throw new Error("OAuth authorization response contains no access_token");
|
|
@@ -4401,9 +4412,12 @@ var resolveOAuthAuthorization = async ({
|
|
|
4401
4412
|
source: "tokenResponse"
|
|
4402
4413
|
});
|
|
4403
4414
|
} else if (authProvider === "withings") {
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4415
|
+
if (withingsBody === null || typeof withingsBody !== "object") {
|
|
4416
|
+
throw new Error("Withings OAuth response contains no body");
|
|
4417
|
+
}
|
|
4418
|
+
userIdentity = { userid: Reflect.get(withingsBody, "userid") };
|
|
4419
|
+
accessToken = readOptionalString(withingsBody, "access_token") ?? accessToken;
|
|
4420
|
+
refreshToken = readOptionalString(withingsBody, "refresh_token") ?? refreshToken;
|
|
4407
4421
|
} else {
|
|
4408
4422
|
userIdentity = normalizeProviderIdentity({
|
|
4409
4423
|
identity: await providerInstance.fetchUserProfile(accessToken),
|
|
@@ -4435,7 +4449,7 @@ var resolveOAuthTokenExpiresAt = (tokenResponse, now = Date.now()) => {
|
|
|
4435
4449
|
if (!Number.isFinite(expiresInSeconds) || expiresInSeconds <= 0) {
|
|
4436
4450
|
return;
|
|
4437
4451
|
}
|
|
4438
|
-
return now + expiresInSeconds *
|
|
4452
|
+
return now + expiresInSeconds * MILLISECONDS_IN_A_SECOND2;
|
|
4439
4453
|
};
|
|
4440
4454
|
var validateSession = ({
|
|
4441
4455
|
user_session_id,
|
|
@@ -7445,11 +7459,11 @@ var updateRegisteredClient = async ({
|
|
|
7445
7459
|
};
|
|
7446
7460
|
|
|
7447
7461
|
// src/oidc/routes.ts
|
|
7448
|
-
var
|
|
7462
|
+
var HTTP_OK3 = 200;
|
|
7449
7463
|
var HTTP_NO_CONTENT = 204;
|
|
7450
7464
|
var HTTP_FOUND = 302;
|
|
7451
|
-
var
|
|
7452
|
-
var
|
|
7465
|
+
var HTTP_BAD_REQUEST3 = 400;
|
|
7466
|
+
var HTTP_UNAUTHORIZED4 = 401;
|
|
7453
7467
|
var HTTP_NOT_IMPLEMENTED = 501;
|
|
7454
7468
|
var CODE_TTL_MINUTES = 10;
|
|
7455
7469
|
var CODE_TTL_MS = MILLISECONDS_IN_A_MINUTE * CODE_TTL_MINUTES;
|
|
@@ -7463,7 +7477,7 @@ var jsonResponse = (value, status) => new Response(JSON.stringify(value), {
|
|
|
7463
7477
|
status
|
|
7464
7478
|
});
|
|
7465
7479
|
var oauthError2 = (status, error) => jsonResponse({ error }, status);
|
|
7466
|
-
var tokenResponse = (tokens) => jsonResponse(tokens,
|
|
7480
|
+
var tokenResponse = (tokens) => jsonResponse(tokens, HTTP_OK3);
|
|
7467
7481
|
var canonicalizeRequestUrl = (requestUrl, issuer) => {
|
|
7468
7482
|
try {
|
|
7469
7483
|
const url = new URL(requestUrl);
|
|
@@ -7485,7 +7499,7 @@ var formPostResponse = (redirectUri, params) => {
|
|
|
7485
7499
|
"cache-control": "no-store",
|
|
7486
7500
|
"content-type": "text/html;charset=UTF-8"
|
|
7487
7501
|
},
|
|
7488
|
-
status:
|
|
7502
|
+
status: HTTP_OK3
|
|
7489
7503
|
});
|
|
7490
7504
|
};
|
|
7491
7505
|
var respondToClient = (redirectUri, responseMode, params) => {
|
|
@@ -7623,7 +7637,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7623
7637
|
"dpop-nonce": fresh,
|
|
7624
7638
|
"www-authenticate": 'DPoP error="use_dpop_nonce"'
|
|
7625
7639
|
},
|
|
7626
|
-
status:
|
|
7640
|
+
status: HTTP_UNAUTHORIZED4
|
|
7627
7641
|
});
|
|
7628
7642
|
};
|
|
7629
7643
|
const grantAuthorizationCode = async (client, body, dpop, clientCertThumbprint) => {
|
|
@@ -7633,11 +7647,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
7633
7647
|
redirect_uri: redirectUri
|
|
7634
7648
|
} = body;
|
|
7635
7649
|
if (code === undefined || codeVerifier === undefined || redirectUri === undefined) {
|
|
7636
|
-
return oauthError2(
|
|
7650
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7637
7651
|
}
|
|
7638
7652
|
const record = await authorizationCodeStore.consumeCode(await hashToken(code));
|
|
7639
7653
|
if (record === undefined || record.expiresAt < Date.now() || record.clientId !== client.clientId || record.redirectUri !== redirectUri || !await verifyPkce(codeVerifier, record.codeChallenge)) {
|
|
7640
|
-
return oauthError2(
|
|
7654
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_grant");
|
|
7641
7655
|
}
|
|
7642
7656
|
const dpopResult = dpop === undefined ? undefined : await verifyDpopProof({
|
|
7643
7657
|
htm: "POST",
|
|
@@ -7645,7 +7659,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7645
7659
|
proof: dpop
|
|
7646
7660
|
});
|
|
7647
7661
|
if (dpop !== undefined && dpopResult === undefined) {
|
|
7648
|
-
return oauthError2(
|
|
7662
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7649
7663
|
}
|
|
7650
7664
|
return tokenResponse(await issueTokenSet({
|
|
7651
7665
|
acr: record.acr,
|
|
@@ -7662,11 +7676,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
7662
7676
|
const grantRefreshToken = async (client, body, dpop, clientCertThumbprint) => {
|
|
7663
7677
|
const presented = body.refresh_token;
|
|
7664
7678
|
if (presented === undefined) {
|
|
7665
|
-
return oauthError2(
|
|
7679
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7666
7680
|
}
|
|
7667
7681
|
const record = await refreshTokenStore.consumeToken(await hashToken(presented));
|
|
7668
7682
|
if (record === undefined || record.expiresAt < Date.now() || record.clientId !== client.clientId) {
|
|
7669
|
-
return oauthError2(
|
|
7683
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_grant");
|
|
7670
7684
|
}
|
|
7671
7685
|
if (record.dpopJkt !== undefined) {
|
|
7672
7686
|
const proof = await verifyDpopProof({
|
|
@@ -7675,7 +7689,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7675
7689
|
proof: dpop
|
|
7676
7690
|
});
|
|
7677
7691
|
if (proof === undefined || proof.jkt !== record.dpopJkt) {
|
|
7678
|
-
return oauthError2(
|
|
7692
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7679
7693
|
}
|
|
7680
7694
|
}
|
|
7681
7695
|
return tokenResponse(await issueTokenSet({
|
|
@@ -7691,7 +7705,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7691
7705
|
};
|
|
7692
7706
|
const grantTokenExchange = async (client, body, dpop) => {
|
|
7693
7707
|
if (body.subject_token === undefined) {
|
|
7694
|
-
return oauthError2(
|
|
7708
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7695
7709
|
}
|
|
7696
7710
|
const dpopResult = dpop === undefined ? undefined : await verifyDpopProof({
|
|
7697
7711
|
htm: "POST",
|
|
@@ -7699,7 +7713,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7699
7713
|
proof: dpop
|
|
7700
7714
|
});
|
|
7701
7715
|
if (dpop !== undefined && dpopResult === undefined) {
|
|
7702
|
-
return oauthError2(
|
|
7716
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7703
7717
|
}
|
|
7704
7718
|
const result = await exchangeToken({
|
|
7705
7719
|
actorClientId: client.clientId,
|
|
@@ -7710,21 +7724,21 @@ var oidcProviderRoutes = (config) => {
|
|
|
7710
7724
|
subjectToken: body.subject_token
|
|
7711
7725
|
});
|
|
7712
7726
|
if (!result.ok)
|
|
7713
|
-
return oauthError2(
|
|
7727
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
7714
7728
|
return jsonResponse({
|
|
7715
7729
|
access_token: result.accessToken,
|
|
7716
7730
|
expires_in: result.expiresIn,
|
|
7717
7731
|
issued_token_type: "urn:ietf:params:oauth:token-type:access_token",
|
|
7718
7732
|
scope: result.scope,
|
|
7719
7733
|
token_type: dpopResult === undefined ? "Bearer" : "DPoP"
|
|
7720
|
-
},
|
|
7734
|
+
}, HTTP_OK3);
|
|
7721
7735
|
};
|
|
7722
7736
|
const grantBackchannel = async (client, body, dpop, clientCertThumbprint) => {
|
|
7723
7737
|
if (config.backchannelAuthStore === undefined) {
|
|
7724
|
-
return oauthError2(
|
|
7738
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
7725
7739
|
}
|
|
7726
7740
|
if (body.auth_req_id === undefined) {
|
|
7727
|
-
return oauthError2(
|
|
7741
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7728
7742
|
}
|
|
7729
7743
|
const dpopResult = dpop === undefined ? undefined : await verifyDpopProof({
|
|
7730
7744
|
htm: "POST",
|
|
@@ -7732,7 +7746,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7732
7746
|
proof: dpop
|
|
7733
7747
|
});
|
|
7734
7748
|
if (dpop !== undefined && dpopResult === undefined) {
|
|
7735
|
-
return oauthError2(
|
|
7749
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7736
7750
|
}
|
|
7737
7751
|
const result = await exchangeBackchannelAuth({
|
|
7738
7752
|
authReqId: body.auth_req_id,
|
|
@@ -7742,7 +7756,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7742
7756
|
dpopJkt: dpopResult?.jkt
|
|
7743
7757
|
});
|
|
7744
7758
|
if (!result.ok)
|
|
7745
|
-
return oauthError2(
|
|
7759
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
7746
7760
|
return jsonResponse({
|
|
7747
7761
|
access_token: result.access_token,
|
|
7748
7762
|
expires_in: result.expires_in,
|
|
@@ -7750,14 +7764,14 @@ var oidcProviderRoutes = (config) => {
|
|
|
7750
7764
|
refresh_token: result.refresh_token,
|
|
7751
7765
|
scope: result.scope,
|
|
7752
7766
|
token_type: dpopResult === undefined ? "Bearer" : "DPoP"
|
|
7753
|
-
},
|
|
7767
|
+
}, HTTP_OK3);
|
|
7754
7768
|
};
|
|
7755
7769
|
const grantDeviceCode = async (client, body, dpop) => {
|
|
7756
7770
|
if (config.deviceAuthorizationStore === undefined) {
|
|
7757
|
-
return oauthError2(
|
|
7771
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
7758
7772
|
}
|
|
7759
7773
|
if (body.device_code === undefined) {
|
|
7760
|
-
return oauthError2(
|
|
7774
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
7761
7775
|
}
|
|
7762
7776
|
const dpopResult = dpop === undefined ? undefined : await verifyDpopProof({
|
|
7763
7777
|
htm: "POST",
|
|
@@ -7765,7 +7779,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7765
7779
|
proof: dpop
|
|
7766
7780
|
});
|
|
7767
7781
|
if (dpop !== undefined && dpopResult === undefined) {
|
|
7768
|
-
return oauthError2(
|
|
7782
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_dpop_proof");
|
|
7769
7783
|
}
|
|
7770
7784
|
const result = await exchangeDeviceCode({
|
|
7771
7785
|
clientId: client.clientId,
|
|
@@ -7774,7 +7788,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7774
7788
|
dpopJkt: dpopResult?.jkt
|
|
7775
7789
|
});
|
|
7776
7790
|
if (!result.ok)
|
|
7777
|
-
return oauthError2(
|
|
7791
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
7778
7792
|
return jsonResponse({
|
|
7779
7793
|
access_token: result.access_token,
|
|
7780
7794
|
expires_in: result.expires_in,
|
|
@@ -7782,7 +7796,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7782
7796
|
refresh_token: result.refresh_token,
|
|
7783
7797
|
scope: result.scope,
|
|
7784
7798
|
token_type: dpopResult === undefined ? "Bearer" : "DPoP"
|
|
7785
|
-
},
|
|
7799
|
+
}, HTTP_OK3);
|
|
7786
7800
|
};
|
|
7787
7801
|
const grantTypes = [
|
|
7788
7802
|
"authorization_code",
|
|
@@ -7895,7 +7909,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7895
7909
|
requestedUri: query.post_logout_redirect_uri
|
|
7896
7910
|
});
|
|
7897
7911
|
if (redirectUri === undefined) {
|
|
7898
|
-
return jsonResponse({ ok: true },
|
|
7912
|
+
return jsonResponse({ ok: true }, HTTP_OK3);
|
|
7899
7913
|
}
|
|
7900
7914
|
const url = new URL(redirectUri);
|
|
7901
7915
|
if (query.state !== undefined)
|
|
@@ -7916,11 +7930,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
7916
7930
|
store: config.pushedAuthorizationRequestStore
|
|
7917
7931
|
});
|
|
7918
7932
|
if (pushed === undefined) {
|
|
7919
|
-
return jsonResponse({ error: "invalid_request_uri" },
|
|
7933
|
+
return jsonResponse({ error: "invalid_request_uri" }, HTTP_BAD_REQUEST3);
|
|
7920
7934
|
}
|
|
7921
7935
|
effectiveQuery = pushed;
|
|
7922
7936
|
} else if (query.request_uri !== undefined && query.request_uri.startsWith(REQUEST_URI_PREFIX)) {
|
|
7923
|
-
return jsonResponse({ error: "invalid_request_uri" },
|
|
7937
|
+
return jsonResponse({ error: "invalid_request_uri" }, HTTP_BAD_REQUEST3);
|
|
7924
7938
|
}
|
|
7925
7939
|
const initialClientId = effectiveQuery.client_id;
|
|
7926
7940
|
const initialClient = initialClientId === undefined ? undefined : await resolveClient(initialClientId);
|
|
@@ -7931,7 +7945,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7931
7945
|
jwt: effectiveQuery.request
|
|
7932
7946
|
});
|
|
7933
7947
|
if (!parsed.ok) {
|
|
7934
|
-
return jsonResponse({ error: parsed.error },
|
|
7948
|
+
return jsonResponse({ error: parsed.error }, HTTP_BAD_REQUEST3);
|
|
7935
7949
|
}
|
|
7936
7950
|
effectiveQuery = {
|
|
7937
7951
|
...parsed.params,
|
|
@@ -7951,11 +7965,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
7951
7965
|
} = effectiveQuery;
|
|
7952
7966
|
const client = initialClient;
|
|
7953
7967
|
if (client === undefined || clientId !== client.clientId || redirectUri === undefined || !client.redirectUris.includes(redirectUri)) {
|
|
7954
|
-
return jsonResponse({ error: "invalid_client" },
|
|
7968
|
+
return jsonResponse({ error: "invalid_client" }, HTTP_BAD_REQUEST3);
|
|
7955
7969
|
}
|
|
7956
7970
|
const responseMode = requestedResponseMode === "form_post" ? "form_post" : "query";
|
|
7957
7971
|
if (requestedResponseMode !== undefined && requestedResponseMode !== "query" && requestedResponseMode !== "form_post") {
|
|
7958
|
-
return jsonResponse({ error: "unsupported_response_mode" },
|
|
7972
|
+
return jsonResponse({ error: "unsupported_response_mode" }, HTTP_BAD_REQUEST3);
|
|
7959
7973
|
}
|
|
7960
7974
|
const errorRedirect = (error) => {
|
|
7961
7975
|
const params2 = {
|
|
@@ -7999,7 +8013,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
7999
8013
|
if (wantsSilent) {
|
|
8000
8014
|
return errorRedirect(userSession === undefined ? "login_required" : "interaction_required");
|
|
8001
8015
|
}
|
|
8002
|
-
return loginUrl === undefined ? jsonResponse({ error: "login_required" },
|
|
8016
|
+
return loginUrl === undefined ? jsonResponse({ error: "login_required" }, HTTP_UNAUTHORIZED4) : redirectTo(`${loginUrl}?return_to=${encodeURIComponent(canonicalizeRequestUrl(request.url, issuer))}`);
|
|
8003
8017
|
}
|
|
8004
8018
|
const requested = scope === undefined || scope.length === 0 ? client.scopes : scope.split(" ").filter((entry) => client.scopes.includes(entry));
|
|
8005
8019
|
if (config.consentUrl !== undefined && await config.needsConsent?.({
|
|
@@ -8082,7 +8096,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8082
8096
|
if (body.grant_type === PRE_AUTHORIZED_CODE_GRANT && config.vciConfig !== undefined) {
|
|
8083
8097
|
const preAuthorizedCode = body["pre-authorized_code"];
|
|
8084
8098
|
if (typeof preAuthorizedCode !== "string") {
|
|
8085
|
-
return oauthError2(
|
|
8099
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
8086
8100
|
}
|
|
8087
8101
|
const result = await exchangePreAuthorizedCode({
|
|
8088
8102
|
config: config.vciConfig,
|
|
@@ -8091,14 +8105,14 @@ var oidcProviderRoutes = (config) => {
|
|
|
8091
8105
|
signingKey: config.vciConfig.signingKey ?? config.signingKey
|
|
8092
8106
|
});
|
|
8093
8107
|
if (!result.ok)
|
|
8094
|
-
return oauthError2(
|
|
8108
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
8095
8109
|
return jsonResponse({
|
|
8096
8110
|
access_token: result.access_token,
|
|
8097
8111
|
c_nonce: result.c_nonce,
|
|
8098
8112
|
c_nonce_expires_in: result.c_nonce_expires_in,
|
|
8099
8113
|
expires_in: result.expires_in,
|
|
8100
8114
|
token_type: result.token_type
|
|
8101
|
-
},
|
|
8115
|
+
}, HTTP_OK3);
|
|
8102
8116
|
}
|
|
8103
8117
|
if (typeof body.grant_type === "string" && config.publicTokenGrantTypes?.includes(body.grant_type) === true && config.handlePublicTokenGrant !== undefined) {
|
|
8104
8118
|
const result = await config.handlePublicTokenGrant({
|
|
@@ -8120,7 +8134,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8120
8134
|
requestHeaders: request.headers
|
|
8121
8135
|
});
|
|
8122
8136
|
if (auth === undefined) {
|
|
8123
|
-
return oauthError2(
|
|
8137
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8124
8138
|
}
|
|
8125
8139
|
const { client, clientCertThumbprint } = auth;
|
|
8126
8140
|
const nonceChallenge = await dpopNonceChallenge(headers.dpop);
|
|
@@ -8141,7 +8155,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8141
8155
|
if (body.grant_type === CIBA_GRANT_TYPE) {
|
|
8142
8156
|
return grantBackchannel(client, body, headers.dpop, clientCertThumbprint);
|
|
8143
8157
|
}
|
|
8144
|
-
return oauthError2(
|
|
8158
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
8145
8159
|
}, {
|
|
8146
8160
|
body: t14.Object({
|
|
8147
8161
|
assertion: t14.Optional(t14.String()),
|
|
@@ -8179,7 +8193,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8179
8193
|
requestHeaders: request.headers
|
|
8180
8194
|
});
|
|
8181
8195
|
if (auth === undefined) {
|
|
8182
|
-
return oauthError2(
|
|
8196
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8183
8197
|
}
|
|
8184
8198
|
const { client } = auth;
|
|
8185
8199
|
const isAuthField = (key) => key === "client_assertion" || key === "client_assertion_type" || key === "client_secret";
|
|
@@ -8190,7 +8204,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8190
8204
|
store: config.pushedAuthorizationRequestStore,
|
|
8191
8205
|
ttlMs: config.pushedAuthorizationRequestTtlMs
|
|
8192
8206
|
});
|
|
8193
|
-
return jsonResponse(result.body, result.ok ?
|
|
8207
|
+
return jsonResponse(result.body, result.ok ? HTTP_OK3 : result.status);
|
|
8194
8208
|
}, {
|
|
8195
8209
|
body: t14.Object({
|
|
8196
8210
|
acr_values: t14.Optional(t14.String()),
|
|
@@ -8217,11 +8231,11 @@ var oidcProviderRoutes = (config) => {
|
|
|
8217
8231
|
const clientId = body.client_id ?? basic.clientId;
|
|
8218
8232
|
const clientSecret = body.client_secret ?? basic.clientSecret;
|
|
8219
8233
|
if (clientId === undefined) {
|
|
8220
|
-
return oauthError2(
|
|
8234
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8221
8235
|
}
|
|
8222
8236
|
const client = await authenticateClient(clientId, clientSecret);
|
|
8223
8237
|
if (client === undefined) {
|
|
8224
|
-
return oauthError2(
|
|
8238
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8225
8239
|
}
|
|
8226
8240
|
const result = await introspectToken({
|
|
8227
8241
|
config,
|
|
@@ -8229,7 +8243,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8229
8243
|
now: Date.now(),
|
|
8230
8244
|
token: body.token
|
|
8231
8245
|
});
|
|
8232
|
-
return jsonResponse(result,
|
|
8246
|
+
return jsonResponse(result, HTTP_OK3);
|
|
8233
8247
|
}, {
|
|
8234
8248
|
body: t14.Object({
|
|
8235
8249
|
client_id: t14.Optional(t14.String()),
|
|
@@ -8245,16 +8259,16 @@ var oidcProviderRoutes = (config) => {
|
|
|
8245
8259
|
const clientId = body.client_id ?? basic.clientId;
|
|
8246
8260
|
const clientSecret = body.client_secret ?? basic.clientSecret;
|
|
8247
8261
|
if (clientId === undefined) {
|
|
8248
|
-
return oauthError2(
|
|
8262
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8249
8263
|
}
|
|
8250
8264
|
const client = await authenticateClient(clientId, clientSecret);
|
|
8251
8265
|
if (client === undefined) {
|
|
8252
|
-
return oauthError2(
|
|
8266
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8253
8267
|
}
|
|
8254
8268
|
if (body.token_type_hint !== "access_token") {
|
|
8255
8269
|
await revokeRefreshToken(config, body.token);
|
|
8256
8270
|
}
|
|
8257
|
-
return new Response(null, { status:
|
|
8271
|
+
return new Response(null, { status: HTTP_OK3 });
|
|
8258
8272
|
}, {
|
|
8259
8273
|
body: t14.Object({
|
|
8260
8274
|
client_id: t14.Optional(t14.String()),
|
|
@@ -8267,20 +8281,20 @@ var oidcProviderRoutes = (config) => {
|
|
|
8267
8281
|
})
|
|
8268
8282
|
}).post(backchannelAuthorizationRoute, async ({ body, headers }) => {
|
|
8269
8283
|
if (config.backchannelAuthStore === undefined) {
|
|
8270
|
-
return oauthError2(
|
|
8284
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
8271
8285
|
}
|
|
8272
8286
|
const basic = readBasicAuth2(headers.authorization);
|
|
8273
8287
|
const clientId = body.client_id ?? basic.clientId;
|
|
8274
8288
|
const clientSecret = body.client_secret ?? basic.clientSecret;
|
|
8275
8289
|
if (clientId === undefined) {
|
|
8276
|
-
return oauthError2(
|
|
8290
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8277
8291
|
}
|
|
8278
8292
|
const client = await authenticateClient(clientId, clientSecret);
|
|
8279
8293
|
if (client === undefined) {
|
|
8280
|
-
return oauthError2(
|
|
8294
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8281
8295
|
}
|
|
8282
8296
|
if (body.login_hint === undefined) {
|
|
8283
|
-
return oauthError2(
|
|
8297
|
+
return oauthError2(HTTP_BAD_REQUEST3, "invalid_request");
|
|
8284
8298
|
}
|
|
8285
8299
|
const requested = body.scope === undefined || body.scope.length === 0 ? client.scopes : body.scope.split(" ").filter((entry) => client.scopes.includes(entry));
|
|
8286
8300
|
const result = await issueBackchannelAuth({
|
|
@@ -8292,12 +8306,12 @@ var oidcProviderRoutes = (config) => {
|
|
|
8292
8306
|
requestedScopes: requested
|
|
8293
8307
|
});
|
|
8294
8308
|
if (!result.ok)
|
|
8295
|
-
return oauthError2(
|
|
8309
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
8296
8310
|
return jsonResponse({
|
|
8297
8311
|
auth_req_id: result.auth_req_id,
|
|
8298
8312
|
expires_in: result.expires_in,
|
|
8299
8313
|
interval: result.interval
|
|
8300
|
-
},
|
|
8314
|
+
}, HTTP_OK3);
|
|
8301
8315
|
}, {
|
|
8302
8316
|
body: t14.Object({
|
|
8303
8317
|
binding_message: t14.Optional(t14.String()),
|
|
@@ -8311,17 +8325,17 @@ var oidcProviderRoutes = (config) => {
|
|
|
8311
8325
|
})
|
|
8312
8326
|
}).post(deviceAuthorizationRoute, async ({ body, headers }) => {
|
|
8313
8327
|
if (config.deviceAuthorizationStore === undefined) {
|
|
8314
|
-
return oauthError2(
|
|
8328
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
8315
8329
|
}
|
|
8316
8330
|
const basic = readBasicAuth2(headers.authorization);
|
|
8317
8331
|
const clientId = body.client_id ?? basic.clientId;
|
|
8318
8332
|
const clientSecret = body.client_secret ?? basic.clientSecret;
|
|
8319
8333
|
if (clientId === undefined) {
|
|
8320
|
-
return oauthError2(
|
|
8334
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8321
8335
|
}
|
|
8322
8336
|
const client = await authenticateClient(clientId, clientSecret);
|
|
8323
8337
|
if (client === undefined) {
|
|
8324
|
-
return oauthError2(
|
|
8338
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "invalid_client");
|
|
8325
8339
|
}
|
|
8326
8340
|
const requested = body.scope === undefined || body.scope.length === 0 ? client.scopes : body.scope.split(" ").filter((entry) => client.scopes.includes(entry));
|
|
8327
8341
|
const response = await issueDeviceAuthorization({
|
|
@@ -8330,7 +8344,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8330
8344
|
now: Date.now(),
|
|
8331
8345
|
requestedScopes: requested
|
|
8332
8346
|
});
|
|
8333
|
-
return jsonResponse(response,
|
|
8347
|
+
return jsonResponse(response, HTTP_OK3);
|
|
8334
8348
|
}, {
|
|
8335
8349
|
body: t14.Object({
|
|
8336
8350
|
client_id: t14.Optional(t14.String()),
|
|
@@ -8342,7 +8356,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8342
8356
|
})
|
|
8343
8357
|
}).post(deviceApproveRoute, async ({ body, cookie: { user_session_id }, store }) => {
|
|
8344
8358
|
if (config.deviceAuthorizationStore === undefined) {
|
|
8345
|
-
return oauthError2(
|
|
8359
|
+
return oauthError2(HTTP_BAD_REQUEST3, "unsupported_grant_type");
|
|
8346
8360
|
}
|
|
8347
8361
|
const userSession = await loadSessionFromSource({
|
|
8348
8362
|
authSessionStore,
|
|
@@ -8350,7 +8364,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8350
8364
|
userSessionId: user_session_id.value
|
|
8351
8365
|
});
|
|
8352
8366
|
if (userSession === undefined) {
|
|
8353
|
-
return oauthError2(
|
|
8367
|
+
return oauthError2(HTTP_UNAUTHORIZED4, "login_required");
|
|
8354
8368
|
}
|
|
8355
8369
|
const result = body.action === "deny" ? await denyDeviceAuthorization({
|
|
8356
8370
|
config,
|
|
@@ -8361,8 +8375,8 @@ var oidcProviderRoutes = (config) => {
|
|
|
8361
8375
|
userSub: getUserId(userSession.user)
|
|
8362
8376
|
});
|
|
8363
8377
|
if (!result.ok)
|
|
8364
|
-
return oauthError2(
|
|
8365
|
-
return jsonResponse({ ok: true },
|
|
8378
|
+
return oauthError2(HTTP_BAD_REQUEST3, result.error);
|
|
8379
|
+
return jsonResponse({ ok: true }, HTTP_OK3);
|
|
8366
8380
|
}, {
|
|
8367
8381
|
body: t14.Object({
|
|
8368
8382
|
action: t14.Optional(t14.Union([t14.Literal("approve"), t14.Literal("deny")])),
|
|
@@ -8414,7 +8428,7 @@ var oidcProviderRoutes = (config) => {
|
|
|
8414
8428
|
registrationBaseUrl,
|
|
8415
8429
|
registrationTokenStore: config.clientRegistrationTokenStore
|
|
8416
8430
|
});
|
|
8417
|
-
return jsonResponse(result.body, result.ok ?
|
|
8431
|
+
return jsonResponse(result.body, result.ok ? HTTP_OK3 : result.status);
|
|
8418
8432
|
}, {
|
|
8419
8433
|
body: t14.Object({
|
|
8420
8434
|
backchannel_logout_uri: t14.Optional(t14.String()),
|
|
@@ -8501,10 +8515,10 @@ var oidcProviderRoutes = (config) => {
|
|
|
8501
8515
|
"content-type": "application/json",
|
|
8502
8516
|
"www-authenticate": userInfoChallengeHeader(result.error)
|
|
8503
8517
|
},
|
|
8504
|
-
status:
|
|
8518
|
+
status: HTTP_UNAUTHORIZED4
|
|
8505
8519
|
});
|
|
8506
8520
|
}
|
|
8507
|
-
return jsonResponse(result.body,
|
|
8521
|
+
return jsonResponse(result.body, HTTP_OK3);
|
|
8508
8522
|
}, {
|
|
8509
8523
|
headers: t14.Object({
|
|
8510
8524
|
authorization: t14.Optional(t14.String())
|
|
@@ -8518,10 +8532,10 @@ var oidcProviderRoutes = (config) => {
|
|
|
8518
8532
|
"content-type": "application/json",
|
|
8519
8533
|
"www-authenticate": userInfoChallengeHeader(result.error)
|
|
8520
8534
|
},
|
|
8521
|
-
status:
|
|
8535
|
+
status: HTTP_UNAUTHORIZED4
|
|
8522
8536
|
});
|
|
8523
8537
|
}
|
|
8524
|
-
return jsonResponse(result.body,
|
|
8538
|
+
return jsonResponse(result.body, HTTP_OK3);
|
|
8525
8539
|
}, {
|
|
8526
8540
|
body: t14.Object({
|
|
8527
8541
|
access_token: t14.Optional(t14.String())
|
|
@@ -25039,9 +25053,9 @@ var createInMemoryCredentialOfferStore = () => {
|
|
|
25039
25053
|
};
|
|
25040
25054
|
// src/oidc/vciRoutes.ts
|
|
25041
25055
|
import { Elysia as Elysia38, t as t33 } from "elysia";
|
|
25042
|
-
var
|
|
25043
|
-
var
|
|
25044
|
-
var
|
|
25056
|
+
var HTTP_OK4 = 200;
|
|
25057
|
+
var HTTP_BAD_REQUEST4 = 400;
|
|
25058
|
+
var HTTP_UNAUTHORIZED5 = 401;
|
|
25045
25059
|
var BEARER_PREFIX5 = "Bearer ";
|
|
25046
25060
|
var errorBody = (error, status) => new Response(JSON.stringify({ error }), {
|
|
25047
25061
|
headers: { "content-type": "application/json" },
|
|
@@ -25070,7 +25084,7 @@ var vciRoutes = ({
|
|
|
25070
25084
|
}))).post(credentialRoute, async ({ body, headers }) => {
|
|
25071
25085
|
const accessToken = extractBearer(headers.authorization);
|
|
25072
25086
|
if (accessToken === undefined) {
|
|
25073
|
-
return errorBody("invalid_token",
|
|
25087
|
+
return errorBody("invalid_token", HTTP_UNAUTHORIZED5);
|
|
25074
25088
|
}
|
|
25075
25089
|
const result = await issueCredential({
|
|
25076
25090
|
config: vciConfig,
|
|
@@ -25083,8 +25097,8 @@ var vciRoutes = ({
|
|
|
25083
25097
|
signingKey: vciSigningKey
|
|
25084
25098
|
});
|
|
25085
25099
|
if (!result.ok)
|
|
25086
|
-
return errorBody(result.error,
|
|
25087
|
-
return Response.json({ credential: result.credential, format: result.format }, { status:
|
|
25100
|
+
return errorBody(result.error, HTTP_BAD_REQUEST4);
|
|
25101
|
+
return Response.json({ credential: result.credential, format: result.format }, { status: HTTP_OK4 });
|
|
25088
25102
|
}, {
|
|
25089
25103
|
body: t33.Object({
|
|
25090
25104
|
format: t33.Optional(t33.Union([t33.Literal("vc+sd-jwt")])),
|
|
@@ -25095,7 +25109,7 @@ var vciRoutes = ({
|
|
|
25095
25109
|
})
|
|
25096
25110
|
}).post(nonceRoute, async () => {
|
|
25097
25111
|
if (vciConfig.credentialNonceStore === undefined) {
|
|
25098
|
-
return errorBody("not_supported",
|
|
25112
|
+
return errorBody("not_supported", HTTP_BAD_REQUEST4);
|
|
25099
25113
|
}
|
|
25100
25114
|
const { generateSecureToken: generateSecureToken2, hashToken: hashToken2 } = await Promise.resolve().then(() => (init_crypto(), exports_crypto));
|
|
25101
25115
|
const nonceBytes = 16;
|
|
@@ -25109,7 +25123,7 @@ var vciRoutes = ({
|
|
|
25109
25123
|
return Response.json({
|
|
25110
25124
|
c_nonce: nonce,
|
|
25111
25125
|
c_nonce_expires_in: Math.floor(ttlMs / msPerSecond)
|
|
25112
|
-
}, { status:
|
|
25126
|
+
}, { status: HTTP_OK4 });
|
|
25113
25127
|
});
|
|
25114
25128
|
};
|
|
25115
25129
|
// src/vc/statusList.ts
|
|
@@ -25213,7 +25227,7 @@ var verifyStatusListJwt = async ({
|
|
|
25213
25227
|
};
|
|
25214
25228
|
// src/vc/statusListRoutes.ts
|
|
25215
25229
|
import { Elysia as Elysia39, t as t34 } from "elysia";
|
|
25216
|
-
var
|
|
25230
|
+
var HTTP_OK5 = 200;
|
|
25217
25231
|
var HTTP_NOT_FOUND = 404;
|
|
25218
25232
|
var DEFAULT_STATUS_ROUTE = "/vc/status";
|
|
25219
25233
|
var statusListRoutes = ({
|
|
@@ -25238,7 +25252,7 @@ var statusListRoutes = ({
|
|
|
25238
25252
|
});
|
|
25239
25253
|
return new Response(jwt, {
|
|
25240
25254
|
headers: { "content-type": STATUS_LIST_SUB_TYP },
|
|
25241
|
-
status:
|
|
25255
|
+
status: HTTP_OK5
|
|
25242
25256
|
});
|
|
25243
25257
|
}, { params: t34.Object({ listId: t34.String() }) });
|
|
25244
25258
|
};
|
|
@@ -25446,8 +25460,8 @@ var createInMemoryPresentationRequestStore = () => {
|
|
|
25446
25460
|
};
|
|
25447
25461
|
// src/vc/vpRoutes.ts
|
|
25448
25462
|
import { Elysia as Elysia40, t as t35 } from "elysia";
|
|
25449
|
-
var
|
|
25450
|
-
var
|
|
25463
|
+
var HTTP_OK6 = 200;
|
|
25464
|
+
var HTTP_BAD_REQUEST5 = 400;
|
|
25451
25465
|
var HTTP_NOT_FOUND2 = 404;
|
|
25452
25466
|
var errorBody2 = (error, status) => new Response(JSON.stringify({ error }), {
|
|
25453
25467
|
headers: { "content-type": "application/json" },
|
|
@@ -25480,7 +25494,7 @@ var vpRoutes = ({
|
|
|
25480
25494
|
nonce: result.nonce,
|
|
25481
25495
|
request_uri: result.requestUri,
|
|
25482
25496
|
requestId: result.request.requestId
|
|
25483
|
-
}, { status:
|
|
25497
|
+
}, { status: HTTP_OK6 });
|
|
25484
25498
|
}, {
|
|
25485
25499
|
body: t35.Object({
|
|
25486
25500
|
client_id: t35.Optional(t35.String()),
|
|
@@ -25509,19 +25523,19 @@ var vpRoutes = ({
|
|
|
25509
25523
|
headers: {
|
|
25510
25524
|
"content-type": "application/oauth-authz-req+jwt"
|
|
25511
25525
|
},
|
|
25512
|
-
status:
|
|
25526
|
+
status: HTTP_OK6
|
|
25513
25527
|
});
|
|
25514
25528
|
}, { params: t35.Object({ id: t35.String() }) }).post(responseRoute, async ({ body }) => {
|
|
25515
25529
|
const requestId = body.state;
|
|
25516
25530
|
if (requestId === undefined) {
|
|
25517
|
-
return errorBody2("missing_state",
|
|
25531
|
+
return errorBody2("missing_state", HTTP_BAD_REQUEST5);
|
|
25518
25532
|
}
|
|
25519
25533
|
const result = await verifyPresentationResponse({
|
|
25520
25534
|
config: vpConfig,
|
|
25521
25535
|
input: { requestId, vpToken: body.vp_token }
|
|
25522
25536
|
});
|
|
25523
25537
|
if (!result.ok)
|
|
25524
|
-
return errorBody2(result.error,
|
|
25538
|
+
return errorBody2(result.error, HTTP_BAD_REQUEST5);
|
|
25525
25539
|
if (onVerifiedPresentation !== undefined) {
|
|
25526
25540
|
await onVerifiedPresentation({ verified: result.verified });
|
|
25527
25541
|
}
|
|
@@ -25530,7 +25544,7 @@ var vpRoutes = ({
|
|
|
25530
25544
|
holder_jwk: result.verified.holderJwk,
|
|
25531
25545
|
protected_claims: result.verified.protectedClaims,
|
|
25532
25546
|
verified: true
|
|
25533
|
-
}, { status:
|
|
25547
|
+
}, { status: HTTP_OK6 });
|
|
25534
25548
|
}, {
|
|
25535
25549
|
body: t35.Object({
|
|
25536
25550
|
presentation_submission: t35.Optional(t35.Unknown()),
|
|
@@ -28640,17 +28654,17 @@ var blockMigrations = {
|
|
|
28640
28654
|
};
|
|
28641
28655
|
// src/sso/samlIdpRoutes.ts
|
|
28642
28656
|
import { Elysia as Elysia41, t as t36 } from "elysia";
|
|
28643
|
-
var
|
|
28644
|
-
var
|
|
28657
|
+
var HTTP_BAD_REQUEST6 = 400;
|
|
28658
|
+
var HTTP_UNAUTHORIZED6 = 401;
|
|
28645
28659
|
var HTTP_FOUND2 = 302;
|
|
28646
|
-
var
|
|
28660
|
+
var HTTP_OK7 = 200;
|
|
28647
28661
|
var xmlResponse = (body) => new Response(body, {
|
|
28648
28662
|
headers: { "content-type": "application/samlmetadata+xml" },
|
|
28649
|
-
status:
|
|
28663
|
+
status: HTTP_OK7
|
|
28650
28664
|
});
|
|
28651
28665
|
var htmlResponse = (body) => new Response(body, {
|
|
28652
28666
|
headers: { "content-type": "text/html; charset=utf-8" },
|
|
28653
|
-
status:
|
|
28667
|
+
status: HTTP_OK7
|
|
28654
28668
|
});
|
|
28655
28669
|
var redirectTo2 = (url) => new Response(null, { headers: { location: url }, status: HTTP_FOUND2 });
|
|
28656
28670
|
var errorJson = (status, error) => new Response(JSON.stringify({ error }), {
|
|
@@ -28702,7 +28716,7 @@ var samlIdpRoutes = ({
|
|
|
28702
28716
|
userSessionIdValue
|
|
28703
28717
|
}) => {
|
|
28704
28718
|
if (body.SAMLRequest === undefined) {
|
|
28705
|
-
return errorJson(
|
|
28719
|
+
return errorJson(HTTP_BAD_REQUEST6, "missing_saml_request");
|
|
28706
28720
|
}
|
|
28707
28721
|
let firstPass;
|
|
28708
28722
|
try {
|
|
@@ -28711,11 +28725,11 @@ var samlIdpRoutes = ({
|
|
|
28711
28725
|
samlRequest: body.SAMLRequest
|
|
28712
28726
|
});
|
|
28713
28727
|
} catch {
|
|
28714
|
-
return errorJson(
|
|
28728
|
+
return errorJson(HTTP_BAD_REQUEST6, "invalid_authn_request");
|
|
28715
28729
|
}
|
|
28716
28730
|
const serviceProvider = await samlServiceProviderStore.findServiceProvider(firstPass.issuer);
|
|
28717
28731
|
if (serviceProvider === undefined) {
|
|
28718
|
-
return errorJson(
|
|
28732
|
+
return errorJson(HTTP_BAD_REQUEST6, "unknown_service_provider");
|
|
28719
28733
|
}
|
|
28720
28734
|
let parsed;
|
|
28721
28735
|
try {
|
|
@@ -28728,7 +28742,7 @@ var samlIdpRoutes = ({
|
|
|
28728
28742
|
signedQueryString: binding === "Redirect" ? new URL(request.url).search.slice(1) : undefined
|
|
28729
28743
|
});
|
|
28730
28744
|
} catch {
|
|
28731
|
-
return errorJson(
|
|
28745
|
+
return errorJson(HTTP_BAD_REQUEST6, "invalid_authn_request");
|
|
28732
28746
|
}
|
|
28733
28747
|
const userSession = await loadSessionFromSource({
|
|
28734
28748
|
authSessionStore,
|
|
@@ -28737,7 +28751,7 @@ var samlIdpRoutes = ({
|
|
|
28737
28751
|
});
|
|
28738
28752
|
if (userSession === undefined || parsed.forceAuthn === true) {
|
|
28739
28753
|
if (loginUrl === undefined) {
|
|
28740
|
-
return errorJson(
|
|
28754
|
+
return errorJson(HTTP_UNAUTHORIZED6, "login_required");
|
|
28741
28755
|
}
|
|
28742
28756
|
return redirectTo2(`${loginUrl}?return_to=${encodeURIComponent(request.url)}`);
|
|
28743
28757
|
}
|
|
@@ -28786,11 +28800,11 @@ var samlIdpRoutes = ({
|
|
|
28786
28800
|
store
|
|
28787
28801
|
}) => {
|
|
28788
28802
|
if (serviceProviderEntityId === undefined) {
|
|
28789
|
-
return errorJson(
|
|
28803
|
+
return errorJson(HTTP_BAD_REQUEST6, "missing_sp");
|
|
28790
28804
|
}
|
|
28791
28805
|
const serviceProvider = await samlServiceProviderStore.findServiceProvider(serviceProviderEntityId);
|
|
28792
28806
|
if (serviceProvider === undefined) {
|
|
28793
|
-
return errorJson(
|
|
28807
|
+
return errorJson(HTTP_BAD_REQUEST6, "unknown_service_provider");
|
|
28794
28808
|
}
|
|
28795
28809
|
const userSession = authSessionStore === undefined ? await loadSessionFromSource({
|
|
28796
28810
|
session: store.session,
|
|
@@ -28802,7 +28816,7 @@ var samlIdpRoutes = ({
|
|
|
28802
28816
|
});
|
|
28803
28817
|
if (userSession === undefined) {
|
|
28804
28818
|
if (loginUrl === undefined) {
|
|
28805
|
-
return errorJson(
|
|
28819
|
+
return errorJson(HTTP_UNAUTHORIZED6, "login_required");
|
|
28806
28820
|
}
|
|
28807
28821
|
return redirectTo2(`${loginUrl}?return_to=${encodeURIComponent(request.url)}`);
|
|
28808
28822
|
}
|
|
@@ -29815,5 +29829,5 @@ export {
|
|
|
29815
29829
|
AGENT_CLAIM_GRANT_TYPE
|
|
29816
29830
|
};
|
|
29817
29831
|
|
|
29818
|
-
//# debugId=
|
|
29832
|
+
//# debugId=394E6CA4C2DE944764756E2164756E21
|
|
29819
29833
|
//# sourceMappingURL=index.js.map
|