From 2732ce2bdb96392ddf2645d0e67bd08323b3ab26 Mon Sep 17 00:00:00 2001 From: Juan Alvarado Date: Tue, 3 Sep 2024 23:24:08 -0400 Subject: [PATCH] Fix auth endpoint --- src/server/crosscutting/soundCloudApiClient.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/server/crosscutting/soundCloudApiClient.ts b/src/server/crosscutting/soundCloudApiClient.ts index a2fc48a..b2423c8 100644 --- a/src/server/crosscutting/soundCloudApiClient.ts +++ b/src/server/crosscutting/soundCloudApiClient.ts @@ -1,4 +1,5 @@ import axios, { AxiosInstance, AxiosResponse } from "axios"; +import { Buffer } from "buffer"; const SOUNDCLOUD_CLIENT_ID = process.env.SOUNDCLOUD_CLIENT_ID || "no_sound_client_id_read"; @@ -28,9 +29,21 @@ export class SoundCloudApiClient { } async getToken() { - const res = await this.client + const credentials = `${SOUNDCLOUD_CLIENT_ID}:${SOUNDCLOUD_CLIENT_SECRET}`; + const encodedCredentials = Buffer.from(credentials).toString("base64"); + + const res = await axios .post<{ access_token: string }>( - `/oauth2/token?client_id=${SOUNDCLOUD_CLIENT_ID}&client_secret=${SOUNDCLOUD_CLIENT_SECRET}&grant_type=client_credentials` + "https://secure.soundcloud.com/oauth/token", + new URLSearchParams({ + grant_type: "client_credentials", + }), + { + headers: { + "Content-Type": "application/x-www-form-urlencoded", + Authorization: `Basic ${encodedCredentials}`, + }, + } ) .then(this._data);