mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
refactor(database): 🚚 Rename Application to Client everywhere
This commit is contained in:
parent
6f97903f3b
commit
1a0a27bee1
25 changed files with 2549 additions and 90 deletions
|
|
@ -69,7 +69,7 @@ export default apiRoute((app) => {
|
|||
const flow = await db.query.OpenIdLoginFlows.findFirst({
|
||||
where: (flow): SQL | undefined => eq(flow.id, flowId),
|
||||
with: {
|
||||
application: true,
|
||||
client: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -129,11 +129,11 @@ export default apiRoute((app) => {
|
|||
// If linking account
|
||||
if (link && user_id) {
|
||||
// Check if userId is equal to application.clientId
|
||||
if (!flow.application?.id.startsWith(user_id)) {
|
||||
if (!flow.client?.id.startsWith(user_id)) {
|
||||
return redirectWithMessage(
|
||||
{
|
||||
oidc_account_linking_error: "Account linking error",
|
||||
oidc_account_linking_error_message: `User ID does not match application client ID (${user_id} != ${flow.application?.id})`,
|
||||
oidc_account_linking_error_message: `User ID does not match application client ID (${user_id} != ${flow.client?.id})`,
|
||||
},
|
||||
config.frontend.routes.home,
|
||||
);
|
||||
|
|
@ -262,14 +262,14 @@ export default apiRoute((app) => {
|
|||
});
|
||||
}
|
||||
|
||||
if (!flow.application) {
|
||||
if (!flow.client) {
|
||||
throw new ApiError(500, "Application not found");
|
||||
}
|
||||
|
||||
const code = randomString(32, "hex");
|
||||
|
||||
await db.insert(AuthorizationCodes).values({
|
||||
clientId: flow.application.id,
|
||||
clientId: flow.client.id,
|
||||
code,
|
||||
expiresAt: new Date(Date.now() + 60 * 1000).toISOString(), // 1 minute
|
||||
redirectUri: flow.clientRedirectUri ?? undefined,
|
||||
|
|
@ -281,7 +281,7 @@ export default apiRoute((app) => {
|
|||
{
|
||||
sub: user.id,
|
||||
iss: new URL(context.get("config").http.base_url).origin,
|
||||
aud: flow.application.id,
|
||||
aud: flow.client.id,
|
||||
exp: Math.floor(Date.now() / 1000) + 60 * 60,
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
nbf: Math.floor(Date.now() / 1000),
|
||||
|
|
@ -303,9 +303,9 @@ export default apiRoute((app) => {
|
|||
{
|
||||
redirect_uri: flow.clientRedirectUri ?? undefined,
|
||||
code,
|
||||
client_id: flow.application.id,
|
||||
application: flow.application.name,
|
||||
website: flow.application.website ?? "",
|
||||
client_id: flow.client.id,
|
||||
application: flow.client.name,
|
||||
website: flow.client.website ?? "",
|
||||
scope: flow.clientScopes?.join(" "),
|
||||
state: flow.clientState ?? undefined,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { config } from "@versia-server/config";
|
||||
import { ApiError } from "@versia-server/kit";
|
||||
import { apiRoute, handleZodError } from "@versia-server/kit/api";
|
||||
import { Application, db } from "@versia-server/kit/db";
|
||||
import { Client, db } from "@versia-server/kit/db";
|
||||
import { OpenIdLoginFlows } from "@versia-server/kit/tables";
|
||||
import { randomUUIDv7 } from "bun";
|
||||
import { describeRoute, validator } from "hono-openapi";
|
||||
|
|
@ -54,7 +54,7 @@ export default apiRoute((app) => {
|
|||
throw new ApiError(422, "Unknown or invalid issuer");
|
||||
}
|
||||
|
||||
const application = await Application.fromClientId(client_id);
|
||||
const application = await Client.fromClientId(client_id);
|
||||
|
||||
if (!application) {
|
||||
throw new ApiError(422, "Unknown or invalid client_id");
|
||||
|
|
@ -98,7 +98,7 @@ export default apiRoute((app) => {
|
|||
clientState: state,
|
||||
clientRedirectUri: redirect_uri,
|
||||
clientScopes: scopes,
|
||||
applicationId: application.id,
|
||||
clientId: application.id,
|
||||
issuerId,
|
||||
})
|
||||
.returning()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue