mirror of
https://github.com/elk-zone/elk.git
synced 2024-09-06 12:19:08 +01:00
27 lines
668 B
TypeScript
27 lines
668 B
TypeScript
import { stringifyQuery } from 'ufo'
|
|
import { getApp } from '~/server/shared'
|
|
import { HOST_DOMAIN } from '~/constants'
|
|
|
|
export default defineEventHandler(async ({ context, res }) => {
|
|
const server = context.params.server
|
|
const app = await getApp(server)
|
|
|
|
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()
|
|
})
|