title: No 'Access-Control-Allow-Origin' is present, Origin 'null' not allowed access - Passport-SteamStrategy, Node
body: <p>I have a site that is using Passport Steam Strategy. My server (Node with Express) is currently running on localhost:3000 while my front end is running on localhost:8080. I keep running into a cross-origin issue, only when attempting to authorize through Steam. My requests are made through Axios and I am using CORS. I've spent hours Googling and trying various things but I can't seem to get it to work.</p>
  
  <p>This is the error that I get:</p>
  
  <blockquote>
    <p>XMLHttpRequest cannot load
    <a href="https://steamcommunity.com/openid/login?openid.mode=checkid_setup&amp;openid.ns" rel="nofollow noreferrer">https://steamcommunity.com/openid/login?openid.mode=checkid_setup&amp;openid.ns</a>…3000%2Fsteam%2Fauth%2Freturn&amp;openid.realm=http%3A%2F%2Flocalhost%3A3000%2F.
    No 'Access-Control-Allow-Origin' header is present on the requested
    resource. Origin 'null' is therefore not allowed access.</p>
  </blockquote>
  
  <p>Here is where the route is called from the front end:</p>
  
  <pre><code>    linkSteam(){
          api('http://localhost:3000/steam/auth')
              .then(res =&gt; {
                  console.log(res);
                  state.user = res.data.user;
              })
      }
  </code></pre>
  
  <p>And here is my axios configuration on the front end.</p>
  
  <pre><code>let api = axios.create({
    baseURL: 'http://localhost:3000/api/',
    timeout: 3000,
    withCredentials: true
  })
  </code></pre>
  
  <p>My CORS is set up as follows</p>
  
  <pre><code>var whitelist = ['http://localhost:8080', 'https://steamcommunity.com', 'http://localhost:3000', 'null'];
  // I added null here as someone said that it worked as their origin displayed null like mine does
  var corsOptions = {
    origin: function (origin, callback) {
      var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
      callback(null, originIsWhitelisted);
    },
    credentials: true
  };
  </code></pre>
  
  <p>I then import my CORS into my main file and use it as follows</p>
  
  <pre><code>app.use(cors(corsOptions))
  app.use('*', cors(corsOptions))
  </code></pre>
  
  <p>I kept seeing that you can set your Access-Control-Allow-Credentials, etc and did so</p>
  
  <pre><code>app.use(function (req, res, next) {
    res.setHeader('Access-Control-Allow-Credentials', true);
    res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8080');
    res.setHeader('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
    if ('OPTIONS' == req.method) {
       res.send(200);
     } else {
       next();
     }
  });
  </code></pre>
  
  <p>This didn't help. I've tried breaking down my original function where /steam/auth is called and running a console.log(req.headers.origin) and spits back my correct URL, but then the error still reports that the Origin is null. If I set my Access-Control-Allow-Origin' to '*', I get a slightly different error that I must provide credentials, and that the Origin 'localhost:8080' is therefore not allowed.</p>
  
  <p>Here's my /steam/auth route.</p>
  
  <pre><code>router.get('/steam/auth',
    passport.authenticate('steam', {
      failureRedirect: '/'
    }),
    function (req, res) {
      res.redirect('/');
    });
  </code></pre>
  
  <p>And this does work if I click on the URL that cannot be loaded and then login to Steam. It will then redirect me back to my site with my Steam profile information intact. The error is on attempting to get the initial redirect back to Steam in order to login. I have also tried doing this in a res.redirect to their direct URL and I get the same error.</p>
  
  <p>Thanks in advance for any help! And let me know if I'm missing vital information. I've tried to include everything, but I wouldn't be surprise if I missed something.</p>