From dc5a6510daedcf390efb62d339c70f05719ec111 Mon Sep 17 00:00:00 2001 From: Zisu Zhang Date: Mon, 2 Sep 2024 02:16:32 +0800 Subject: [PATCH] chore: updated iaaa compat (#108) --- .yarn/versions/29701c61.yml | 2 ++ apps/server/src/routes/oauth/iaaaCompat.ts | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 .yarn/versions/29701c61.yml diff --git a/.yarn/versions/29701c61.yml b/.yarn/versions/29701c61.yml new file mode 100644 index 00000000..1a06f8be --- /dev/null +++ b/.yarn/versions/29701c61.yml @@ -0,0 +1,2 @@ +releases: + "@aoi-js/server": patch diff --git a/apps/server/src/routes/oauth/iaaaCompat.ts b/apps/server/src/routes/oauth/iaaaCompat.ts index 18182c0c..cecc5f5e 100644 --- a/apps/server/src/routes/oauth/iaaaCompat.ts +++ b/apps/server/src/routes/oauth/iaaaCompat.ts @@ -1,15 +1,37 @@ +import { fastifyFormbody } from '@fastify/formbody' import { UUID } from 'mongodb' import { T } from '../../schemas/common.js' import { defineRoutes, md5, swaggerTagMerger } from '../common/index.js' export const oauthIaaaCompatRoutes = defineRoutes(async (s) => { + await s.register(fastifyFormbody) + const { users, apps } = s.db s.addHook('onRoute', swaggerTagMerger('iaaa-compat')) if (!Object.hasOwn(s.authProviders, 'iaaa')) return + s.get( + '/oauth.jsp', + { + schema: { + body: T.Object({ + appID: T.String(), + appName: T.String(), + redirectUrl: T.String() + }) + } + }, + async (req, rep) => { + const url = new URL('/oauth/authorize', req.originalUrl) + url.searchParams.set('client_id', req.body.appID) + url.searchParams.set('redirect_uri', req.body.redirectUrl) + return rep.redirect(307, url.toString()) + } + ) + s.get( '/svc/token/validate.do', {