wip: oauth
This commit is contained in:
parent
0dac7b9785
commit
72b13f5265
7 changed files with 115 additions and 4 deletions
26
server/api/[server]/login.ts
Normal file
26
server/api/[server]/login.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
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()
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue