2022-11-15 15:29:46 +01:00
|
|
|
import { stringifyQuery } from 'ufo'
|
|
|
|
|
2022-11-26 18:56:35 +01:00
|
|
|
export default defineEventHandler(async (event) => {
|
2022-12-24 01:51:45 +01:00
|
|
|
let { server } = getRouterParams(event)
|
2023-01-13 19:10:51 +01:00
|
|
|
const { origin, force_login, lang } = await readBody(event)
|
2022-12-24 01:51:45 +01:00
|
|
|
server = server.toLocaleLowerCase().trim()
|
2023-01-01 20:30:39 +01:00
|
|
|
const app = await getApp(origin, server)
|
2022-11-15 15:29:46 +01:00
|
|
|
|
|
|
|
if (!app) {
|
2022-11-29 23:55:53 +01:00
|
|
|
throw createError({
|
|
|
|
statusCode: 400,
|
|
|
|
statusMessage: `App not registered for server: ${server}`,
|
|
|
|
})
|
2022-11-15 15:29:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const query = stringifyQuery({
|
|
|
|
client_id: app.client_id,
|
2023-01-13 19:08:15 +01:00
|
|
|
force_login: force_login === true ? 'true' : 'false',
|
2022-11-15 15:29:46 +01:00
|
|
|
scope: 'read write follow push',
|
2023-01-01 20:30:39 +01:00
|
|
|
redirect_uri: getRedirectURI(origin, server),
|
2022-11-15 15:29:46 +01:00
|
|
|
response_type: 'code',
|
2023-01-13 19:10:51 +01:00
|
|
|
lang,
|
2022-11-15 15:29:46 +01:00
|
|
|
})
|
|
|
|
|
2022-12-14 00:12:16 +01:00
|
|
|
return `https://${server}/oauth/authorize?${query}`
|
2022-11-15 15:29:46 +01:00
|
|
|
})
|