Moszeed
Moszeed

Reputation: 1037

Soundcloud API Authentication | NodeWebkit, redirect uri and local file system

i'am try to build a NodeWebkit App that uses the Soundcloud API.
But i fail already at the connect/login process.

In NodeWebkit the User can install the App anywhere on his hard-drive
so that the redirect_uri is never the same.
And hosting the redirect page on a webserver will not work.
{different protocols "file://" and "https://")

I tried the different approaches from the API Doku here
http://developers.soundcloud.com/docs#authentication but with no result.

How i use the Soundcloud API with NodewebKit ?

Thanks in advance.

Upvotes: 4

Views: 786

Answers (2)

Moszeed
Moszeed

Reputation: 1037

After discovering the NodeWebkit Issue`s i saw this thread: https://github.com/rogerwang/node-webkit/issues/542

It describes a way with NodeWebkit IFrames: my code looks like this:

var def     = $.Deferred();        
var $iframe = $('<iframe nwfaketop nwdisable></iframe>')
                .attr('src', SoundCloud.ConnectUrl)
                .load(function(e) {

                    var parser      = document.createElement('a');
                        parser.href = this.contentWindow.location.href;

                    var search = parser.search.substr(1, parser.search.length);
                    var result = URLToArray(search);

                    if (result.error !== void 0) {
                        $iframe.remove();
                        def.reject(result.error_description);
                    }

                    if (result.code !== void 0) {
                        SoundCloud.LoginCode = result.code;
                        $iframe.remove();
                        def.resolve();
                    }
                })
                .appendTo($(opts.iframe));

return def;

hope it helps others with the same problem.

Upvotes: 2

ledzep2
ledzep2

Reputation: 841

For file based solution, maybe you can construct a local redirect_uri every time with __dirname __filename variables of the node module.

For webserver based solution, since node_remote attribute allows you to call node apis within the origin "localhost" or whatever, you should be able to sync the soundcloud data with the callback.html opener (aka your connect page) through a context in node.

Upvotes: 1

Related Questions