diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2020-03-28 11:24:37 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2020-03-28 11:24:37 +0900 |
| commit | 6be127e18bdbea6031698baeb8632f917a8346eb (patch) | |
| tree | 4b7ceb082d76b0628df6496bc802172106721ce9 /src/server/api/index.ts | |
| parent | wip (diff) | |
| download | misskey-6be127e18bdbea6031698baeb8632f917a8346eb.tar.gz misskey-6be127e18bdbea6031698baeb8632f917a8346eb.tar.bz2 misskey-6be127e18bdbea6031698baeb8632f917a8346eb.zip | |
Implement MiAuth
Diffstat (limited to 'src/server/api/index.ts')
| -rw-r--r-- | src/server/api/index.ts | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/server/api/index.ts b/src/server/api/index.ts index 258e632bd8..49209ede43 100644 --- a/src/server/api/index.ts +++ b/src/server/api/index.ts @@ -15,7 +15,7 @@ import signin from './private/signin'; import discord from './service/discord'; import github from './service/github'; import twitter from './service/twitter'; -import { Instances } from '../../models'; +import { Instances, AccessTokens, Users } from '../../models'; // Init app const app = new Koa(); @@ -73,6 +73,28 @@ router.get('/v1/instance/peers', async ctx => { ctx.body = instances.map(instance => instance.host); }); +router.post('/miauth/:session/check', async ctx => { + const token = await AccessTokens.findOne({ + session: ctx.params.session + }); + + if (token && !token.fetched) { + AccessTokens.update(token.id, { + fetched: true + }); + + ctx.body = { + ok: true, + token: token.token, + user: await Users.pack(token.userId, null, { detail: true }) + }; + } else { + ctx.body = { + ok: false, + }; + } +}); + // Return 404 for unknown API router.all('*', async ctx => { ctx.status = 404; |