parse client id

This commit is contained in:
cutestnekoaqua 2023-02-11 01:17:35 +01:00
parent 12e1e676fa
commit 31e0ac1ee8
No known key found for this signature in database
GPG Key ID: 6BF0964A5069C1E0
1 changed files with 8 additions and 2 deletions

View File

@ -148,6 +148,7 @@ mastoRouter.get("/oauth/authorize", async (ctx) => {
mastoRouter.post("/oauth/token", async (ctx) => { mastoRouter.post("/oauth/token", async (ctx) => {
const body: any = ctx.request.body; const body: any = ctx.request.body;
let client_id: any = ctx.request.query.client_id;
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`; const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
const generator = (megalodon as any).default; const generator = (megalodon as any).default;
const client = generator("misskey", BASE_URL, null) as MegalodonInterface; const client = generator("misskey", BASE_URL, null) as MegalodonInterface;
@ -159,11 +160,16 @@ mastoRouter.post("/oauth/token", async (ctx) => {
return; return;
} }
} }
if (client_id instanceof Array) {
client_id = client_id.toString();;
} else if (!client_id) {
client_id = null;
}
try { try {
const atData = await client.fetchAccessToken( const atData = await client.fetchAccessToken(
null, client_id,
body.client_secret, body.client_secret,
m ? m[0] : null, m ? m[0] : '',
); );
ctx.body = { ctx.body = {
access_token: atData.accessToken, access_token: atData.accessToken,