mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-20 07:49:57 +00:00
25 lines
641 B
TypeScript
25 lines
641 B
TypeScript
import { stringifyQuery } from 'ufo'
|
|
import { getApp, getRedirectURI } from '~/server/shared'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { server } = getRouterParams(event)
|
|
const app = await getApp(server)
|
|
|
|
if (!app) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: `App not registered for server: ${server}`,
|
|
})
|
|
}
|
|
|
|
const query = stringifyQuery({
|
|
client_id: app.client_id,
|
|
scope: 'read write follow push',
|
|
redirect_uri: getRedirectURI(server),
|
|
response_type: 'code',
|
|
})
|
|
const url = `https://${server}/oauth/authorize?${query}`
|
|
|
|
await sendRedirect(event, url, 302)
|
|
})
|