Javascript OAuth Authorization Methods!

256 views
Skip to first unread message

Thor

unread,
Nov 9, 2011, 2:23:26 PM11/9/11
to SoundCloudAPI
Hej SoundCloud!

I'm working on a webapp, and I was hoping to use the JavaScript SDK's
recording functionality with the authorization code (server-side)
OAuth 2 flow. One part of the docs implies that this is possible, one
part doesn't mention it. Is this something that I can do using the
SC.connect() function? If so, how do I pass the access token that I
have?

Many thanks,
Thor

Thor

unread,
Nov 9, 2011, 5:17:14 PM11/9/11
to SoundCloudAPI
Update: Found a deeply hacky workaround, but any proper wisdom would
be appreciated.

Vasanth

unread,
Nov 10, 2011, 10:44:18 AM11/10/11
to SoundCloudAPI
Hi,
Can you pls share your workaround. I'm looking for something similar.

Thanks

Hannes Tydén

unread,
Nov 10, 2011, 5:34:01 PM11/10/11
to SoundCloudAPI
Hej Thor!
Sadly there is no "officially supported" way of passing an access
token to the JS SDK, even though it's a totally sensible use case.
So I assume that your hacky workaround is the most proper wisdom there
is regarding this topic.

Please share your findings with us, and we'll improve the JS SDK.

Cheers,
Hannes

Vasanth

unread,
Nov 10, 2011, 11:27:03 PM11/10/11
to SoundCloudAPI
Hi Hannes,
I've been able to figure out a workaround to use the server side
oauth token to connect and authenticate the API calls from JS.
I found that the access token is being stored in window.SC.storage()
with key "SC.accessToken". If it was not found then the JS api has to
connect to SoundCloud using the popup connect window. I just executed
a script from serverside to store the accessToken directly from server
code. (I'm using ASP .Net/C#)

Page.ClientScript.RegisterClientScriptBlock(typeof(string),
"accessToken", "window.SC.storage().setItem(\"SC.accessToken\", \"" +
user.AuthCode + "\")", true);

Hope this helps.

Vasanth

Thor

unread,
Nov 11, 2011, 1:53:04 PM11/11/11
to SoundCloudAPI
Hello Hannes!

Vasanth's solution sounds far more clever than mine, but I'm not
doing .NET stuff.

I ended up appending my access token to the Recorder.upload function
in SDK.js:

Recorder.upload({url:”https://api.soundcloud.com/tracks.json?
oauth_token=” + YOUR_ACCESS_TOKEN,

Yes, this means I downloaded SDK.js, and now have a local copy on my
server. Yes, this is disgusting. This is only good enough because
it's for a school project, and not for serious deployment.

It would be nice to be able to pass the access token into
SC.initialize. I'm sure that has security issues as well though.

Best,
Thor
Reply all
Reply to author
Forward
0 new messages