/* * SPDX-FileCopyrightText: syuilo and misskey-project * SPDX-License-Identifier: AGPL-3.0-only */ /** * Basic OAuth tests to make sure the library is correctly integrated to Misskey * and not regressed by version updates or potential migration to another library. */ process.env.NODE_ENV = 'test'; import * as assert from 'assert'; import { AuthorizationCode, type AuthorizationTokenConfig, ClientCredentials, ModuleOptions, ResourceOwnerPassword, } from 'simple-oauth2'; import pkceChallenge from 'pkce-challenge'; import * as htmlParser from 'node-html-parser'; import Fastify, { type FastifyInstance, type FastifyReply } from 'fastify'; import { api, port, sendEnvUpdateRequest, signup } from '../utils.js'; import type * as misskey from 'misskey-js'; const host = `http://127.0.0.1:${port}`; const clientPort = port + 1; const redirect_uri = `http://127.0.0.1:${clientPort}/redirect`; const basicAuthParams: AuthorizationParamsExtended = { redirect_uri, scope: 'write:notes', state: 'state', code_challenge: 'code', code_challenge_method: 'S256', }; interface AuthorizationParamsExtended { redirect_uri: string; scope: string | string[]; state: string; code_challenge?: string; code_challenge_method?: string; } interface AuthorizationTokenConfigExtended extends AuthorizationTokenConfig { code_verifier: string | undefined; } interface GetTokenError { data: { payload: { error: string; } } } const clientConfig: ModuleOptions<'client_id'> = { client: { id: `http://127.0.0.1:${clientPort}/`, secret: '', }, auth: { tokenHost: host, tokenPath: '/oauth/token', authorizePath: '/oauth/authorize', }, options: { authorizationMethod: 'body', }, }; function getMeta(html: string): { transactionId: string | undefined, clientName: string | undefined, clientLogo: string | undefined } { const doc = htmlParser.parse(`