Node.js/express 400 error

API Discussion

I am trying to figure out how to build a basic node.js/express backend for oauth. I have never used express before so this is new to me. I am following the node.js/express bnet strategy
and I am also following this guide by Uglyer

When I run my server (assuming I have it even set up correctly) and try to hit
localhost:8000/auth/bnet I get a 400 error 'The redirect_uri parameter must be a valid URI' and a URL of

Here is my server.js file

process.env.NODE_ENV= "development";

const express = require('express');
const passport = require('passport');
const constants = require('constants');
const BnetStrategy = require('passport-bnet').Strategy;

const app = express();
const port = process.env.PORT || 8000;

app.listen(port, () => {
console.log('Server started!');


//instance of router
const router = express.Router();

router.use((req, res, next) => {
console.log(req.method, req.url);

// home page
router.get('/', (req, res) => {
res.send('I am the home page');

// Bnet OAuth2 Navigate to
// ===========================*/
// Authenticate Requests
router.get('/auth/bnet', (req, res, next) => {
(err, user, info) => {
if (err) {
return next(err)
})(req, res, next);

// Bnet OAuth2 Callback Route
// ==============================*
router.get('/auth/bnet/callback', (req, res, next) => {
passport.authenticate('bnet', { failureRedirect: constants.DOMAIN
+ '/loginFailure' }, (err, user, info) => {
if (err) {
return next(err);

res.redirect(constants.DOMAIN + '/loginSuccess' );
})(req, res, next);

// handle CORS

const cors = require('cors');

// apply routes to app
app.use('/', router, cors());

// Use the BnetStrategy within Passport.
passport.use(new BnetStrategy({
grant_type: 'authorization_code',
clientID: process.env.BNET_ID,
clientSecret: process.env.BNET_SECRET,
callbackURL: constants.CALLBACKURL,
region: 'us'
}, (accessToken, refreshToken, profile, done) => {
// Profile returns the Bnet Id, Battletag
return done(null, profile);

Here is my .env file


Here is my constants file

let constants = {};
if (process.env.NODE_ENV === 'production') {
constants.DOMAIN = '';
constants.CALLBACKURL = 'https://localhost:8000/auth/bnet/callback'
} else {
constants.DOMAIN = 'https://localhost:' + 4200;
constants.CALLBACKURL = ''

module.exports = constants;

As I said I am new to to express. I'm sure I could move some of this stuff to separate files and clean up some areas, but at the moment I just want to make sure things are in order, as I'm aware code order matters greatly in express, and if I've set up things in a way that should be working as I intend. On my front end I have a button with the tag
<a href=""> that returns a 404 but that is another issue I can solve later. I just want to figure out the node.js/express stuff.

Thanks for taking the time to read this!

Join the Conversation

Return to Forum