Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to streamline a bit #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions authorization_code/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ var cors = require('cors');
var querystring = require('querystring');
var cookieParser = require('cookie-parser');

var client_id = 'CLIENT_ID'; // Your client id
var client_secret = 'CLIENT_SECRET'; // Your secret
var redirect_uri = 'REDIRECT_URI'; // Your redirect uri
var client_id = process.env.SPOTIFY_WEB_API_QS_CLIENT_ID || 'CLIENT_ID'; // Your client id
var client_secret = process.env.SPOTIFY_WEB_API_QS_CLIENT_SECRET || 'CLIENT_SECRET'; // Your secret
var redirect_uri = process.env.SPOTIFY_WEB_API_QS_REDIRECT_URI || 'REDIRECT_URI'; // Your redirect uri
var scope = process.env.SPOTIFY_WEB_API_QS_SCOPE || 'user-read-private user-read-email'; // your application requests authorization

/**
* Generates a random string containing numbers and letters
Expand Down Expand Up @@ -45,8 +46,6 @@ app.get('/login', function(req, res) {
var state = generateRandomString(16);
res.cookie(stateKey, state);

// your application requests authorization
var scope = 'user-read-private user-read-email';
res.redirect('https://accounts.spotify.com/authorize?' +
querystring.stringify({
response_type: 'code',
Expand Down Expand Up @@ -91,6 +90,8 @@ app.get('/callback', function(req, res) {

var access_token = body.access_token,
refresh_token = body.refresh_token;
console.log('Refresh token:', refresh_token);
console.log('Access token:', access_token);

var options = {
url: 'https://api.spotify.com/v1/me',
Expand Down Expand Up @@ -143,5 +144,6 @@ app.get('/refresh_token', function(req, res) {
});
});

console.log('Listening on 8888');
app.listen(8888);
const port = parseInt(process.env.SPOTIFY_WEB_API_PORT || 8888)
console.log(`Listening on ${port}`);
app.listen(port);
4 changes: 2 additions & 2 deletions authorization_code/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ <h1>Logged in as {{display_name}}</h1>
<script id="oauth-template" type="text/x-handlebars-template">
<h2>oAuth info</h2>
<dl class="dl-horizontal">
<dt>Access token</dt><dd class="text-overflow">{{access_token}}</dd>
<dt>Refresh token</dt><dd class="text-overflow">{{refresh_token}}</dd>
<dt>Access token</dt><dd>{{access_token}}</dd>
<dt>Refresh token</dt><dd>{{refresh_token}}</dd>
</dl>
</script>

Expand Down
Loading