From 0d7878f84f27583bbfbce1813770ba7b8f20f726 Mon Sep 17 00:00:00 2001 From: jperez Date: Tue, 3 Jun 2014 13:26:18 +0200 Subject: [PATCH] Minor updates - Rename secret_key to client_secret - Fetch values from new fields - Authorization Code: Exchange code by token sending id and secret in body instead of Base64 header --- README.md | 2 +- authorization_code/app.js | 13 +++++++------ authorization_code/public/index.html | 8 ++++---- client_credentials/app.js | 4 ++-- implicit_grant/app.js | 1 + implicit_grant/public/index.html | 8 ++++---- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 612c721..1027a02 100644 --- a/README.md +++ b/README.md @@ -32,5 +32,5 @@ Go to [My Applications on Spotify Developer](https://developer.spotify.com/my-ap * http://localhost:8888 (needed for the implicit grant flow) * http://localhost:8888/callback -Once you have created your app, replace the `client_id`, `redirect_uri` and `secret_key` in the examples with the ones you get from My Applications. +Once you have created your app, replace the `client_id`, `redirect_uri` and `client_secret` in the examples with the ones you get from My Applications. diff --git a/authorization_code/app.js b/authorization_code/app.js index d61e5a3..d26861e 100644 --- a/authorization_code/app.js +++ b/authorization_code/app.js @@ -12,7 +12,7 @@ var request = require('request'); // "Request" library var querystring = require('querystring'); var client_id = '03ffe0cac0a0401aa6673c3cf6d02ced'; // Your client id -var secret_key = 'a57c43efb9644574a96d6623fb8bfbc2'; // Your secret key +var client_secret = 'a57c43efb9644574a96d6623fb8bfbc2'; // Your client secret var redirect_uri = 'http://localhost:8888/callback'; // Your redirect uri var app = express(); @@ -38,16 +38,16 @@ app.get('/callback', function(req, res) { var code = req.query.code; var authOptions = { url: 'https://accounts.spotify.com/api/token', - headers: { - 'Authorization': 'Basic ' + (new Buffer(client_id + ':' + secret_key).toString('base64')) - }, form: { code: code, redirect_uri: redirect_uri, - grant_type: 'authorization_code' + grant_type: 'authorization_code', + client_id: client_id, + client_secret: client_secret }, json: true }; + request.post(authOptions, function(error, response, body) { if (!error && response.statusCode === 200) { @@ -81,7 +81,7 @@ app.get('/refresh_token', function(req, res) { var refresh_token = req.query.refresh_token; var authOptions = { url: 'https://accounts.spotify.com/api/token', - headers: { 'Authorization': 'Basic ' + (new Buffer(client_id + ':' + secret_key).toString('base64')) }, + headers: { 'Authorization': 'Basic ' + (new Buffer(client_id + ':' + client_secret).toString('base64')) }, form: { grant_type: 'refresh_token', refresh_token: refresh_token @@ -99,4 +99,5 @@ app.get('/refresh_token', function(req, res) { }); }); +console.log('Listening on 8888'); app.listen(8888); diff --git a/authorization_code/public/index.html b/authorization_code/public/index.html index 4d154b8..09cc7f3 100644 --- a/authorization_code/public/index.html +++ b/authorization_code/public/index.html @@ -35,16 +35,16 @@

Logged in as {{display_name}}

- +
Display name
{{display_name}}
Id
{{id}}
Email
{{email}}
-
Spotify URI
{{self.uri}}
-
Link
{{self.web}}
-
Profile Image
{{image.url}}
+
Spotify URI
{{external_urls.spotify}}
+
Link
{{href}}
+
Profile Image
{{images.0.url}}
diff --git a/client_credentials/app.js b/client_credentials/app.js index e3e5f5b..771f061 100644 --- a/client_credentials/app.js +++ b/client_credentials/app.js @@ -10,14 +10,14 @@ var request = require('request'); // "Request" library var client_id = '03ffe0cac0a0401aa6673c3cf6d02ced'; // Your client id -var secret_key = 'a57c43efb9644574a96d6623fb8bfbc2'; // Your secret key +var client_secret = 'a57c43efb9644574a96d6623fb8bfbc2'; // Your client secret var redirect_uri = 'http://localhost:8888/callback'; // Your redirect uri // your application requests authorization var authOptions = { url: 'https://accounts.spotify.com/api/token', headers: { - 'Authorization': 'Basic ' + (new Buffer(client_id + ':' + secret_key).toString('base64')) + 'Authorization': 'Basic ' + (new Buffer(client_id + ':' + client_secret).toString('base64')) }, form: { grant_type: 'client_credentials' diff --git a/implicit_grant/app.js b/implicit_grant/app.js index 9d525d9..03fa15d 100644 --- a/implicit_grant/app.js +++ b/implicit_grant/app.js @@ -10,4 +10,5 @@ var express = require('express'); // Express web server framework var app = express(); app.use(express.static(__dirname + '/public')); +console.log('Listening on 8888'); app.listen(8888); diff --git a/implicit_grant/public/index.html b/implicit_grant/public/index.html index 54da863..29e8a8d 100644 --- a/implicit_grant/public/index.html +++ b/implicit_grant/public/index.html @@ -34,16 +34,16 @@

Logged in as {{display_name}}

- +
Display name
{{display_name}}
Id
{{id}}
Email
{{email}}
-
Spotify URI
{{self.uri}}
-
Link
{{self.web}}
-
Profile Image
{{image.url}}
+
Spotify URI
{{external_urls.spotify}}
+
Link
{{href}}
+
Profile Image
{{images.0.url}}