2022-11-15 14:29:46 +00:00
|
|
|
import { stringifyQuery } from 'ufo'
|
2022-11-27 18:44:19 +00:00
|
|
|
import { HOST_URL, getApp } from '~/server/shared'
|
2022-11-15 14:29:46 +00:00
|
|
|
|
2022-11-26 17:56:35 +00:00
|
|
|
export default defineEventHandler(async (event) => {
|
|
|
|
const server = event.context.params.server
|
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-27 18:07:06 +00:00
|
|
|
event.node.res.statusCode = 400
|
2022-11-15 14:29:46 +00:00
|
|
|
return `App not registered for server: ${server}`
|
|
|
|
}
|
|
|
|
|
|
|
|
const query = stringifyQuery({
|
|
|
|
client_id: app.client_id,
|
|
|
|
scope: 'read write follow push',
|
2022-11-27 18:22:39 +00:00
|
|
|
redirect_uri: `${HOST_URL}/api/${server}/oauth`,
|
2022-11-15 14:29:46 +00:00
|
|
|
response_type: 'code',
|
|
|
|
})
|
|
|
|
const url = `https://${server}/oauth/authorize?${query}`
|
|
|
|
|
2022-11-26 17:56:35 +00:00
|
|
|
await sendRedirect(event, url, 302)
|
2022-11-15 14:29:46 +00:00
|
|
|
})
|