mirror of
https://github.com/versia-pub/server.git
synced 2026-01-26 04:06:01 +01:00
feat(api): ✨ Add support for urn:ietf:wg:oauth:2.0:oob oauth redirect URI
This commit is contained in:
parent
e07337340d
commit
3f9ec0bc80
|
|
@ -22,7 +22,12 @@ export const meta = applyConfig({
|
||||||
export const schemas = {
|
export const schemas = {
|
||||||
form: z.object({
|
form: z.object({
|
||||||
client_name: z.string().trim().min(1).max(100),
|
client_name: z.string().trim().min(1).max(100),
|
||||||
redirect_uris: z.string().min(0).max(2000).url(),
|
redirect_uris: z
|
||||||
|
.string()
|
||||||
|
.min(0)
|
||||||
|
.max(2000)
|
||||||
|
.url()
|
||||||
|
.or(z.literal("urn:ietf:wg:oauth:2.0:oob")),
|
||||||
scopes: z.string().min(1).max(200),
|
scopes: z.string().min(1).max(200),
|
||||||
website: z.string().min(0).max(2000).url().optional(),
|
website: z.string().min(0).max(2000).url().optional(),
|
||||||
}),
|
}),
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,11 @@ export const schemas = {
|
||||||
}),
|
}),
|
||||||
form: z.object({
|
form: z.object({
|
||||||
scope: z.string().optional(),
|
scope: z.string().optional(),
|
||||||
redirect_uri: z.string().url().optional(),
|
redirect_uri: z
|
||||||
|
.string()
|
||||||
|
.url()
|
||||||
|
.optional()
|
||||||
|
.or(z.literal("urn:ietf:wg:oauth:2.0:oob")),
|
||||||
response_type: z.enum([
|
response_type: z.enum([
|
||||||
"code",
|
"code",
|
||||||
"token",
|
"token",
|
||||||
|
|
@ -178,7 +182,7 @@ export default (app: Hono) =>
|
||||||
return returnError(
|
return returnError(
|
||||||
body,
|
body,
|
||||||
"invalid_request",
|
"invalid_request",
|
||||||
"Redirect URI is required for code flow",
|
"Redirect URI is required for code flow (can be urn:ietf:wg:oauth:2.0:oob)",
|
||||||
);
|
);
|
||||||
|
|
||||||
/* if (asksCode && !code_challenge)
|
/* if (asksCode && !code_challenge)
|
||||||
|
|
@ -212,9 +216,6 @@ export default (app: Hono) =>
|
||||||
"Redirect URI does not match client_id",
|
"Redirect URI does not match client_id",
|
||||||
);
|
);
|
||||||
|
|
||||||
/* if (application.slate !== slate)
|
|
||||||
return returnError("invalid_request", "Invalid slate"); */
|
|
||||||
|
|
||||||
// Validate scopes, they can either be equal or a subset of the application's scopes
|
// Validate scopes, they can either be equal or a subset of the application's scopes
|
||||||
const applicationScopes = application.scopes.split(" ");
|
const applicationScopes = application.scopes.split(" ");
|
||||||
|
|
||||||
|
|
@ -295,14 +296,17 @@ export default (app: Hono) =>
|
||||||
});
|
});
|
||||||
|
|
||||||
// Redirect to the client
|
// Redirect to the client
|
||||||
const redirectUri = new URL(
|
const redirectUri =
|
||||||
redirect_uri ?? application.redirectUri,
|
redirect_uri === "urn:ietf:wg:oauth:2.0:oob"
|
||||||
);
|
? new URL("/oauth/code", config.http.base_url)
|
||||||
|
: new URL(redirect_uri ?? application.redirectUri);
|
||||||
|
|
||||||
const searchParams = new URLSearchParams({
|
const searchParams = new URLSearchParams({
|
||||||
code: code,
|
code: code,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (state) searchParams.append("state", state);
|
||||||
|
|
||||||
return response(null, 302, {
|
return response(null, 302, {
|
||||||
Location: `${redirectUri.origin}${
|
Location: `${redirectUri.origin}${
|
||||||
redirectUri.pathname
|
redirectUri.pathname
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue