2022-11-15 15:29:46 +01:00
|
|
|
import { stringifyQuery } from 'ufo'
|
2022-11-25 17:57:29 +01:00
|
|
|
import { HOST_DOMAIN, getApp } from '~/server/shared'
|
2022-11-15 15:29:46 +01:00
|
|
|
|
|
|
|
export default defineEventHandler(async ({ context, res }) => {
|
|
|
|
const server = context.params.server
|
2022-11-25 17:57:29 +01:00
|
|
|
const app = await getApp(HOST_DOMAIN, server)
|
2022-11-15 15:29:46 +01:00
|
|
|
|
|
|
|
if (!app) {
|
|
|
|
res.statusCode = 400
|
|
|
|
return `App not registered for server: ${server}`
|
|
|
|
}
|
|
|
|
|
|
|
|
const query = stringifyQuery({
|
|
|
|
client_id: app.client_id,
|
|
|
|
scope: 'read write follow push',
|
|
|
|
redirect_uri: `${HOST_DOMAIN}/api/${server}/oauth`,
|
|
|
|
response_type: 'code',
|
|
|
|
})
|
|
|
|
const url = `https://${server}/oauth/authorize?${query}`
|
|
|
|
|
|
|
|
res.writeHead(302, {
|
|
|
|
Location: url,
|
|
|
|
})
|
|
|
|
res.end()
|
|
|
|
})
|