I am playing around with Spotify's API and I am trying to get the authorization from the user using res.redirect, but the authorization dialogue is not showing up. Here is the code. Additional info the redirect URL is localhost:3000, and the js script is connect to a static folder which has one html file .
const Joi = require('joi');
const querystring = require('querystring');
const express = require('express');
const cors = require('cors');
const request = require('request');
const cookieParser = require('cookie-parser');
const app = express();
app.use(express.json()); //middleware
app.use(express.static(__dirname + '/public'))
.use(cors())
.use(cookieParser());
app.get('/user', (req, res) => {
const client_id = 'b*****************';
const redirect_uri = 'http://localhost:3000/';
const scope = 'user-read-private user-read-email';
res.redirect('https://accounts.spotify.com/authorize?' + querystring.stringify({
response_type: 'code',
client_id: client_id,
redirect_uri: redirect_uri
}));
});
app.listen(3000);
if you’re implementing authorization in a mobile app, single page web app, or any other type of application where the client secret can’t be safely stored.
Authorization Code with PKCE Flowin hereI will demo a more simple version
Authorization Code Flowbut the concept is the same.Authorization Code Flow in here
Demo code save as
demo.jsInstall dependencies
Run the server
Login to get a token by Browser
Login Dialog will show
Result from express server
Scopes
Each API need to match scope, Example,