Add OAuth controller
This commit is contained in:
parent
8ed662321d
commit
b36b8ea7d2
|
@ -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 };
|
|
@ -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;
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Reference in New Issue