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..baf676b 100644 --- a/data/app.js +++ b/data/app.js @@ -4,21 +4,24 @@ 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'), 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) { @@ -33,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); @@ -276,7 +303,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 +475,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 +490,29 @@ if(appjs) { window.on('close', function(){ console.log("Window Closed"); }); -} \ No newline at end of file +} + +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/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..a8e4925 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "portify", + "description": "Moves your Spotify playlists to Google", + "version": "0.0.6", + "private": true, + "dependencies": { + "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", + "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" + } +} 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')