2022-11-15 14:29:46 +00:00
|
|
|
import { stringifyQuery } from 'ufo'
|
2022-12-22 02:12:37 +00:00
|
|
|
import { createError, defineEventHandler, getRouterParams } from 'h3'
|
2022-11-29 22:55:53 +00:00
|
|
|
import { getApp, getRedirectURI } from '~/server/shared'
|
2022-11-15 14:29:46 +00:00
|
|
|
|
2022-11-26 17:56:35 +00:00
|
|
|
export default defineEventHandler(async (event) => {
|
2022-12-24 00:51:45 +00:00
|
|
|
let { server } = getRouterParams(event)
|
|
|
|
server = server.toLocaleLowerCase().trim()
|
2022-11-27 18:44:19 +00:00
|
|
|
const app = await getApp(server)
|
2022-11-15 14:29:46 +00:00
|
|
|
|
|
|
|
if (!app) {
|
2022-11-29 22:55:53 +00:00
|
|
|
throw createError({
|
|
|
|
statusCode: 400,
|
|
|
|
statusMessage: `App not registered for server: ${server}`,
|
|
|
|
})
|
2022-11-15 14:29:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const query = stringifyQuery({
|
|
|
|
client_id: app.client_id,
|
|
|
|
scope: 'read write follow push',
|
2022-11-29 22:55:53 +00:00
|
|
|
redirect_uri: getRedirectURI(server),
|
2022-11-15 14:29:46 +00:00
|
|
|
response_type: 'code',
|
|
|
|
})
|
|
|
|
|
2022-12-13 23:12:16 +00:00
|
|
|
return `https://${server}/oauth/authorize?${query}`
|
2022-11-15 14:29:46 +00:00
|
|
|
})
|