@spfn/auth 0.2.0-beta.62 → 0.2.0-beta.64
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/{authenticate-DcOkuB7d.d.ts → authenticate-mfVRzeIK.d.ts} +121 -2
- package/dist/index.d.ts +33 -3
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +177 -259
- package/dist/server.js +90 -3
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -9158,7 +9158,13 @@ var userRouter = defineRouter3({
|
|
|
9158
9158
|
init_esm();
|
|
9159
9159
|
init_types();
|
|
9160
9160
|
import { Transactional as Transactional2 } from "@spfn/core/db";
|
|
9161
|
+
import { ValidationError as ValidationError4 } from "@spfn/core/errors";
|
|
9161
9162
|
import { defineRouter as defineRouter4, route as route4 } from "@spfn/core/route";
|
|
9163
|
+
var providerParams = Type.Object({
|
|
9164
|
+
provider: Type.Union(SOCIAL_PROVIDERS.map((p) => Type.Literal(p)), {
|
|
9165
|
+
description: "OAuth provider id (google, github, kakao, naver, superself)"
|
|
9166
|
+
})
|
|
9167
|
+
});
|
|
9162
9168
|
var oauthGoogleStart = route4.get("/_auth/oauth/google").input({
|
|
9163
9169
|
query: Type.Object({
|
|
9164
9170
|
state: Type.String({
|
|
@@ -9255,10 +9261,12 @@ var getGoogleOAuthUrl = route4.post("/_auth/oauth/google/url").input({
|
|
|
9255
9261
|
}).skip(["auth"]).handler(async (c) => {
|
|
9256
9262
|
const { body } = await c.data();
|
|
9257
9263
|
if (!isGoogleOAuthEnabled()) {
|
|
9258
|
-
throw new
|
|
9264
|
+
throw new ValidationError4({ message: "Google OAuth is not configured" });
|
|
9259
9265
|
}
|
|
9260
9266
|
if (!body.state) {
|
|
9261
|
-
throw new
|
|
9267
|
+
throw new ValidationError4({
|
|
9268
|
+
message: "OAuth state is required. Ensure the OAuth interceptor is configured."
|
|
9269
|
+
});
|
|
9262
9270
|
}
|
|
9263
9271
|
return { authUrl: getGoogleAuthUrl(body.state) };
|
|
9264
9272
|
});
|
|
@@ -9277,13 +9285,88 @@ var oauthFinalize = route4.post("/_auth/oauth/finalize").input({
|
|
|
9277
9285
|
returnUrl: body.returnUrl || "/"
|
|
9278
9286
|
};
|
|
9279
9287
|
});
|
|
9288
|
+
var oauthProviderStart = route4.get("/_auth/oauth/:provider").input({
|
|
9289
|
+
params: providerParams,
|
|
9290
|
+
query: Type.Object({
|
|
9291
|
+
state: Type.String({
|
|
9292
|
+
description: "Encrypted OAuth state (returnUrl, publicKey, keyId, fingerprint, algorithm)"
|
|
9293
|
+
})
|
|
9294
|
+
})
|
|
9295
|
+
}).skip(["auth"]).handler(async (c) => {
|
|
9296
|
+
const { params, query } = await c.data();
|
|
9297
|
+
const provider = getOAuthProvider(params.provider);
|
|
9298
|
+
if (!provider?.isEnabled()) {
|
|
9299
|
+
return c.redirect(buildOAuthErrorUrl(`OAuth provider '${params.provider}' is not configured`));
|
|
9300
|
+
}
|
|
9301
|
+
return c.redirect(provider.getAuthUrl(query.state));
|
|
9302
|
+
});
|
|
9303
|
+
var oauthProviderCallback = route4.get("/_auth/oauth/:provider/callback").input({
|
|
9304
|
+
params: providerParams,
|
|
9305
|
+
query: Type.Object({
|
|
9306
|
+
code: Type.Optional(Type.String({
|
|
9307
|
+
description: "Authorization code from provider"
|
|
9308
|
+
})),
|
|
9309
|
+
state: Type.Optional(Type.String({
|
|
9310
|
+
description: "OAuth state parameter"
|
|
9311
|
+
})),
|
|
9312
|
+
error: Type.Optional(Type.String({
|
|
9313
|
+
description: "Error code from provider"
|
|
9314
|
+
})),
|
|
9315
|
+
error_description: Type.Optional(Type.String({
|
|
9316
|
+
description: "Error description from provider"
|
|
9317
|
+
}))
|
|
9318
|
+
})
|
|
9319
|
+
}).use([Transactional2()]).skip(["auth"]).handler(async (c) => {
|
|
9320
|
+
const { params, query } = await c.data();
|
|
9321
|
+
if (query.error) {
|
|
9322
|
+
const errorMessage = query.error_description || query.error;
|
|
9323
|
+
return c.redirect(buildOAuthErrorUrl(errorMessage));
|
|
9324
|
+
}
|
|
9325
|
+
if (!query.code || !query.state) {
|
|
9326
|
+
return c.redirect(buildOAuthErrorUrl("Missing authorization code or state"));
|
|
9327
|
+
}
|
|
9328
|
+
try {
|
|
9329
|
+
const result = await oauthCallbackService({
|
|
9330
|
+
provider: params.provider,
|
|
9331
|
+
code: query.code,
|
|
9332
|
+
state: query.state
|
|
9333
|
+
});
|
|
9334
|
+
return c.redirect(result.redirectUrl);
|
|
9335
|
+
} catch (err) {
|
|
9336
|
+
const message = err instanceof Error ? err.message : "OAuth callback failed";
|
|
9337
|
+
return c.redirect(buildOAuthErrorUrl(message));
|
|
9338
|
+
}
|
|
9339
|
+
});
|
|
9340
|
+
var getProviderOAuthUrl = route4.post("/_auth/oauth/:provider/url").input({
|
|
9341
|
+
params: providerParams,
|
|
9342
|
+
body: Type.Object({
|
|
9343
|
+
returnUrl: Type.Optional(Type.String({
|
|
9344
|
+
description: "URL to redirect after OAuth success"
|
|
9345
|
+
})),
|
|
9346
|
+
state: Type.Optional(Type.String({
|
|
9347
|
+
description: "Encrypted OAuth state (injected by interceptor)"
|
|
9348
|
+
}))
|
|
9349
|
+
})
|
|
9350
|
+
}).skip(["auth"]).handler(async (c) => {
|
|
9351
|
+
const { params, body } = await c.data();
|
|
9352
|
+
const provider = requireEnabledProvider(params.provider);
|
|
9353
|
+
if (!body.state) {
|
|
9354
|
+
throw new ValidationError4({
|
|
9355
|
+
message: "OAuth state is required. Ensure the OAuth interceptor is configured."
|
|
9356
|
+
});
|
|
9357
|
+
}
|
|
9358
|
+
return { authUrl: provider.getAuthUrl(body.state) };
|
|
9359
|
+
});
|
|
9280
9360
|
var oauthRouter = defineRouter4({
|
|
9281
9361
|
oauthGoogleStart,
|
|
9282
9362
|
oauthGoogleCallback,
|
|
9283
9363
|
oauthStart,
|
|
9284
9364
|
oauthProviders,
|
|
9285
9365
|
getGoogleOAuthUrl,
|
|
9286
|
-
oauthFinalize
|
|
9366
|
+
oauthFinalize,
|
|
9367
|
+
oauthProviderStart,
|
|
9368
|
+
oauthProviderCallback,
|
|
9369
|
+
getProviderOAuthUrl
|
|
9287
9370
|
});
|
|
9288
9371
|
|
|
9289
9372
|
// src/server/routes/admin/index.ts
|
|
@@ -9403,6 +9486,9 @@ var mainAuthRouter = defineRouter5({
|
|
|
9403
9486
|
oauthProviders,
|
|
9404
9487
|
getGoogleOAuthUrl,
|
|
9405
9488
|
oauthFinalize,
|
|
9489
|
+
oauthProviderStart,
|
|
9490
|
+
oauthProviderCallback,
|
|
9491
|
+
getProviderOAuthUrl,
|
|
9406
9492
|
// Invitation routes
|
|
9407
9493
|
getInvitation,
|
|
9408
9494
|
acceptInvitation: acceptInvitation2,
|
|
@@ -9876,6 +9962,7 @@ export {
|
|
|
9876
9962
|
registerService,
|
|
9877
9963
|
removePermissionFromRole,
|
|
9878
9964
|
requireAnyPermission,
|
|
9965
|
+
requireEnabledProvider,
|
|
9879
9966
|
requirePermissions,
|
|
9880
9967
|
requireRole,
|
|
9881
9968
|
resendInvitation,
|