title: using nodejs, express and basic auth how do i get username and password
body: <p>I am using nodejs, express
  A third party that will be calling my api will be using basic auth in the format of http://{username}:{password}@yourdomain.com/</p>
  
  <p>I have tried </p>
  
  <pre><code>var auth = require('basic-auth')
  
  app.use(function(req, res, next) {
       var credentials = auth(req)
       if (req.headers.authorization) {
         console.log("found headers");
       }
  }
  </code></pre>
  
  <p>But this only works if the basic auth is passed in the header. </p>
  
  <p>I can not seem to get the username and password from the URL(which is the only way this external party can call my api)</p>
  
  <p>I then tried as suggested use url</p>
  
  <p>here is what i am seeing now when i do a POST to </p>
  
  <pre><code>http://myusername:mypassword@localhost:4050/api/callback
  
  
  var express = require('express');
  var http = require('http');
  var url = require('url');
  
  var app = express();
  
  app.use(function(req, res, next) {
  
      console.log("req.protocol=",req.protocol);
      console.log("req.get('host')=",req.get('host'));
      console.log("req.originalUrl=",req.originalUrl);
  }
  
  http.createServer(app).listen(config.port, function () {
       console.log("HTTP BandWidth listening on port " + config.port);
  
  });
  </code></pre>
  
  <p>My console looks like</p>
  
  <p>req.protocol= http </p>
  
  <p>req.get('host')= localhost:4050 </p>
  
  <p>req.originalUrl=/api/callback</p>
  
  <p>if i dump the entire req obj i do not see myusername or mypassword</p>
  
  <p>i must be missing something obvious</p>
  
  <p>Thanks
  Randy</p>