soundcloud / api

A public repo for our Developer Community to engage about bugs and feature requests on our Public API
148 stars 24 forks source link

Login with Facebook using SoundCloud web api is returning a 401 error #220

Closed bricemacias closed 2 years ago

bricemacias commented 2 years ago

Title: login with Facebook using SoundCloud web api is returning a 401 error

Issue found of: July 12th, 2022

Endpoint(s):

Steps to reproduce:

It is exactly the same issue as reported here some time ago : https://stackoverflow.com/questions/20327184/connect-to-soundcloud-api-with-facebook-account

Expected behaviour:

SoundCloud login should work with code received from url after user logs in through Facebook, as it works with normal email and password. We have the same problem with login with Google too.

Actual behaviour:

401 unauthorised error

dpreussler commented 2 years ago

@bricemacias we had login issues earlier today platform wide, can you confirm the problem still occurs?

bricemacias commented 2 years ago

Hi @dpreussler, thank you for your answer, yes I just tried with normal email and password authentication and it works fine, but when I try using Facebook login I get Request failed with status code 401

Can you confirm it's supposed to be the same implementation, meaning getting the code from the first url response after user logs in and passing it to https://api.soundcloud.com/oauth2/token with the same payload as normal email and password login ? Or should there be a special implementation on our side that we should follow for Facebook or Google (and Apple but we didn't test it yet) ?

mgoodfellow commented 2 years ago

Sounds like you are capturing the callback from Facebook to SoundCloud and trying to use that code.

The only code you should capture is when SoundCloud calls back to your defined redirect_uri and appends the code as a query parameter there. It sounds to me like you are watching the URL and capturing a code parameter on the URL change (you refer to "first url response") - if this is the case then you are probably capturing the wrong callback which wasn't meant for you. This isn't the correct implementation, and would not be considered best practice.

Can you confirm it's supposed to be the same implementation, meaning getting the code from the first url response after user logs in

The correct implementation is extracting the code parameter when SoundCloud returns control to your application via the redirect_uri.

The form will be:

[redirect_uri]?code=XXXX&state=AnyStateYouSentButThatIsOptional

It is documented here:

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

bricemacias commented 2 years ago

Yes indeed ! I was recovering the code from the first response URL and not from the one that had the redirect url in it, thank you so much !

Thanks a lot for your fast responses too :)