Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid_client (401 unauthorized) error coming while migrating to new client credential api #339

Open
kejul-vyas-mck opened this issue Oct 23, 2024 · 10 comments
Labels
credentials question Further information is requested

Comments

@kejul-vyas-mck
Copy link

Title: Invalid_Client (401 Unauthorized) error coming from https://secure.soundcloud.com/oauth/token API

Issue found of: Oct 23th, 2024

Endpoint(s):

  • POST https://secure.soundcloud.com/oauth/token

Scope(s):

application is uses client_credentials workflow for authentication

Steps to reproduce:

curl --location 'https://secure.soundcloud.com/oauth/token' \
--header 'accept: application/json; charset=utf-8' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Authorization: Basic Base64(client_id:client_secret)' \
--data-urlencode 'grant_type=client_credentials'

Expected behaviour:

It should return access_token, refresh_token along with other parameters as per the documentation here - https://developers.soundcloud.com/docs/api/guide#client-creds

Actual behaviour:

401 Unauthorized error

@youssefhassan
Copy link

Hey @kejul-vyas-mck, my suspicion would be around whether the Base64 is done properly, it can be confusing.

The Base64 encoded string of "my_client_id:my_client_secret" is "bXlfY2xpZW50X2lkOm15X2NsaWVudF9zZWNyZXQ="

Please let us know if this was the issue or otherwise we are happy to assist further.

@youssefhassan youssefhassan added the question Further information is requested label Oct 24, 2024
@kejul-vyas-mck
Copy link
Author

kejul-vyas-mck commented Oct 24, 2024

Thank you @youssefhassan for looking into this. The Base64 encoded string was able to resolve the issue and it generated the access_token and refresh_token.

However, when I am calling the upload track api (https://api.soundcloud.com/tracks) with the generated access_token, I am unable to upload the audio. It gives Unauthorized 401 error.

image

Upload track api request I followed from the documentation - https://developers.soundcloud.com/docs/api/guide#uploading-files
image

@youssefhassan
Copy link

Can you please share your soundcloud username and application name so I can debug the issue?
thanks for reporting :)

@youssefhassan
Copy link

I deleted the message as it had the client id that can be misused, I will look into the issue soon. From the configuration, it looks that with a valid token, you should be able to make requests to the public api. Is it only giving 401 on track uploads or other endpoints as well?

@mgoodfellow
Copy link

Hi,

It seems like you are requesting a client_credential grant - this doesn't have a user context associated with it and it can only be used for GET operations on "public" endpoints, such as /tracks or /track/{id} etc.

In order to make mutations to user data, you need to go through the OAuth connect flow and authorize a specific user context against your app via the connect with soundcloud web flow. Then you can make requests to user context endpoints (/me) and also perform mutations, such as uploading/editing tracks/playlists etc with the OAuth token generated from this.

https://developers.soundcloud.com/docs/api/guide#authentication

You are looking for the Authorization Code Flow, not the Client Credentials Token Exchange Flow

Hope this helps!

@kejul-vyas-mck
Copy link
Author

@mgoodfellow The Authentication workflow works now with @youssefhassan's given solution (needed to encrypt the clientid:clientsecret to base64 encoded string).

@youssefhassan the access_token isn't working with any of the SoundCloud api. I tried checking below api to get list of tracks uploaded -
image

@youssefhassan
Copy link

This shouldn't be the case, I'm thinking if the token could have been expired or the client credentials were revoked. Can you please let us know which user the app is attached to and the name of the app?

@kejul-vyas-mck
Copy link
Author

kejul-vyas-mck commented Oct 30, 2024

@youssefhassan I have always used unexpired tokens. Also, the client credentials and upload tracks API work perfectly fine with the generated access_token from the old URL https://api.soundcloud.com/oauth2/token Only the access_token generated from the new API URL - https://secure.soundcloud.com/oauth/token doesn't work

please find the user and app details below:
user email id - [email protected]
name of the app - https://soundcloud.com/mckinsey

@kejul-vyas-mck
Copy link
Author

@youssefhassan, are there any findings from your end?

@kejul-vyas-mck
Copy link
Author

@youssefhassan following up on this issue - do we have any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
credentials question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants