I was trying to implement official guide of Spotify WEB Playback SDK with CEF C++. I need finish the web app version to try out CEF so i need to run 'npm run build' and 'serve -s build' commands but when build the app and run the 'server file' from powershell i get an error 'INVALID_CLIENT: Invalid client' when trying to LOG IN for authentication. Below, you can find my backend code, developer dashboard redirect uri's. Frontend is same as guide. I want to say it again: App works in 'developer mode', i can use it with 'run-p server start' but when i create a production build App fails. Also i use http://localhost:5000/index.html to use app in build version because http://localhost:3000/auth/login is not even working! I'm in need of help and i belive StackOverflow community can help me! Thanks a lot for any help, happy coding!
My dashboard redirect URIs:
const request = require('request');
const dotenv = require('dotenv');
const path = require('path');
const port = 5000
global.access_token = ''
dotenv.config()
var spotify_client_id = process.env.SPOTIFY_CLIENT_ID
var spotify_client_secret = process.env.SPOTIFY_CLIENT_SECRET
var spotify_redirect_uri = 'http://localhost:3000/auth/callback'
var generateRandomString = function (length) {
var text = '';
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};
var app = express();
app.get('/auth/login', (req, res) => {
var scope = "streaming user-read-email user-read-private"
var state = generateRandomString(16);
var auth_query_parameters = new URLSearchParams({
response_type: "code",
client_id: spotify_client_id,
scope: scope,
redirect_uri: spotify_redirect_uri,
state: state
})
res.redirect('https://accounts.spotify.com/authorize/?' + auth_query_parameters.toString());
})
app.get('/auth/callback', (req, res) => {
var code = req.query.code;
var authOptions = {
url: 'https://accounts.spotify.com/api/token',
form: {
code: code,
redirect_uri: spotify_redirect_uri,
grant_type: 'authorization_code'
},
headers: {
'Authorization': 'Basic ' + (Buffer.from(spotify_client_id + ':' + spotify_client_secret).toString('base64')),
'Content-Type' : 'application/x-www-form-urlencoded'
},
json: true
};
request.post(authOptions, function(error, response, body) {
if (!error && response.statusCode === 200) {
access_token = body.access_token;
res.redirect('/')
}
});
})
app.get('/auth/token', (req, res) => {
res.json({ access_token: access_token})
})
app.listen(port, () => {
console.log(`Listening at http://localhost:${port}`)
})
app.use(express.static(path.join(__dirname, '../build')));```