diff --git a/src/api/oauth.ts b/src/api/oauth.ts new file mode 100644 index 00000000..fa3dbacb --- /dev/null +++ b/src/api/oauth.ts @@ -0,0 +1,22 @@ +import { validator, z } from '@/deps.ts'; + +const createTokenSchema = z.object({ + password: z.string(), +}); + +const createTokenController = validator('json', (value, c) => { + const result = createTokenSchema.safeParse(value); + + if (result.success) { + return c.json({ + access_token: result.data.password, + token_type: 'Bearer', + scope: 'read write follow push', + created_at: Math.floor(new Date().getTime() / 1000), + }); + } else { + return c.json({ error: 'Invalid request' }, 400); + } +}); + +export { createTokenController }; diff --git a/src/app.ts b/src/app.ts index c183f555..3093f3ec 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,8 @@ import { Hono } from '@/deps.ts'; -import { appVerifyCredentials, createAppController } from './api/apps.ts'; +import { appVerifyCredentials, createAppController } from './api/apps.ts'; import instanceController from './api/instance.ts'; +import { createTokenController } from './api/oauth.ts'; const app = new Hono(); @@ -10,4 +11,6 @@ app.get('/api/v1/instance', instanceController); app.get('/api/v1/apps/verify_credentials', appVerifyCredentials); app.post('/api/v1/apps', createAppController); +app.post('/oauth/token', createTokenController); + export default app; diff --git a/src/deps.ts b/src/deps.ts index 0925d11f..f8f4a098 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -1,3 +1,4 @@ -import { Context, Hono } from 'https://deno.land/x/hono@v3.0.2/mod.ts'; -export { Hono }; +import { Context, Hono, validator } from 'https://deno.land/x/hono@v3.0.2/mod.ts'; +export { Hono, validator }; +export { z } from 'https://deno.land/x/zod@v3.20.5/mod.ts'; export type { Context };