upd: add oauth decision endpoint

This commit is contained in:
Mar0xy 2023-11-08 21:11:54 +01:00
parent 82f8d79c92
commit 88da6f16a9
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828

View file

@ -3,9 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import querystring from 'querystring';
import { Inject, Injectable } from '@nestjs/common';
import megalodon, { MegalodonInterface } from 'megalodon';
import querystring from 'querystring';
import { v4 as uuid } from 'uuid';
/* import { kinds } from '@/misc/api-permissions.js';
import type { Config } from '@/config.js';
@ -74,10 +74,18 @@ export class OAuth2ProviderService {
if (query.redirect_uri) param += `&redirect_uri=${query.redirect_uri}`;
const client = query.client_id ? query.client_id : "";
reply.redirect(
`${atob(client)}?${param}`,
`${Buffer.from(client.toString(), 'base64').toString()}?${param}`,
);
});
fastify.post('/oauth/decision', async (request, reply) => {
const body: any = request.body;
if (body.cancel) {
reply.send({ user: body.login_token, allow: false });
}
reply.send({ user: body.login_token, allow: true });
});
fastify.post('/oauth/token', async (request, reply) => {
const body: any = request.body || request.query;
if (body.grant_type === "client_credentials") {