@absolutejs/auth 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/credentials/config.d.ts +1 -0
- package/dist/credentials/login.d.ts +1 -1
- package/dist/credentials/register.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +354 -309
- package/dist/index.js.map +22 -22
- package/dist/mfa/challenge.d.ts +1 -1
- package/dist/mfa/config.d.ts +1 -0
- package/dist/passwordless/config.d.ts +1 -0
- package/dist/passwordless/routes.d.ts +1 -1
- package/dist/routes/authorize.d.ts +2 -1
- package/dist/routes/signout.d.ts +1 -1
- package/dist/session/anonymous.d.ts +2 -1
- package/dist/session/impersonation.d.ts +4 -2
- package/dist/session/multiSession.d.ts +5 -3
- package/dist/session/promote.d.ts +2 -1
- package/dist/sso/oidcRoutes.d.ts +2 -1
- package/dist/sso/samlRoutes.d.ts +2 -1
- package/dist/types.d.ts +14 -1
- package/dist/utils.d.ts +4 -2
- package/dist/webauthn/config.d.ts +1 -0
- package/dist/webauthn/routes.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3184,6 +3184,184 @@ var protectPermissionPlugin = ({
|
|
|
3184
3184
|
// src/compliance/routes.ts
|
|
3185
3185
|
import { Elysia as Elysia4, t as t4 } from "elysia";
|
|
3186
3186
|
|
|
3187
|
+
// src/utils.ts
|
|
3188
|
+
var defineAuthConfig = (configuration) => configuration;
|
|
3189
|
+
var defineAuthHtmxConfig = (htmxConfig) => htmxConfig;
|
|
3190
|
+
var defineAuthSettings = (settings) => settings;
|
|
3191
|
+
var defineProvidersConfiguration = (providersConfiguration) => providersConfiguration;
|
|
3192
|
+
var getStatus = async (session, user_session_id) => {
|
|
3193
|
+
if (user_session_id === undefined) {
|
|
3194
|
+
return {
|
|
3195
|
+
error: {
|
|
3196
|
+
code: "Bad Request",
|
|
3197
|
+
message: "Cookies are missing"
|
|
3198
|
+
},
|
|
3199
|
+
user: null
|
|
3200
|
+
};
|
|
3201
|
+
}
|
|
3202
|
+
const userSession = validateSession({ session, user_session_id });
|
|
3203
|
+
const user = userSession?.user ?? null;
|
|
3204
|
+
return {
|
|
3205
|
+
error: null,
|
|
3206
|
+
user
|
|
3207
|
+
};
|
|
3208
|
+
};
|
|
3209
|
+
var instantiateUserSession = async ({
|
|
3210
|
+
authProvider,
|
|
3211
|
+
cookieSecure,
|
|
3212
|
+
session,
|
|
3213
|
+
user_session_id,
|
|
3214
|
+
unregisteredSession,
|
|
3215
|
+
tokenResponse,
|
|
3216
|
+
providerInstance,
|
|
3217
|
+
getUser,
|
|
3218
|
+
onNewUser,
|
|
3219
|
+
resolvedAuthorization,
|
|
3220
|
+
sessionDurationMs = MILLISECONDS_IN_A_DAY,
|
|
3221
|
+
unregisteredSessionDurationMs = MILLISECONDS_IN_AN_HOUR
|
|
3222
|
+
}) => {
|
|
3223
|
+
const authorization = resolvedAuthorization ?? await resolveOAuthAuthorization({
|
|
3224
|
+
authProvider,
|
|
3225
|
+
providerInstance,
|
|
3226
|
+
tokenResponse
|
|
3227
|
+
});
|
|
3228
|
+
const { accessToken, refreshToken, userIdentity } = authorization;
|
|
3229
|
+
const userSession = validateSession({ session, user_session_id });
|
|
3230
|
+
const userSessionId = getUserSessionId({
|
|
3231
|
+
cookieSecure,
|
|
3232
|
+
session,
|
|
3233
|
+
unregisteredSession,
|
|
3234
|
+
user_session_id
|
|
3235
|
+
});
|
|
3236
|
+
let user = userSession?.user ?? await getUser(userIdentity);
|
|
3237
|
+
const response = user ?? await onNewUser(userIdentity);
|
|
3238
|
+
const isRedirectOrStatus = response instanceof Response || isStatusResponse(response);
|
|
3239
|
+
if (!isRedirectOrStatus) {
|
|
3240
|
+
user = response;
|
|
3241
|
+
session[userSessionId] = {
|
|
3242
|
+
accessToken,
|
|
3243
|
+
authenticatedAt: Date.now(),
|
|
3244
|
+
expiresAt: Date.now() + sessionDurationMs,
|
|
3245
|
+
refreshToken,
|
|
3246
|
+
user
|
|
3247
|
+
};
|
|
3248
|
+
return;
|
|
3249
|
+
}
|
|
3250
|
+
const existingUnregistered = unregisteredSession[userSessionId];
|
|
3251
|
+
if (existingUnregistered) {
|
|
3252
|
+
existingUnregistered.accessToken = accessToken;
|
|
3253
|
+
existingUnregistered.expiresAt = Date.now() + unregisteredSessionDurationMs;
|
|
3254
|
+
existingUnregistered.refreshToken = refreshToken;
|
|
3255
|
+
existingUnregistered.userIdentity = userIdentity;
|
|
3256
|
+
return response;
|
|
3257
|
+
}
|
|
3258
|
+
unregisteredSession[userSessionId] = {
|
|
3259
|
+
accessToken,
|
|
3260
|
+
expiresAt: Date.now() + unregisteredSessionDurationMs,
|
|
3261
|
+
refreshToken,
|
|
3262
|
+
userIdentity
|
|
3263
|
+
};
|
|
3264
|
+
return response;
|
|
3265
|
+
};
|
|
3266
|
+
var resolveCookieSecure = (override) => override ?? false;
|
|
3267
|
+
var resolveOAuthAuthorization = async ({
|
|
3268
|
+
authProvider,
|
|
3269
|
+
providerInstance,
|
|
3270
|
+
tokenResponse,
|
|
3271
|
+
now = Date.now()
|
|
3272
|
+
}) => {
|
|
3273
|
+
let userIdentity;
|
|
3274
|
+
let accessToken = tokenResponse.access_token;
|
|
3275
|
+
let refreshToken = tokenResponse.refresh_token;
|
|
3276
|
+
if (tokenResponse.id_token) {
|
|
3277
|
+
userIdentity = normalizeProviderIdentity({
|
|
3278
|
+
identity: decodeJWT(tokenResponse.id_token),
|
|
3279
|
+
providerConfiguration: providers[authProvider],
|
|
3280
|
+
source: "idToken"
|
|
3281
|
+
});
|
|
3282
|
+
} else if (authProvider === "withings") {
|
|
3283
|
+
userIdentity = { userid: tokenResponse.body.userid };
|
|
3284
|
+
accessToken = tokenResponse.body.access_token;
|
|
3285
|
+
refreshToken = tokenResponse.body.refresh_token;
|
|
3286
|
+
} else {
|
|
3287
|
+
userIdentity = normalizeProviderIdentity({
|
|
3288
|
+
identity: await providerInstance.fetchUserProfile(tokenResponse.access_token),
|
|
3289
|
+
providerConfiguration: providers[authProvider],
|
|
3290
|
+
source: "profile"
|
|
3291
|
+
});
|
|
3292
|
+
}
|
|
3293
|
+
const tokenType = Reflect.get(tokenResponse, "token_type");
|
|
3294
|
+
return {
|
|
3295
|
+
accessToken,
|
|
3296
|
+
expiresAt: resolveOAuthTokenExpiresAt(tokenResponse, now),
|
|
3297
|
+
refreshToken,
|
|
3298
|
+
tokenType: typeof tokenType === "string" ? tokenType : undefined,
|
|
3299
|
+
userIdentity
|
|
3300
|
+
};
|
|
3301
|
+
};
|
|
3302
|
+
var parseExpiresInSeconds = (expiresIn) => {
|
|
3303
|
+
if (typeof expiresIn === "number") {
|
|
3304
|
+
return expiresIn;
|
|
3305
|
+
}
|
|
3306
|
+
if (typeof expiresIn === "string" && expiresIn.trim().length > 0) {
|
|
3307
|
+
return Number(expiresIn);
|
|
3308
|
+
}
|
|
3309
|
+
return Number.NaN;
|
|
3310
|
+
};
|
|
3311
|
+
var resolveOAuthTokenExpiresAt = (tokenResponse, now = Date.now()) => {
|
|
3312
|
+
const expiresIn = Reflect.get(tokenResponse, "expires_in");
|
|
3313
|
+
const expiresInSeconds = parseExpiresInSeconds(expiresIn);
|
|
3314
|
+
if (!Number.isFinite(expiresInSeconds) || expiresInSeconds <= 0) {
|
|
3315
|
+
return;
|
|
3316
|
+
}
|
|
3317
|
+
return now + expiresInSeconds * 1000;
|
|
3318
|
+
};
|
|
3319
|
+
var validateSession = ({
|
|
3320
|
+
user_session_id,
|
|
3321
|
+
session
|
|
3322
|
+
}) => {
|
|
3323
|
+
const userSessionId = user_session_id.value;
|
|
3324
|
+
if (!userSessionId) {
|
|
3325
|
+
return;
|
|
3326
|
+
}
|
|
3327
|
+
const userSession = session[userSessionId];
|
|
3328
|
+
if (!userSession) {
|
|
3329
|
+
return;
|
|
3330
|
+
}
|
|
3331
|
+
const isExpired = userSession.expiresAt < Date.now();
|
|
3332
|
+
if (isExpired) {
|
|
3333
|
+
delete session[userSessionId];
|
|
3334
|
+
user_session_id.remove();
|
|
3335
|
+
return;
|
|
3336
|
+
}
|
|
3337
|
+
return userSession;
|
|
3338
|
+
};
|
|
3339
|
+
var clearExistingSession = (existingId, session, unregisteredSession) => {
|
|
3340
|
+
if (session)
|
|
3341
|
+
delete session[existingId];
|
|
3342
|
+
if (unregisteredSession)
|
|
3343
|
+
delete unregisteredSession[existingId];
|
|
3344
|
+
};
|
|
3345
|
+
var getUserSessionId = ({
|
|
3346
|
+
cookieSecure,
|
|
3347
|
+
user_session_id,
|
|
3348
|
+
session,
|
|
3349
|
+
unregisteredSession
|
|
3350
|
+
}) => {
|
|
3351
|
+
const existingId = user_session_id?.value;
|
|
3352
|
+
if (isNonEmptyString(existingId)) {
|
|
3353
|
+
clearExistingSession(existingId, session, unregisteredSession);
|
|
3354
|
+
}
|
|
3355
|
+
const userSessionId = crypto.randomUUID();
|
|
3356
|
+
user_session_id.set({
|
|
3357
|
+
httpOnly: true,
|
|
3358
|
+
sameSite: "lax",
|
|
3359
|
+
secure: resolveCookieSecure(cookieSecure),
|
|
3360
|
+
value: userSessionId
|
|
3361
|
+
});
|
|
3362
|
+
return userSessionId;
|
|
3363
|
+
};
|
|
3364
|
+
|
|
3187
3365
|
// src/session/promote.ts
|
|
3188
3366
|
var clearSession = async ({
|
|
3189
3367
|
authSessionStore,
|
|
@@ -3216,6 +3394,7 @@ var promoteToSession = async ({
|
|
|
3216
3394
|
anonymous,
|
|
3217
3395
|
authSessionStore,
|
|
3218
3396
|
cookie,
|
|
3397
|
+
cookieSecure,
|
|
3219
3398
|
impersonator,
|
|
3220
3399
|
inMemorySession,
|
|
3221
3400
|
samlLogout,
|
|
@@ -3243,7 +3422,7 @@ var promoteToSession = async ({
|
|
|
3243
3422
|
cookie.set({
|
|
3244
3423
|
httpOnly: true,
|
|
3245
3424
|
sameSite: "lax",
|
|
3246
|
-
secure:
|
|
3425
|
+
secure: resolveCookieSecure(cookieSecure),
|
|
3247
3426
|
value: userSessionId
|
|
3248
3427
|
});
|
|
3249
3428
|
if (authSessionStore) {
|
|
@@ -3549,6 +3728,7 @@ var isPasswordCompromised = (password) => isPasswordBreached(password);
|
|
|
3549
3728
|
var credentialsLogin = ({
|
|
3550
3729
|
authSessionStore,
|
|
3551
3730
|
checkBreachesOnLogin,
|
|
3731
|
+
cookieSecure,
|
|
3552
3732
|
credentialStore,
|
|
3553
3733
|
getUserByEmail,
|
|
3554
3734
|
isMfaRequired,
|
|
@@ -3620,7 +3800,7 @@ var credentialsLogin = ({
|
|
|
3620
3800
|
user_session_id.set({
|
|
3621
3801
|
httpOnly: true,
|
|
3622
3802
|
sameSite: "lax",
|
|
3623
|
-
secure:
|
|
3803
|
+
secure: resolveCookieSecure(cookieSecure),
|
|
3624
3804
|
value: pendingSessionId
|
|
3625
3805
|
});
|
|
3626
3806
|
await persistWhen(authSessionStore !== undefined, compatibilityLayer.persist);
|
|
@@ -3630,6 +3810,7 @@ var credentialsLogin = ({
|
|
|
3630
3810
|
const userSessionId = await promoteToSession({
|
|
3631
3811
|
authSessionStore,
|
|
3632
3812
|
cookie: user_session_id,
|
|
3813
|
+
cookieSecure,
|
|
3633
3814
|
inMemorySession: session,
|
|
3634
3815
|
sessionDurationMs,
|
|
3635
3816
|
user
|
|
@@ -3703,6 +3884,7 @@ var credentialsPasswordReset = ({
|
|
|
3703
3884
|
import { Elysia as Elysia8, t as t8 } from "elysia";
|
|
3704
3885
|
var credentialsRegister = ({
|
|
3705
3886
|
authSessionStore,
|
|
3887
|
+
cookieSecure,
|
|
3706
3888
|
credentialStore,
|
|
3707
3889
|
onCreateCredentialUser,
|
|
3708
3890
|
onCredentialsLoginSuccess,
|
|
@@ -3773,6 +3955,7 @@ var credentialsRegister = ({
|
|
|
3773
3955
|
const userSessionId = await promoteToSession({
|
|
3774
3956
|
authSessionStore,
|
|
3775
3957
|
cookie: user_session_id,
|
|
3958
|
+
cookieSecure,
|
|
3776
3959
|
inMemorySession: session,
|
|
3777
3960
|
sessionDurationMs,
|
|
3778
3961
|
user: created
|
|
@@ -4041,6 +4224,7 @@ var encryptTotpSecret = (secret, encryptionKey) => encryptionKey ? encryptSecret
|
|
|
4041
4224
|
var mfaChallenge = ({
|
|
4042
4225
|
authSessionStore,
|
|
4043
4226
|
challengeRoute = "/auth/mfa/challenge",
|
|
4227
|
+
cookieSecure,
|
|
4044
4228
|
encryptionKey,
|
|
4045
4229
|
getChallengeUser,
|
|
4046
4230
|
getUserId,
|
|
@@ -4098,7 +4282,7 @@ var mfaChallenge = ({
|
|
|
4098
4282
|
user_session_id.set({
|
|
4099
4283
|
httpOnly: true,
|
|
4100
4284
|
sameSite: "lax",
|
|
4101
|
-
secure:
|
|
4285
|
+
secure: resolveCookieSecure(cookieSecure),
|
|
4102
4286
|
value: userSessionId
|
|
4103
4287
|
});
|
|
4104
4288
|
await persistWhen(authSessionStore !== undefined, compatibilityLayer.persist);
|
|
@@ -6480,6 +6664,7 @@ var generateOtpCode = (length) => {
|
|
|
6480
6664
|
};
|
|
6481
6665
|
var passwordlessRoutes = ({
|
|
6482
6666
|
authSessionStore,
|
|
6667
|
+
cookieSecure,
|
|
6483
6668
|
emit,
|
|
6484
6669
|
getUserByEmail,
|
|
6485
6670
|
getUserId,
|
|
@@ -6505,6 +6690,7 @@ var passwordlessRoutes = ({
|
|
|
6505
6690
|
const userSessionId = await promoteToSession({
|
|
6506
6691
|
authSessionStore,
|
|
6507
6692
|
cookie: userSessionCookie,
|
|
6693
|
+
cookieSecure,
|
|
6508
6694
|
inMemorySession: session,
|
|
6509
6695
|
sessionDurationMs,
|
|
6510
6696
|
user
|
|
@@ -7072,132 +7258,136 @@ var parseReferer = (headerReferer) => {
|
|
|
7072
7258
|
var authorize = ({
|
|
7073
7259
|
clientProviders,
|
|
7074
7260
|
authorizeRoute = "/oauth2/:provider/authorization",
|
|
7261
|
+
cookieSecure,
|
|
7075
7262
|
onAuthorizeSuccess,
|
|
7076
7263
|
onAuthorizeError
|
|
7077
|
-
}) => new Elysia20().get(authorizeRoute, async ({
|
|
7078
|
-
status,
|
|
7079
|
-
redirect,
|
|
7080
|
-
cookie: {
|
|
7081
|
-
state,
|
|
7082
|
-
code_verifier,
|
|
7083
|
-
auth_provider,
|
|
7084
|
-
auth_client,
|
|
7085
|
-
auth_intent,
|
|
7086
|
-
origin_url
|
|
7087
|
-
},
|
|
7088
|
-
params: { provider },
|
|
7089
|
-
query: { client, intent },
|
|
7090
|
-
headers
|
|
7091
7264
|
}) => {
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
|
|
7115
|
-
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
7122
|
-
|
|
7123
|
-
|
|
7124
|
-
httpOnly: true,
|
|
7125
|
-
maxAge: COOKIE_DURATION,
|
|
7126
|
-
path: "/",
|
|
7127
|
-
sameSite: "lax",
|
|
7128
|
-
secure: true,
|
|
7129
|
-
value: clientName ?? ""
|
|
7130
|
-
});
|
|
7131
|
-
if (authIntent !== undefined) {
|
|
7132
|
-
auth_intent.set({
|
|
7265
|
+
const secure = resolveCookieSecure(cookieSecure);
|
|
7266
|
+
return new Elysia20().get(authorizeRoute, async ({
|
|
7267
|
+
status,
|
|
7268
|
+
redirect,
|
|
7269
|
+
cookie: {
|
|
7270
|
+
state,
|
|
7271
|
+
code_verifier,
|
|
7272
|
+
auth_provider,
|
|
7273
|
+
auth_client,
|
|
7274
|
+
auth_intent,
|
|
7275
|
+
origin_url
|
|
7276
|
+
},
|
|
7277
|
+
params: { provider },
|
|
7278
|
+
query: { client, intent },
|
|
7279
|
+
headers
|
|
7280
|
+
}) => {
|
|
7281
|
+
if (auth_provider === undefined || auth_client === undefined || auth_intent === undefined || origin_url === undefined || state === undefined || code_verifier === undefined)
|
|
7282
|
+
return status("Bad Request", "Cookies are missing");
|
|
7283
|
+
if (provider === undefined)
|
|
7284
|
+
return status("Bad Request", "Provider is required");
|
|
7285
|
+
const resolvedProvider = resolveClientProviderEntry({
|
|
7286
|
+
clientName: client,
|
|
7287
|
+
clientProviders,
|
|
7288
|
+
providerName: provider
|
|
7289
|
+
});
|
|
7290
|
+
if ("error" in resolvedProvider) {
|
|
7291
|
+
return status("Unauthorized", resolvedProvider.error);
|
|
7292
|
+
}
|
|
7293
|
+
const { clientName, providerInstance, scope, searchParams } = resolvedProvider.entry;
|
|
7294
|
+
const referer = parseReferer(headers["referer"]);
|
|
7295
|
+
const authIntent = isAuthIntent(intent) ? intent : undefined;
|
|
7296
|
+
origin_url.set({
|
|
7133
7297
|
httpOnly: true,
|
|
7134
7298
|
maxAge: COOKIE_DURATION,
|
|
7135
7299
|
path: "/",
|
|
7136
7300
|
sameSite: "lax",
|
|
7137
|
-
secure
|
|
7138
|
-
value:
|
|
7301
|
+
secure,
|
|
7302
|
+
value: referer
|
|
7139
7303
|
});
|
|
7140
|
-
|
|
7141
|
-
auth_intent.remove();
|
|
7142
|
-
}
|
|
7143
|
-
const currentState = generateState();
|
|
7144
|
-
state.set({
|
|
7145
|
-
httpOnly: true,
|
|
7146
|
-
maxAge: COOKIE_DURATION,
|
|
7147
|
-
path: "/",
|
|
7148
|
-
sameSite: "lax",
|
|
7149
|
-
secure: true,
|
|
7150
|
-
value: currentState
|
|
7151
|
-
});
|
|
7152
|
-
const codeVerifier = isPKCEProviderOption(provider) ? generateCodeVerifier() : undefined;
|
|
7153
|
-
if (codeVerifier) {
|
|
7154
|
-
code_verifier.set({
|
|
7304
|
+
auth_provider.set({
|
|
7155
7305
|
httpOnly: true,
|
|
7156
7306
|
maxAge: COOKIE_DURATION,
|
|
7157
7307
|
path: "/",
|
|
7158
7308
|
sameSite: "lax",
|
|
7159
|
-
secure
|
|
7160
|
-
value:
|
|
7161
|
-
});
|
|
7162
|
-
}
|
|
7163
|
-
try {
|
|
7164
|
-
const authorizationURL = await providerInstance.createAuthorizationUrl(codeVerifier ? { codeVerifier, scope, state: currentState } : { scope, state: currentState });
|
|
7165
|
-
searchParams?.forEach(([key, value]) => authorizationURL.searchParams.set(key, value));
|
|
7166
|
-
await onAuthorizeSuccess?.({
|
|
7167
|
-
authClient: clientName,
|
|
7168
|
-
authIntent,
|
|
7169
|
-
authorizationUrl: authorizationURL,
|
|
7170
|
-
authProvider: provider
|
|
7309
|
+
secure,
|
|
7310
|
+
value: provider
|
|
7171
7311
|
});
|
|
7172
|
-
|
|
7173
|
-
|
|
7174
|
-
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7312
|
+
auth_client.set({
|
|
7313
|
+
httpOnly: true,
|
|
7314
|
+
maxAge: COOKIE_DURATION,
|
|
7315
|
+
path: "/",
|
|
7316
|
+
sameSite: "lax",
|
|
7317
|
+
secure,
|
|
7318
|
+
value: clientName ?? ""
|
|
7179
7319
|
});
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7320
|
+
if (authIntent !== undefined) {
|
|
7321
|
+
auth_intent.set({
|
|
7322
|
+
httpOnly: true,
|
|
7323
|
+
maxAge: COOKIE_DURATION,
|
|
7324
|
+
path: "/",
|
|
7325
|
+
sameSite: "lax",
|
|
7326
|
+
secure,
|
|
7327
|
+
value: authIntent
|
|
7328
|
+
});
|
|
7329
|
+
} else {
|
|
7330
|
+
auth_intent.remove();
|
|
7331
|
+
}
|
|
7332
|
+
const currentState = generateState();
|
|
7333
|
+
state.set({
|
|
7334
|
+
httpOnly: true,
|
|
7335
|
+
maxAge: COOKIE_DURATION,
|
|
7336
|
+
path: "/",
|
|
7337
|
+
sameSite: "lax",
|
|
7338
|
+
secure,
|
|
7339
|
+
value: currentState
|
|
7184
7340
|
});
|
|
7185
|
-
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7341
|
+
const codeVerifier = isPKCEProviderOption(provider) ? generateCodeVerifier() : undefined;
|
|
7342
|
+
if (codeVerifier) {
|
|
7343
|
+
code_verifier.set({
|
|
7344
|
+
httpOnly: true,
|
|
7345
|
+
maxAge: COOKIE_DURATION,
|
|
7346
|
+
path: "/",
|
|
7347
|
+
sameSite: "lax",
|
|
7348
|
+
secure,
|
|
7349
|
+
value: codeVerifier
|
|
7350
|
+
});
|
|
7351
|
+
}
|
|
7352
|
+
try {
|
|
7353
|
+
const authorizationURL = await providerInstance.createAuthorizationUrl(codeVerifier ? { codeVerifier, scope, state: currentState } : { scope, state: currentState });
|
|
7354
|
+
searchParams?.forEach(([key, value]) => authorizationURL.searchParams.set(key, value));
|
|
7355
|
+
await onAuthorizeSuccess?.({
|
|
7356
|
+
authClient: clientName,
|
|
7357
|
+
authIntent,
|
|
7358
|
+
authorizationUrl: authorizationURL,
|
|
7359
|
+
authProvider: provider
|
|
7360
|
+
});
|
|
7361
|
+
return redirect(authorizationURL.toString());
|
|
7362
|
+
} catch (err) {
|
|
7363
|
+
console.error("[authorize] Failed to create authorization URL:", {
|
|
7364
|
+
authClient: clientName,
|
|
7365
|
+
error: err instanceof Error ? err.message : err,
|
|
7366
|
+
provider,
|
|
7367
|
+
stack: err instanceof Error ? err.stack : undefined
|
|
7368
|
+
});
|
|
7369
|
+
await onAuthorizeError?.({
|
|
7370
|
+
authClient: clientName,
|
|
7371
|
+
authProvider: provider,
|
|
7372
|
+
error: err
|
|
7373
|
+
});
|
|
7374
|
+
return status("Internal Server Error", "Failed to create authorization URL");
|
|
7375
|
+
}
|
|
7376
|
+
}, {
|
|
7377
|
+
cookie: t17.Cookie({
|
|
7378
|
+
auth_client: authClientOption,
|
|
7379
|
+
auth_intent: authIntentOption,
|
|
7380
|
+
auth_provider: t17.Optional(authProviderOption)
|
|
7381
|
+
}),
|
|
7382
|
+
params: t17.Object({
|
|
7383
|
+
provider: authProviderOption
|
|
7384
|
+
}),
|
|
7385
|
+
query: t17.Object({
|
|
7386
|
+
client: authClientOption,
|
|
7387
|
+
intent: authIntentOption
|
|
7388
|
+
})
|
|
7389
|
+
});
|
|
7390
|
+
};
|
|
7201
7391
|
|
|
7202
7392
|
// src/routes/callback.ts
|
|
7203
7393
|
import { Elysia as Elysia21, t as t18 } from "elysia";
|
|
@@ -7701,12 +7891,9 @@ var signout = ({
|
|
|
7701
7891
|
store: { session },
|
|
7702
7892
|
cookie: { user_session_id, auth_provider }
|
|
7703
7893
|
}) => {
|
|
7704
|
-
if (
|
|
7894
|
+
if (user_session_id === undefined) {
|
|
7705
7895
|
return status("Bad Request", "Cookies are missing");
|
|
7706
7896
|
}
|
|
7707
|
-
if (auth_provider.value === undefined) {
|
|
7708
|
-
return status("Unauthorized", "No auth provider found");
|
|
7709
|
-
}
|
|
7710
7897
|
if (user_session_id.value === undefined) {
|
|
7711
7898
|
return status("Unauthorized", "No user session id found");
|
|
7712
7899
|
}
|
|
@@ -7718,7 +7905,7 @@ var signout = ({
|
|
|
7718
7905
|
const currentSession = signoutSession[user_session_id.value];
|
|
7719
7906
|
if (currentSession !== undefined) {
|
|
7720
7907
|
const signedOut = await runSignOut(onSignOut, {
|
|
7721
|
-
authProvider: auth_provider
|
|
7908
|
+
authProvider: auth_provider?.value,
|
|
7722
7909
|
session: signoutSession,
|
|
7723
7910
|
userSessionId: user_session_id.value
|
|
7724
7911
|
});
|
|
@@ -7735,7 +7922,7 @@ var signout = ({
|
|
|
7735
7922
|
delete session[user_session_id.value];
|
|
7736
7923
|
}
|
|
7737
7924
|
user_session_id.remove();
|
|
7738
|
-
auth_provider
|
|
7925
|
+
auth_provider?.remove();
|
|
7739
7926
|
return new Response(null, { status: 204 });
|
|
7740
7927
|
}, {
|
|
7741
7928
|
cookie: t24.Cookie({
|
|
@@ -8470,13 +8657,13 @@ var ssoDiscoveryRoute = ({
|
|
|
8470
8657
|
|
|
8471
8658
|
// src/sso/oidcRoutes.ts
|
|
8472
8659
|
import { Elysia as Elysia32, t as t28 } from "elysia";
|
|
8473
|
-
var
|
|
8660
|
+
var makeSsoCookieOptions = (secure) => ({
|
|
8474
8661
|
httpOnly: true,
|
|
8475
8662
|
maxAge: COOKIE_DURATION,
|
|
8476
8663
|
path: "/",
|
|
8477
8664
|
sameSite: "lax",
|
|
8478
|
-
secure
|
|
8479
|
-
};
|
|
8665
|
+
secure
|
|
8666
|
+
});
|
|
8480
8667
|
var ssoCookieSchema = t28.Cookie({
|
|
8481
8668
|
sso_nonce: t28.Optional(t28.String()),
|
|
8482
8669
|
sso_organization: t28.Optional(t28.String()),
|
|
@@ -8497,6 +8684,7 @@ var parseReferer2 = (referer) => {
|
|
|
8497
8684
|
};
|
|
8498
8685
|
var oidcSsoRoutes = ({
|
|
8499
8686
|
authSessionStore,
|
|
8687
|
+
cookieSecure,
|
|
8500
8688
|
getSsoUser,
|
|
8501
8689
|
onSsoCallbackError,
|
|
8502
8690
|
onSsoCallbackSuccess,
|
|
@@ -8504,6 +8692,7 @@ var oidcSsoRoutes = ({
|
|
|
8504
8692
|
ssoConnectionStore,
|
|
8505
8693
|
ssoRoute = DEFAULT_SSO_ROUTE
|
|
8506
8694
|
}) => {
|
|
8695
|
+
const ssoCookieOptions = makeSsoCookieOptions(resolveCookieSecure(cookieSecure));
|
|
8507
8696
|
const authorizeRoute = `${ssoRoute}/oidc/:organizationId/authorize`;
|
|
8508
8697
|
const callbackRoute = `${ssoRoute}/oidc/:organizationId/callback`;
|
|
8509
8698
|
return new Elysia32().use(sessionStore()).get(authorizeRoute, async ({
|
|
@@ -8606,6 +8795,7 @@ var oidcSsoRoutes = ({
|
|
|
8606
8795
|
const userSessionId = await promoteToSession({
|
|
8607
8796
|
authSessionStore,
|
|
8608
8797
|
cookie: user_session_id,
|
|
8798
|
+
cookieSecure,
|
|
8609
8799
|
inMemorySession: session,
|
|
8610
8800
|
sessionDurationMs,
|
|
8611
8801
|
user
|
|
@@ -8655,6 +8845,7 @@ var settle = async (work) => {
|
|
|
8655
8845
|
};
|
|
8656
8846
|
var samlSsoRoutes = ({
|
|
8657
8847
|
authSessionStore,
|
|
8848
|
+
cookieSecure,
|
|
8658
8849
|
getSsoUser,
|
|
8659
8850
|
onSsoCallbackError,
|
|
8660
8851
|
onSsoCallbackSuccess,
|
|
@@ -8730,6 +8921,7 @@ var samlSsoRoutes = ({
|
|
|
8730
8921
|
const userSessionId = await promoteToSession({
|
|
8731
8922
|
authSessionStore,
|
|
8732
8923
|
cookie: user_session_id,
|
|
8924
|
+
cookieSecure,
|
|
8733
8925
|
inMemorySession: session,
|
|
8734
8926
|
samlLogout: {
|
|
8735
8927
|
connectionId: connection.connectionId,
|
|
@@ -8897,6 +9089,7 @@ var WEBAUTHN_CHALLENGE_COOKIE = "webauthn_challenge";
|
|
|
8897
9089
|
var webauthnRoutes = ({
|
|
8898
9090
|
authSessionStore,
|
|
8899
9091
|
challengeDurationMs = DEFAULT_WEBAUTHN_CHALLENGE_TTL_MS,
|
|
9092
|
+
cookieSecure,
|
|
8900
9093
|
credentialStore,
|
|
8901
9094
|
emit,
|
|
8902
9095
|
getUserDisplayName,
|
|
@@ -8912,6 +9105,7 @@ var webauthnRoutes = ({
|
|
|
8912
9105
|
webauthnAdapter,
|
|
8913
9106
|
webauthnRoute = DEFAULT_WEBAUTHN_ROUTE
|
|
8914
9107
|
}) => {
|
|
9108
|
+
const secure = resolveCookieSecure(cookieSecure);
|
|
8915
9109
|
const challengeCookie = t30.Cookie({
|
|
8916
9110
|
user_session_id: t30.Optional(userSessionIdTypebox),
|
|
8917
9111
|
webauthn_challenge: t30.Optional(t30.String())
|
|
@@ -8920,7 +9114,7 @@ var webauthnRoutes = ({
|
|
|
8920
9114
|
httpOnly: true,
|
|
8921
9115
|
maxAge: Math.floor(challengeDurationMs / MILLISECONDS_IN_A_SECOND),
|
|
8922
9116
|
sameSite: "lax",
|
|
8923
|
-
secure
|
|
9117
|
+
secure,
|
|
8924
9118
|
value: challenge
|
|
8925
9119
|
});
|
|
8926
9120
|
return new Elysia34().use(sessionStore()).post(`${webauthnRoute}/register/options`, async ({
|
|
@@ -9052,6 +9246,7 @@ var webauthnRoutes = ({
|
|
|
9052
9246
|
const userSessionId = await promoteToSession({
|
|
9053
9247
|
authSessionStore,
|
|
9054
9248
|
cookie: user_session_id,
|
|
9249
|
+
cookieSecure,
|
|
9055
9250
|
inMemorySession: session,
|
|
9056
9251
|
sessionDurationMs,
|
|
9057
9252
|
user
|
|
@@ -19549,7 +19744,7 @@ var getGrantedScopes = (scopeValue, fallbackScopes) => {
|
|
|
19549
19744
|
}
|
|
19550
19745
|
return [...new Set(fallbackScopes.filter(Boolean))];
|
|
19551
19746
|
};
|
|
19552
|
-
var
|
|
19747
|
+
var parseExpiresInSeconds2 = (expiresIn) => {
|
|
19553
19748
|
if (typeof expiresIn === "number") {
|
|
19554
19749
|
return expiresIn;
|
|
19555
19750
|
}
|
|
@@ -19559,7 +19754,7 @@ var parseExpiresInSeconds = (expiresIn) => {
|
|
|
19559
19754
|
return Number.NaN;
|
|
19560
19755
|
};
|
|
19561
19756
|
var getExpiresAt = (tokenResponse2) => {
|
|
19562
|
-
const expiresInSeconds =
|
|
19757
|
+
const expiresInSeconds = parseExpiresInSeconds2(tokenResponse2.expires_in);
|
|
19563
19758
|
if (!Number.isFinite(expiresInSeconds) || expiresInSeconds <= 0) {
|
|
19564
19759
|
return;
|
|
19565
19760
|
}
|
|
@@ -19898,6 +20093,7 @@ var DEFAULT_IMPERSONATION_TTL_MS = MILLISECONDS_IN_AN_HOUR;
|
|
|
19898
20093
|
var endImpersonation = async ({
|
|
19899
20094
|
authSessionStore,
|
|
19900
20095
|
cookie,
|
|
20096
|
+
cookieSecure,
|
|
19901
20097
|
emit,
|
|
19902
20098
|
inMemorySession
|
|
19903
20099
|
}) => {
|
|
@@ -19930,7 +20126,7 @@ var endImpersonation = async ({
|
|
|
19930
20126
|
cookie.set({
|
|
19931
20127
|
httpOnly: true,
|
|
19932
20128
|
sameSite: "lax",
|
|
19933
|
-
secure:
|
|
20129
|
+
secure: resolveCookieSecure(cookieSecure),
|
|
19934
20130
|
value: returnTo
|
|
19935
20131
|
});
|
|
19936
20132
|
return { restored: true };
|
|
@@ -19942,6 +20138,7 @@ var isImpersonating = (session) => session?.impersonator !== undefined;
|
|
|
19942
20138
|
var startImpersonation = async ({
|
|
19943
20139
|
authSessionStore,
|
|
19944
20140
|
cookie,
|
|
20141
|
+
cookieSecure,
|
|
19945
20142
|
emit,
|
|
19946
20143
|
getUserId,
|
|
19947
20144
|
impersonator,
|
|
@@ -19959,6 +20156,7 @@ var startImpersonation = async ({
|
|
|
19959
20156
|
const sessionId = await promoteToSession({
|
|
19960
20157
|
authSessionStore,
|
|
19961
20158
|
cookie,
|
|
20159
|
+
cookieSecure,
|
|
19962
20160
|
impersonator: stamp,
|
|
19963
20161
|
inMemorySession,
|
|
19964
20162
|
sessionDurationMs,
|
|
@@ -19977,6 +20175,7 @@ var DEFAULT_GUEST_TTL_MS = MILLISECONDS_IN_A_DAY;
|
|
|
19977
20175
|
var createAnonymousSession = async ({
|
|
19978
20176
|
authSessionStore,
|
|
19979
20177
|
cookie,
|
|
20178
|
+
cookieSecure,
|
|
19980
20179
|
guestUser,
|
|
19981
20180
|
inMemorySession,
|
|
19982
20181
|
sessionDurationMs = DEFAULT_GUEST_TTL_MS
|
|
@@ -19984,6 +20183,7 @@ var createAnonymousSession = async ({
|
|
|
19984
20183
|
anonymous: true,
|
|
19985
20184
|
authSessionStore,
|
|
19986
20185
|
cookie,
|
|
20186
|
+
cookieSecure,
|
|
19987
20187
|
inMemorySession,
|
|
19988
20188
|
sessionDurationMs,
|
|
19989
20189
|
user: guestUser
|
|
@@ -19991,14 +20191,14 @@ var createAnonymousSession = async ({
|
|
|
19991
20191
|
var isAnonymousSession = (session) => session?.anonymous === true;
|
|
19992
20192
|
// src/session/multiSession.ts
|
|
19993
20193
|
var SEPARATOR = " ";
|
|
19994
|
-
var writeRing = (ring, ids) => ring.set({
|
|
20194
|
+
var writeRing = (ring, ids, cookieSecure) => ring.set({
|
|
19995
20195
|
httpOnly: true,
|
|
19996
20196
|
sameSite: "lax",
|
|
19997
|
-
secure:
|
|
20197
|
+
secure: resolveCookieSecure(cookieSecure),
|
|
19998
20198
|
value: ids.join(SEPARATOR)
|
|
19999
20199
|
});
|
|
20000
20200
|
var readRing = (ring) => (ring.value ?? "").split(SEPARATOR).filter((entry) => isUserSessionId(entry));
|
|
20001
|
-
var addToSessionRing = (ring, sessionId) => writeRing(ring, [...new Set([...readRing(ring), sessionId])]);
|
|
20201
|
+
var addToSessionRing = (ring, sessionId, cookieSecure) => writeRing(ring, [...new Set([...readRing(ring), sessionId])], cookieSecure);
|
|
20002
20202
|
var listRingSessions = async ({
|
|
20003
20203
|
authSessionStore,
|
|
20004
20204
|
inMemorySession,
|
|
@@ -20018,12 +20218,13 @@ var readSessionRing = (ring) => readRing(ring);
|
|
|
20018
20218
|
var removeFromSessionRing = async ({
|
|
20019
20219
|
activeCookie,
|
|
20020
20220
|
authSessionStore,
|
|
20221
|
+
cookieSecure,
|
|
20021
20222
|
inMemorySession,
|
|
20022
20223
|
ring,
|
|
20023
20224
|
sessionId
|
|
20024
20225
|
}) => {
|
|
20025
20226
|
const remaining = readRing(ring).filter((id) => id !== sessionId);
|
|
20026
|
-
writeRing(ring, remaining);
|
|
20227
|
+
writeRing(ring, remaining, cookieSecure);
|
|
20027
20228
|
if (authSessionStore)
|
|
20028
20229
|
await authSessionStore.removeSession(sessionId);
|
|
20029
20230
|
else if (inMemorySession)
|
|
@@ -20037,12 +20238,13 @@ var removeFromSessionRing = async ({
|
|
|
20037
20238
|
activeCookie.set({
|
|
20038
20239
|
httpOnly: true,
|
|
20039
20240
|
sameSite: "lax",
|
|
20040
|
-
secure:
|
|
20241
|
+
secure: resolveCookieSecure(cookieSecure),
|
|
20041
20242
|
value: fallback
|
|
20042
20243
|
});
|
|
20043
20244
|
};
|
|
20044
20245
|
var switchActiveSession = ({
|
|
20045
20246
|
activeCookie,
|
|
20247
|
+
cookieSecure,
|
|
20046
20248
|
ring,
|
|
20047
20249
|
sessionId
|
|
20048
20250
|
}) => {
|
|
@@ -20051,184 +20253,11 @@ var switchActiveSession = ({
|
|
|
20051
20253
|
activeCookie.set({
|
|
20052
20254
|
httpOnly: true,
|
|
20053
20255
|
sameSite: "lax",
|
|
20054
|
-
secure:
|
|
20256
|
+
secure: resolveCookieSecure(cookieSecure),
|
|
20055
20257
|
value: sessionId
|
|
20056
20258
|
});
|
|
20057
20259
|
return true;
|
|
20058
20260
|
};
|
|
20059
|
-
// src/utils.ts
|
|
20060
|
-
var defineAuthConfig = (configuration) => configuration;
|
|
20061
|
-
var defineAuthHtmxConfig = (htmxConfig) => htmxConfig;
|
|
20062
|
-
var defineAuthSettings = (settings) => settings;
|
|
20063
|
-
var defineProvidersConfiguration = (providersConfiguration) => providersConfiguration;
|
|
20064
|
-
var getStatus = async (session, user_session_id) => {
|
|
20065
|
-
if (user_session_id === undefined) {
|
|
20066
|
-
return {
|
|
20067
|
-
error: {
|
|
20068
|
-
code: "Bad Request",
|
|
20069
|
-
message: "Cookies are missing"
|
|
20070
|
-
},
|
|
20071
|
-
user: null
|
|
20072
|
-
};
|
|
20073
|
-
}
|
|
20074
|
-
const userSession = validateSession({ session, user_session_id });
|
|
20075
|
-
const user = userSession?.user ?? null;
|
|
20076
|
-
return {
|
|
20077
|
-
error: null,
|
|
20078
|
-
user
|
|
20079
|
-
};
|
|
20080
|
-
};
|
|
20081
|
-
var instantiateUserSession = async ({
|
|
20082
|
-
authProvider,
|
|
20083
|
-
session,
|
|
20084
|
-
user_session_id,
|
|
20085
|
-
unregisteredSession,
|
|
20086
|
-
tokenResponse: tokenResponse2,
|
|
20087
|
-
providerInstance,
|
|
20088
|
-
getUser,
|
|
20089
|
-
onNewUser,
|
|
20090
|
-
resolvedAuthorization,
|
|
20091
|
-
sessionDurationMs = MILLISECONDS_IN_A_DAY,
|
|
20092
|
-
unregisteredSessionDurationMs = MILLISECONDS_IN_AN_HOUR
|
|
20093
|
-
}) => {
|
|
20094
|
-
const authorization = resolvedAuthorization ?? await resolveOAuthAuthorization({
|
|
20095
|
-
authProvider,
|
|
20096
|
-
providerInstance,
|
|
20097
|
-
tokenResponse: tokenResponse2
|
|
20098
|
-
});
|
|
20099
|
-
const { accessToken, refreshToken, userIdentity } = authorization;
|
|
20100
|
-
const userSession = validateSession({ session, user_session_id });
|
|
20101
|
-
const userSessionId = getUserSessionId({
|
|
20102
|
-
session,
|
|
20103
|
-
unregisteredSession,
|
|
20104
|
-
user_session_id
|
|
20105
|
-
});
|
|
20106
|
-
let user = userSession?.user ?? await getUser(userIdentity);
|
|
20107
|
-
const response = user ?? await onNewUser(userIdentity);
|
|
20108
|
-
const isRedirectOrStatus = response instanceof Response || isStatusResponse(response);
|
|
20109
|
-
if (!isRedirectOrStatus) {
|
|
20110
|
-
user = response;
|
|
20111
|
-
session[userSessionId] = {
|
|
20112
|
-
accessToken,
|
|
20113
|
-
authenticatedAt: Date.now(),
|
|
20114
|
-
expiresAt: Date.now() + sessionDurationMs,
|
|
20115
|
-
refreshToken,
|
|
20116
|
-
user
|
|
20117
|
-
};
|
|
20118
|
-
return;
|
|
20119
|
-
}
|
|
20120
|
-
const existingUnregistered = unregisteredSession[userSessionId];
|
|
20121
|
-
if (existingUnregistered) {
|
|
20122
|
-
existingUnregistered.accessToken = accessToken;
|
|
20123
|
-
existingUnregistered.expiresAt = Date.now() + unregisteredSessionDurationMs;
|
|
20124
|
-
existingUnregistered.refreshToken = refreshToken;
|
|
20125
|
-
existingUnregistered.userIdentity = userIdentity;
|
|
20126
|
-
return response;
|
|
20127
|
-
}
|
|
20128
|
-
unregisteredSession[userSessionId] = {
|
|
20129
|
-
accessToken,
|
|
20130
|
-
expiresAt: Date.now() + unregisteredSessionDurationMs,
|
|
20131
|
-
refreshToken,
|
|
20132
|
-
userIdentity
|
|
20133
|
-
};
|
|
20134
|
-
return response;
|
|
20135
|
-
};
|
|
20136
|
-
var resolveOAuthAuthorization = async ({
|
|
20137
|
-
authProvider,
|
|
20138
|
-
providerInstance,
|
|
20139
|
-
tokenResponse: tokenResponse2,
|
|
20140
|
-
now = Date.now()
|
|
20141
|
-
}) => {
|
|
20142
|
-
let userIdentity;
|
|
20143
|
-
let accessToken = tokenResponse2.access_token;
|
|
20144
|
-
let refreshToken = tokenResponse2.refresh_token;
|
|
20145
|
-
if (tokenResponse2.id_token) {
|
|
20146
|
-
userIdentity = normalizeProviderIdentity({
|
|
20147
|
-
identity: decodeJWT(tokenResponse2.id_token),
|
|
20148
|
-
providerConfiguration: providers[authProvider],
|
|
20149
|
-
source: "idToken"
|
|
20150
|
-
});
|
|
20151
|
-
} else if (authProvider === "withings") {
|
|
20152
|
-
userIdentity = { userid: tokenResponse2.body.userid };
|
|
20153
|
-
accessToken = tokenResponse2.body.access_token;
|
|
20154
|
-
refreshToken = tokenResponse2.body.refresh_token;
|
|
20155
|
-
} else {
|
|
20156
|
-
userIdentity = normalizeProviderIdentity({
|
|
20157
|
-
identity: await providerInstance.fetchUserProfile(tokenResponse2.access_token),
|
|
20158
|
-
providerConfiguration: providers[authProvider],
|
|
20159
|
-
source: "profile"
|
|
20160
|
-
});
|
|
20161
|
-
}
|
|
20162
|
-
const tokenType = Reflect.get(tokenResponse2, "token_type");
|
|
20163
|
-
return {
|
|
20164
|
-
accessToken,
|
|
20165
|
-
expiresAt: resolveOAuthTokenExpiresAt(tokenResponse2, now),
|
|
20166
|
-
refreshToken,
|
|
20167
|
-
tokenType: typeof tokenType === "string" ? tokenType : undefined,
|
|
20168
|
-
userIdentity
|
|
20169
|
-
};
|
|
20170
|
-
};
|
|
20171
|
-
var parseExpiresInSeconds2 = (expiresIn) => {
|
|
20172
|
-
if (typeof expiresIn === "number") {
|
|
20173
|
-
return expiresIn;
|
|
20174
|
-
}
|
|
20175
|
-
if (typeof expiresIn === "string" && expiresIn.trim().length > 0) {
|
|
20176
|
-
return Number(expiresIn);
|
|
20177
|
-
}
|
|
20178
|
-
return Number.NaN;
|
|
20179
|
-
};
|
|
20180
|
-
var resolveOAuthTokenExpiresAt = (tokenResponse2, now = Date.now()) => {
|
|
20181
|
-
const expiresIn = Reflect.get(tokenResponse2, "expires_in");
|
|
20182
|
-
const expiresInSeconds = parseExpiresInSeconds2(expiresIn);
|
|
20183
|
-
if (!Number.isFinite(expiresInSeconds) || expiresInSeconds <= 0) {
|
|
20184
|
-
return;
|
|
20185
|
-
}
|
|
20186
|
-
return now + expiresInSeconds * 1000;
|
|
20187
|
-
};
|
|
20188
|
-
var validateSession = ({
|
|
20189
|
-
user_session_id,
|
|
20190
|
-
session
|
|
20191
|
-
}) => {
|
|
20192
|
-
const userSessionId = user_session_id.value;
|
|
20193
|
-
if (!userSessionId) {
|
|
20194
|
-
return;
|
|
20195
|
-
}
|
|
20196
|
-
const userSession = session[userSessionId];
|
|
20197
|
-
if (!userSession) {
|
|
20198
|
-
return;
|
|
20199
|
-
}
|
|
20200
|
-
const isExpired2 = userSession.expiresAt < Date.now();
|
|
20201
|
-
if (isExpired2) {
|
|
20202
|
-
delete session[userSessionId];
|
|
20203
|
-
user_session_id.remove();
|
|
20204
|
-
return;
|
|
20205
|
-
}
|
|
20206
|
-
return userSession;
|
|
20207
|
-
};
|
|
20208
|
-
var clearExistingSession = (existingId, session, unregisteredSession) => {
|
|
20209
|
-
if (session)
|
|
20210
|
-
delete session[existingId];
|
|
20211
|
-
if (unregisteredSession)
|
|
20212
|
-
delete unregisteredSession[existingId];
|
|
20213
|
-
};
|
|
20214
|
-
var getUserSessionId = ({
|
|
20215
|
-
user_session_id,
|
|
20216
|
-
session,
|
|
20217
|
-
unregisteredSession
|
|
20218
|
-
}) => {
|
|
20219
|
-
const existingId = user_session_id?.value;
|
|
20220
|
-
if (isNonEmptyString(existingId)) {
|
|
20221
|
-
clearExistingSession(existingId, session, unregisteredSession);
|
|
20222
|
-
}
|
|
20223
|
-
const userSessionId = crypto.randomUUID();
|
|
20224
|
-
user_session_id.set({
|
|
20225
|
-
httpOnly: true,
|
|
20226
|
-
sameSite: "lax",
|
|
20227
|
-
secure: true,
|
|
20228
|
-
value: userSessionId
|
|
20229
|
-
});
|
|
20230
|
-
return userSessionId;
|
|
20231
|
-
};
|
|
20232
20261
|
// src/tenancy.ts
|
|
20233
20262
|
var hasOrganizationScope = (value) => typeof value.organizationId === "string" && value.organizationId.length > 0;
|
|
20234
20263
|
// src/credentials/emailValidation.ts
|
|
@@ -23342,6 +23371,7 @@ var createPostgresSetupSessionStore = (db) => ({
|
|
|
23342
23371
|
var auth = async ({
|
|
23343
23372
|
providersConfiguration,
|
|
23344
23373
|
authorizeRoute,
|
|
23374
|
+
cookieSecure,
|
|
23345
23375
|
callbackRoute,
|
|
23346
23376
|
profileRoute,
|
|
23347
23377
|
signoutRoute,
|
|
@@ -23389,6 +23419,7 @@ var auth = async ({
|
|
|
23389
23419
|
onSessionCleanup
|
|
23390
23420
|
}) => {
|
|
23391
23421
|
const clientProviders = await buildClientProviders(providersConfiguration, createOAuth2Client);
|
|
23422
|
+
const resolvedCookieSecure = resolveCookieSecure(cookieSecure);
|
|
23392
23423
|
const webhookDispatch = webhooks ? createWebhookDispatcher(webhooks) : undefined;
|
|
23393
23424
|
const auditEmit = audit || webhookDispatch ? createAuditEmitter({
|
|
23394
23425
|
...audit,
|
|
@@ -23432,6 +23463,7 @@ var auth = async ({
|
|
|
23432
23463
|
})).use(authorize({
|
|
23433
23464
|
authorizeRoute,
|
|
23434
23465
|
clientProviders,
|
|
23466
|
+
cookieSecure: resolvedCookieSecure,
|
|
23435
23467
|
onAuthorizeError,
|
|
23436
23468
|
onAuthorizeSuccess
|
|
23437
23469
|
})).use(callback({
|
|
@@ -23452,14 +23484,25 @@ var auth = async ({
|
|
|
23452
23484
|
})).use(auditedCredentials ? credentialRoutes({
|
|
23453
23485
|
...auditedCredentials,
|
|
23454
23486
|
authSessionStore,
|
|
23487
|
+
cookieSecure: resolvedCookieSecure,
|
|
23455
23488
|
lockoutGuard
|
|
23456
|
-
}) : new Elysia36).use(auditedMfa ? mfaRoutes({
|
|
23489
|
+
}) : new Elysia36).use(auditedMfa ? mfaRoutes({
|
|
23490
|
+
...auditedMfa,
|
|
23491
|
+
authSessionStore,
|
|
23492
|
+
cookieSecure: resolvedCookieSecure
|
|
23493
|
+
}) : new Elysia36).use(passwordless ? passwordlessRoutes({
|
|
23457
23494
|
...passwordless,
|
|
23458
23495
|
authSessionStore,
|
|
23496
|
+
cookieSecure: resolvedCookieSecure,
|
|
23459
23497
|
emit: auditEmit
|
|
23460
|
-
}) : new Elysia36).use(sessions ? sessionRoutes({ ...sessions, authSessionStore }) : new Elysia36).use(sso ? oidcSsoRoutes({
|
|
23498
|
+
}) : new Elysia36).use(sessions ? sessionRoutes({ ...sessions, authSessionStore }) : new Elysia36).use(sso ? oidcSsoRoutes({
|
|
23499
|
+
...sso,
|
|
23500
|
+
authSessionStore,
|
|
23501
|
+
cookieSecure: resolvedCookieSecure
|
|
23502
|
+
}) : new Elysia36).use(sso && sso.samlAdapter ? samlSsoRoutes({
|
|
23461
23503
|
...sso,
|
|
23462
23504
|
authSessionStore,
|
|
23505
|
+
cookieSecure: resolvedCookieSecure,
|
|
23463
23506
|
samlAdapter: sso.samlAdapter
|
|
23464
23507
|
}) : new Elysia36).use(sso && sso.getOrganizationByEmailDomain ? ssoDiscoveryRoute({
|
|
23465
23508
|
getOrganizationByEmailDomain: sso.getOrganizationByEmailDomain,
|
|
@@ -23476,6 +23519,7 @@ var auth = async ({
|
|
|
23476
23519
|
}) : new Elysia36).use(portal ? portalRoutes({ ...portal, emit: auditEmit }) : new Elysia36).use(webauthn ? webauthnRoutes({
|
|
23477
23520
|
...webauthn,
|
|
23478
23521
|
authSessionStore,
|
|
23522
|
+
cookieSecure: resolvedCookieSecure,
|
|
23479
23523
|
emit: auditEmit
|
|
23480
23524
|
}) : new Elysia36).use(compliance ? complianceRoutes({
|
|
23481
23525
|
...compliance,
|
|
@@ -23556,6 +23600,7 @@ export {
|
|
|
23556
23600
|
resolvePermissions,
|
|
23557
23601
|
resolveOAuthTokenExpiresAt,
|
|
23558
23602
|
resolveOAuthAuthorization,
|
|
23603
|
+
resolveCookieSecure,
|
|
23559
23604
|
resolveClientProviderEntry,
|
|
23560
23605
|
resolveAuthHtmxRenderers,
|
|
23561
23606
|
resolveApiPrincipal,
|
|
@@ -23856,5 +23901,5 @@ export {
|
|
|
23856
23901
|
AuthIdentityConflictError
|
|
23857
23902
|
};
|
|
23858
23903
|
|
|
23859
|
-
//# debugId=
|
|
23904
|
+
//# debugId=334E206D4FA9C2DF64756E2164756E21
|
|
23860
23905
|
//# sourceMappingURL=index.js.map
|