[mastodon-client] Fix scopes parsing error in auth helper

This commit is contained in:
Laura Hausmann 2023-10-14 00:58:54 +02:00
parent 693916b2f6
commit d049de2935
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -50,7 +50,7 @@ export class AuthHelpers {
if (!user) throw new MastoApiError(401, "Unauthorized"); if (!user) throw new MastoApiError(401, "Unauthorized");
const body = ctx.request.body as any; const body = ctx.request.body as any;
const scopes = body.scopes as string[]; const scopes = (typeof body.scopes === "string" ? body.scopes.split(' ') : body.scopes) ?? ['read'];
const clientId = toSingleLast(body.client_id); const clientId = toSingleLast(body.client_id);
if (clientId == null) throw new MastoApiError(400, "Invalid client_id"); if (clientId == null) throw new MastoApiError(400, "Invalid client_id");
@ -92,7 +92,7 @@ export class AuthHelpers {
public static async getAuthToken(ctx: MastoContext) { public static async getAuthToken(ctx: MastoContext) {
const body: any = ctx.request.body || ctx.request.query; const body: any = ctx.request.body || ctx.request.query;
const scopes = body.scopes as string[] ?? ['read']; const scopes = (typeof body.scopes === "string" ? body.scopes.split(' ') : body.scopes) ?? ['read'];
const clientId = toSingleLast(body.client_id); const clientId = toSingleLast(body.client_id);
const code = toSingleLast(body.code); const code = toSingleLast(body.code);