mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
fix(plugin): 🐛 Don't incorrectly call errorSearchParams before initialization in callback
This commit is contained in:
parent
a265e9df41
commit
d000914f61
|
|
@ -91,7 +91,19 @@ export default (plugin: PluginType) => {
|
||||||
flowId,
|
flowId,
|
||||||
currentUrl,
|
currentUrl,
|
||||||
redirectUrl,
|
redirectUrl,
|
||||||
(error, message) => {
|
(error, message, flow) => {
|
||||||
|
const errorSearchParams = new URLSearchParams(
|
||||||
|
Object.entries({
|
||||||
|
redirect_uri: flow?.application?.redirectUri,
|
||||||
|
client_id: flow?.application?.clientId,
|
||||||
|
response_type: "code",
|
||||||
|
scope: flow?.application?.scopes,
|
||||||
|
}).filter(([_, value]) => value !== undefined) as [
|
||||||
|
string,
|
||||||
|
string,
|
||||||
|
][],
|
||||||
|
);
|
||||||
|
|
||||||
errorSearchParams.append("error", error);
|
errorSearchParams.append("error", error);
|
||||||
errorSearchParams.append("error_description", message);
|
errorSearchParams.append("error_description", message);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
import { db } from "@versia/kit/db";
|
import { db } from "@versia/kit/db";
|
||||||
|
import type { InferSelectModel } from "@versia/kit/drizzle";
|
||||||
|
import type { Applications, OpenIdLoginFlows } from "@versia/kit/tables";
|
||||||
import {
|
import {
|
||||||
type AuthorizationResponseError,
|
type AuthorizationResponseError,
|
||||||
type AuthorizationServer,
|
type AuthorizationServer,
|
||||||
|
|
@ -15,7 +17,6 @@ import {
|
||||||
userInfoRequest,
|
userInfoRequest,
|
||||||
validateAuthResponse,
|
validateAuthResponse,
|
||||||
} from "oauth4webapi";
|
} from "oauth4webapi";
|
||||||
import type { Application } from "~/classes/functions/application";
|
|
||||||
|
|
||||||
export const oauthDiscoveryRequest = (
|
export const oauthDiscoveryRequest = (
|
||||||
issuerUrl: string | URL,
|
issuerUrl: string | URL,
|
||||||
|
|
@ -131,7 +132,11 @@ export const automaticOidcFlow = async (
|
||||||
errorFn: (
|
errorFn: (
|
||||||
error: string,
|
error: string,
|
||||||
message: string,
|
message: string,
|
||||||
app: Application | null,
|
flow:
|
||||||
|
| (InferSelectModel<typeof OpenIdLoginFlows> & {
|
||||||
|
application?: InferSelectModel<typeof Applications> | null;
|
||||||
|
})
|
||||||
|
| null,
|
||||||
) => Response,
|
) => Response,
|
||||||
) => {
|
) => {
|
||||||
const flow = await getFlow(flowId);
|
const flow = await getFlow(flowId);
|
||||||
|
|
@ -171,11 +176,7 @@ export const automaticOidcFlow = async (
|
||||||
const claims = getValidatedIdTokenClaims(result);
|
const claims = getValidatedIdTokenClaims(result);
|
||||||
|
|
||||||
if (!claims) {
|
if (!claims) {
|
||||||
return errorFn(
|
return errorFn("invalid_request", "Invalid claims", flow);
|
||||||
"invalid_request",
|
|
||||||
"Invalid claims",
|
|
||||||
flow.application,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { sub } = claims;
|
const { sub } = claims;
|
||||||
|
|
@ -196,10 +197,6 @@ export const automaticOidcFlow = async (
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = e as ResponseBodyError | AuthorizationResponseError;
|
const error = e as ResponseBodyError | AuthorizationResponseError;
|
||||||
return errorFn(
|
return errorFn(error.error, error.error_description || "", flow);
|
||||||
error.error,
|
|
||||||
error.error_description || "",
|
|
||||||
flow.application,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue