From f313d5f602a85dc3b51bd53f381f5d1a3476779e Mon Sep 17 00:00:00 2001 From: Drew Wells Date: Sun, 23 Feb 2014 08:02:46 -0600 Subject: [PATCH 1/4] package.json --- data/package.json | 15 --------------- package.json | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) delete mode 100644 data/package.json create mode 100644 package.json diff --git a/data/package.json b/data/package.json deleted file mode 100644 index 0b9973b..0000000 --- a/data/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "portify", - "description": "Moves your Spotify playlists to Google", - "version": "0.0.5", - "private": true, - "dependencies": { - "googleclientlogin": "*", - "spotify-web": "https://github.com/mauimauer/node-spotify-web/tarball/master", - "socket.io": "*", - "express": "*", - "superagent": "*", - "levenshtein": "*", - "timequeue": "*" - } -} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..d54f17b --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "portify", + "description": "Moves your Spotify playlists to Google", + "version": "0.0.6", + "private": true, + "dependencies": { + "spotify-web": "https://github.com/mauimauer/node-spotify-web/tarball/master", + "socket.io": "~0.9.16", + "express": "~3.4.8", + "superagent": "~0.16.0", + "levenshtein": "~1.0.4", + "timequeue": "~0.2.2", + "googleapis": "~0.6.1" + } +} From 31695a012f3a4e11645088e111e735bc9b1afb8d Mon Sep 17 00:00:00 2001 From: Drew Wells Date: Sun, 23 Feb 2014 09:48:14 -0600 Subject: [PATCH 2/4] Enable `npm start` Dynamically find version of package.json Update readme for new installation/run instructions --- .gitignore | 2 ++ README.md | 4 ++-- data/app.js | 15 +++++++++------ server.js | 1 + 4 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 server.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed42d01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +npm_debug.log diff --git a/README.md b/README.md index d22badd..74c7a32 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ Building portify * Make sure you have installed a usable build enviroment (gcc, make & co.) * Install Node.js (using your favourite package manager, but make sure it's newer than 0.8) * Clone the git repo (master branch) -* Go into the ./data/ directory and run npm install (This will fetch and compile all depenencies of portify) -* Try running the daemon by executing node app.js in the ./data/ folder +* `npm install` Install dependencies +* `npm start` Start the server * Open your favourite browser and go to localhost:3132 [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mauimauer/portify/trend.png)](https://bitdeli.com/free "Bitdeli Badge") diff --git a/data/app.js b/data/app.js index 1543868..d6075c0 100644 --- a/data/app.js +++ b/data/app.js @@ -12,13 +12,14 @@ var app, io = require('socket.io'), TimeQueue = require('timequeue'); -console.log("portify 0.51"); +console.log("portify, version: " + process.env.npm_package_version); + if (typeof Proxy !== 'object' || typeof WeakMap !== 'function') { console.log("Starting without harmony"); express = require('express'); postField = "body"; app = express(); - server = http.createServer(app) + server = http.createServer(app); router = app; app.use(express.static(__dirname + '/content')); app.use (function(req, res, next) { @@ -276,7 +277,7 @@ router.post('/spotify/login', function(request, response, next){ response.send({ status: 400, message: "login failed.", error: err }); return; } - + console.log("Spotify Login success"); spotifySession = spotify; response.send({ status: 200, message: "login successful." }); @@ -448,8 +449,10 @@ if(appjs) { window.process = process; window.module = module; - function F12(e){ return e.keyIdentifier === 'F12' } - function Command_Option_J(e){ return e.keyCode === 74 && e.metaKey && e.altKey } + function F12(e){ return e.keyIdentifier === 'F12'; } + function Command_Option_J(e){ + return e.keyCode === 74 && e.metaKey && e.altKey; + } window.addEventListener('keydown', function(e){ if (F12(e) || Command_Option_J(e)) { @@ -461,4 +464,4 @@ if(appjs) { window.on('close', function(){ console.log("Window Closed"); }); -} \ No newline at end of file +} diff --git a/server.js b/server.js new file mode 100644 index 0000000..6e55ba7 --- /dev/null +++ b/server.js @@ -0,0 +1 @@ +require('./data/app') From 184a457e7cfefc5dbf5a6dd5c5e3f3889408af30 Mon Sep 17 00:00:00 2001 From: Drew Wells Date: Sun, 23 Feb 2014 09:49:48 -0600 Subject: [PATCH 3/4] Switch to api-redesign --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d54f17b..8464f3c 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "0.0.6", "private": true, "dependencies": { - "spotify-web": "https://github.com/mauimauer/node-spotify-web/tarball/master", + "spotify-web": "https://github.com/adammw/node-spotify-web/tarball/api-redesign/", "socket.io": "~0.9.16", "express": "~3.4.8", "superagent": "~0.16.0", From 152ce534c1f7505458bc45974434a736d7c650fc Mon Sep 17 00:00:00 2001 From: Drew Wells Date: Sun, 23 Feb 2014 10:02:39 -0600 Subject: [PATCH 4/4] Use google OAuth2 --- data/app.js | 53 ++++++++++++++++++++++++- data/content/partials/google_login.html | 8 +--- package.json | 5 +++ 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/data/app.js b/data/app.js index d6075c0..baf676b 100644 --- a/data/app.js +++ b/data/app.js @@ -4,8 +4,10 @@ var app, server, postField, appjs = false, + env = process.env, http = require('http'), - GoogleClientLogin = require('googleclientlogin').GoogleClientLogin, + googleapis = require('googleapis'), + googleapisOAuth = googleapis.OAuth2Client, Spotify = require('spotify-web'), events = require('events'), googleMusic = require('./gmusic.js'), @@ -34,6 +36,30 @@ if (typeof Proxy !== 'object' || typeof WeakMap !== 'function') { next(); }); }); + app.get("/generateoauth", function (req, res) { + var uri = getAccessToken(); + res.redirect(301,uri); + }); + app.get("/oauthcallback", function (req, res) { + var code = req.query.code; + res.cookie( + 'token', + req.query.code + ); + if (code) { + res.redirect(301, "/#/spotify/login"); + } else { + res.send( + 500, + { + error: 'Please authorize with one Google ' + + 'account.' + } + ); + + } + }); + app.use(app.router); server.listen(3132); @@ -465,3 +491,28 @@ if(appjs) { console.log("Window Closed"); }); } + +function getAccessToken(oauth2Client) { + return function () { + // generate consent page url + var url = oauth2Client.generateAuthUrl({ + access_type: 'offline', // will return a refresh token + scope: 'https://www.googleapis.com/auth/plus.me' + }); + return url; + }; +} + + +// load google plus v1 API resources and methods +googleapis + .execute(function(err, client) { + + var oauth2Client = + new googleapisOAuth( + env.npm_package_config_gapi_client_id, + env.npm_package_config_gapi_client_secret, + env.npm_package_config_gapi_redirect_uri + ); + getAccessToken = getAccessToken(oauth2Client); +}); diff --git a/data/content/partials/google_login.html b/data/content/partials/google_login.html index 28896c1..8a27e87 100644 --- a/data/content/partials/google_login.html +++ b/data/content/partials/google_login.html @@ -6,11 +6,7 @@
- - - - - + Login with Google OAuth2
@@ -21,4 +17,4 @@
-
\ No newline at end of file +
diff --git a/package.json b/package.json index 8464f3c..a8e4925 100644 --- a/package.json +++ b/package.json @@ -11,5 +11,10 @@ "levenshtein": "~1.0.4", "timequeue": "~0.2.2", "googleapis": "~0.6.1" + }, + "config": { + "gapi_client_id": "your_client_id", + "gapi_client_secret": "your_client_secret", + "gapi_redirect_uri": "your_redirect_url" } }